js/src/tests/ecma_3/RegExp/15.10.4.1-5-n.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 *
michael@0 8 * Date: 26 November 2000
michael@0 9 *
michael@0 10 *
michael@0 11 *SUMMARY: Passing a RegExp object to a RegExp() constructor.
michael@0 12 *This test arose from Bugzilla bug 61266. The ECMA3 section is:
michael@0 13 *
michael@0 14 * 15.10.4.1 new RegExp(pattern, flags)
michael@0 15 *
michael@0 16 * If pattern is an object R whose [[Class]] property is "RegExp" and
michael@0 17 * flags is undefined, then let P be the pattern used to construct R
michael@0 18 * and let F be the flags used to construct R. If pattern is an object R
michael@0 19 * whose [[Class]] property is "RegExp" and flags is not undefined,
michael@0 20 * then throw a TypeError exception. Otherwise, let P be the empty string
michael@0 21 * if pattern is undefined and ToString(pattern) otherwise, and let F be
michael@0 22 * the empty string if flags is undefined and ToString(flags) otherwise.
michael@0 23 *
michael@0 24 *
michael@0 25 *The current test will check the second scenario outlined above:
michael@0 26 *
michael@0 27 * "pattern" is itself a RegExp object R
michael@0 28 * "flags" is NOT undefined
michael@0 29 *
michael@0 30 * This should throw an exception ... we test for this.
michael@0 31 *
michael@0 32 */
michael@0 33
michael@0 34 //-------------------------------------------------------------------------------------------------
michael@0 35 var BUGNUMBER = '61266';
michael@0 36 var summary = 'Negative test: Passing (RegExp object, flag) to RegExp() constructor';
michael@0 37 var statprefix = 'Passing RegExp object on pattern ';
michael@0 38 var statsuffix = '; passing flag ';
michael@0 39 var cnFAILURE = 'Expected an exception to be thrown, but none was -';
michael@0 40 var singlequote = "'";
michael@0 41 var i = -1; var j = -1; var s = ''; var f = '';
michael@0 42 var obj1 = {}; var obj2 = {};
michael@0 43 var patterns = new Array();
michael@0 44 var flags = new Array();
michael@0 45
michael@0 46
michael@0 47 // various regular expressions to try -
michael@0 48 patterns[0] = '';
michael@0 49 patterns[1] = 'abc';
michael@0 50 patterns[2] = '(.*)(3-1)\s\w';
michael@0 51 patterns[3] = '(.*)(...)\\s\\w';
michael@0 52 patterns[4] = '[^A-Za-z0-9_]';
michael@0 53 patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
michael@0 54
michael@0 55 // various flags to try -
michael@0 56 flags[0] = 'i';
michael@0 57 flags[1] = 'g';
michael@0 58 flags[2] = 'm';
michael@0 59
michael@0 60
michael@0 61 DESCRIPTION = "Negative test: Passing (RegExp object, flag) to RegExp() constructor"
michael@0 62 EXPECTED = "error";
michael@0 63
michael@0 64
michael@0 65 //-------------------------------------------------------------------------------------------------
michael@0 66 test();
michael@0 67 //-------------------------------------------------------------------------------------------------
michael@0 68
michael@0 69
michael@0 70 function test()
michael@0 71 {
michael@0 72 enterFunc ('test');
michael@0 73 printBugNumber(BUGNUMBER);
michael@0 74 printStatus (summary);
michael@0 75
michael@0 76 for (i in patterns)
michael@0 77 {
michael@0 78 s = patterns[i];
michael@0 79
michael@0 80 for (j in flags)
michael@0 81 {
michael@0 82 f = flags[j];
michael@0 83 printStatus(getStatus(s, f));
michael@0 84 obj1 = new RegExp(s, f);
michael@0 85 obj2 = new RegExp(obj1, f); // this should cause an exception
michael@0 86
michael@0 87 // WE SHOULD NEVER REACH THIS POINT -
michael@0 88 reportCompare('PASS', 'FAIL', cnFAILURE);
michael@0 89 }
michael@0 90 }
michael@0 91
michael@0 92 exitFunc ('test');
michael@0 93 }
michael@0 94
michael@0 95
michael@0 96 function getStatus(regexp, flag)
michael@0 97 {
michael@0 98 return (statprefix + quote(regexp) + statsuffix + flag);
michael@0 99 }
michael@0 100
michael@0 101
michael@0 102 function quote(text)
michael@0 103 {
michael@0 104 return (singlequote + text + singlequote);
michael@0 105 }

mercurial