Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * Date: 26 November 2000
8 *
9 *
10 * SUMMARY: Passing (RegExp object, flag) to RegExp() function.
11 * This test arose from Bugzilla bug 61266. The ECMA3 section is:
12 *
13 * 15.10.3 The RegExp Constructor Called as a Function
14 *
15 * 15.10.3.1 RegExp(pattern, flags)
16 *
17 * If pattern is an object R whose [[Class]] property is "RegExp"
18 * and flags is undefined, then return R unchanged. Otherwise
19 * call the RegExp constructor (section 15.10.4.1), passing it the
20 * pattern and flags arguments and return the object constructed
21 * by that constructor.
22 *
23 *
24 * The current test will check the first scenario outlined above:
25 *
26 * "pattern" is itself a RegExp object R
27 * "flags" is undefined
28 *
29 * This test is identical to test 15.10.3.1-1.js, except here we do:
30 *
31 * RegExp(R, undefined);
32 *
33 * instead of:
34 *
35 * RegExp(R);
36 *
37 *
38 * We check that RegExp(R, undefined) returns R -
39 */
40 //-----------------------------------------------------------------------------
41 var BUGNUMBER = '61266';
42 var summary = 'Passing (RegExp object,flag) to RegExp() function';
43 var statprefix = 'RegExp(new RegExp(';
44 var comma = ', '; var singlequote = "'"; var closeparens = '))';
45 var cnSUCCESS = 'RegExp() returned the supplied RegExp object';
46 var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object';
47 var i = -1; var j = -1; var s = ''; var f = '';
48 var obj = {};
49 var status = ''; var actual = ''; var expect = '';
50 var patterns = new Array();
51 var flags = new Array();
54 // various regular expressions to try -
55 patterns[0] = '';
56 patterns[1] = 'abc';
57 patterns[2] = '(.*)(3-1)\s\w';
58 patterns[3] = '(.*)(...)\\s\\w';
59 patterns[4] = '[^A-Za-z0-9_]';
60 patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
62 // various flags to try -
63 flags[0] = 'i';
64 flags[1] = 'g';
65 flags[2] = 'm';
66 flags[3] = undefined;
70 //-------------------------------------------------------------------------------------------------
71 test();
72 //-------------------------------------------------------------------------------------------------
75 function test()
76 {
77 enterFunc ('test');
78 printBugNumber(BUGNUMBER);
79 printStatus (summary);
81 for (i in patterns)
82 {
83 s = patterns[i];
85 for (j in flags)
86 {
87 f = flags[j];
88 status = getStatus(s, f);
89 obj = new RegExp(s, f);
91 actual = (obj == RegExp(obj, undefined))? cnSUCCESS : cnFAILURE ;
92 expect = cnSUCCESS;
93 reportCompare (expect, actual, status);
94 }
95 }
97 exitFunc ('test');
98 }
101 function getStatus(regexp, flag)
102 {
103 return (statprefix + quote(regexp) + comma + flag + closeparens);
104 }
107 function quote(text)
108 {
109 return (singlequote + text + singlequote);
110 }