Debian Codegraph @

rhino/testsrc/tests/ecma_3/extensions/regress-188206-02.js

raw symbols SCIP
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/. */
5
6 //-----------------------------------------------------------------------------
7 var gTestfile = 'regress-188206-02.js';
8 var UBound = 0;
9 var BUGNUMBER = 188206;
10 var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors';
11 var CHECK_PASSED = 'Should not generate an error';
12 var CHECK_FAILED = 'Generated an error!';
13 var status = '';
14 var statusitems = [];
15 var actual = '';
16 var actualvalues = [];
17 var expect= '';
18 var expectedvalues = [];
19
20
21 /*
22 * Misusing the {DecmalDigits} quantifier - according to ECMA,
23 * but not according to Perl.
24 *
25 * ECMA-262 Edition 3 prohibits the use of unescaped braces in
26 * regexp patterns, unless they form part of a quantifier.
27 *
28 * Hovever, Perl does not prohibit this. If not used as part
29 * of a quantifer, Perl treats braces literally.
30 *
31 * We decided to follow Perl on this for backward compatibility.
32 * See http://bugzilla.mozilla.org/show_bug.cgi?id=190685.
33 *
34 * Therefore NONE of the following ECMA violations should generate
35 * a SyntaxError. Note we use checkThis() instead of testThis().
36 */
37 status = inSection(13);
38 checkThis(' /a*{/ ');
39
40 status = inSection(14);
41 checkThis(' /a{}/ ');
42
43 status = inSection(15);
44 checkThis(' /{a/ ');
45
46 status = inSection(16);
47 checkThis(' /}a/ ');
48
49 status = inSection(17);
50 checkThis(' /x{abc}/ ');
51
52 status = inSection(18);
53 checkThis(' /{{0}/ ');
54
55 status = inSection(19);
56 checkThis(' /{{1}/ ');
57
58 status = inSection(20);
59 checkThis(' /x{{0}/ ');
60
61 status = inSection(21);
62 checkThis(' /x{{1}/ ');
63
64 status = inSection(22);
65 checkThis(' /x{{0}}/ ');
66
67 status = inSection(23);
68 checkThis(' /x{{1}}/ ');
69
70 status = inSection(24);
71 checkThis(' /x{{0}}/ ');
72
73 status = inSection(25);
74 checkThis(' /x{{1}}/ ');
75
76 status = inSection(26);
77 checkThis(' /x{{0}}/ ');
78
79 status = inSection(27);
80 checkThis(' /x{{1}}/ ');
81
82
83 //-----------------------------------------------------------------------------
84 test();
85 //-----------------------------------------------------------------------------
86
87
88
89 /*
90 * Allowed syntax shouldn't generate any errors
91 */
92 function checkThis(sAllowedSyntax)
93 {
94 expect = CHECK_PASSED;
95 actual = CHECK_PASSED;
96
97 try
98 {
99 eval(sAllowedSyntax);
100 }
101 catch(e)
102 {
103 actual = CHECK_FAILED;
104 }
105
106 statusitems[UBound] = status;
107 expectedvalues[UBound] = expect;
108 actualvalues[UBound] = actual;
109 UBound++;
110 }
111
112
113 function test()
114 {
115 enterFunc('test');
116 printBugNumber(BUGNUMBER);
117 printStatus(summary);
118
119 for (var i=0; i<UBound; i++)
120 {
121 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
122 }
123
124 exitFunc ('test');
125 }