OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file relies on the fact that the following declaration has been made | 5 // This file relies on the fact that the following declaration has been made |
6 // in runtime.js: | 6 // in runtime.js: |
7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
8 // var $Array = global.Array; | 8 // var $Array = global.Array; |
9 | 9 |
10 var $RegExp = global.RegExp; | 10 var $RegExp = global.RegExp; |
(...skipping 12 matching lines...) Expand all Loading... |
23 + (pattern.ignoreCase ? 'i' : '') | 23 + (pattern.ignoreCase ? 'i' : '') |
24 + (pattern.multiline ? 'm' : ''); | 24 + (pattern.multiline ? 'm' : ''); |
25 if (harmony_regexps) | 25 if (harmony_regexps) |
26 flags += (pattern.sticky ? 'y' : ''); | 26 flags += (pattern.sticky ? 'y' : ''); |
27 pattern = pattern.source; | 27 pattern = pattern.source; |
28 } | 28 } |
29 | 29 |
30 pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern); | 30 pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern); |
31 flags = IS_UNDEFINED(flags) ? '' : ToString(flags); | 31 flags = IS_UNDEFINED(flags) ? '' : ToString(flags); |
32 | 32 |
33 var global = false; | 33 %RegExpInitializeAndCompile(object, pattern, flags); |
34 var ignoreCase = false; | |
35 var multiline = false; | |
36 var sticky = false; | |
37 for (var i = 0; i < flags.length; i++) { | |
38 var c = %_CallFunction(flags, i, StringCharAt); | |
39 switch (c) { | |
40 case 'g': | |
41 if (global) { | |
42 throw MakeSyntaxError("invalid_regexp_flags", [flags]); | |
43 } | |
44 global = true; | |
45 break; | |
46 case 'i': | |
47 if (ignoreCase) { | |
48 throw MakeSyntaxError("invalid_regexp_flags", [flags]); | |
49 } | |
50 ignoreCase = true; | |
51 break; | |
52 case 'm': | |
53 if (multiline) { | |
54 throw MakeSyntaxError("invalid_regexp_flags", [flags]); | |
55 } | |
56 multiline = true; | |
57 break; | |
58 case 'y': | |
59 if (!harmony_regexps || sticky) { | |
60 throw MakeSyntaxError("invalid_regexp_flags", [flags]); | |
61 } | |
62 sticky = true; | |
63 break; | |
64 default: | |
65 throw MakeSyntaxError("invalid_regexp_flags", [flags]); | |
66 } | |
67 } | |
68 | |
69 %RegExpInitializeObject(object, pattern, global, ignoreCase, multiline, sticky
); | |
70 | |
71 // Call internal function to compile the pattern. | |
72 %RegExpCompile(object, pattern, flags); | |
73 } | 34 } |
74 | 35 |
75 | 36 |
76 function RegExpConstructor(pattern, flags) { | 37 function RegExpConstructor(pattern, flags) { |
77 if (%_IsConstructCall()) { | 38 if (%_IsConstructCall()) { |
78 DoConstructRegExp(this, pattern, flags); | 39 DoConstructRegExp(this, pattern, flags); |
79 } else { | 40 } else { |
80 // RegExp : Called as function; see ECMA-262, section 15.10.3.1. | 41 // RegExp : Called as function; see ECMA-262, section 15.10.3.1. |
81 if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) { | 42 if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) { |
82 return pattern; | 43 return pattern; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 427 |
467 for (var i = 1; i < 10; ++i) { | 428 for (var i = 1; i < 10; ++i) { |
468 %DefineAccessorPropertyUnchecked($RegExp, '$' + i, | 429 %DefineAccessorPropertyUnchecked($RegExp, '$' + i, |
469 RegExpMakeCaptureGetter(i), NoOpSetter, | 430 RegExpMakeCaptureGetter(i), NoOpSetter, |
470 DONT_DELETE); | 431 DONT_DELETE); |
471 } | 432 } |
472 %ToFastProperties($RegExp); | 433 %ToFastProperties($RegExp); |
473 } | 434 } |
474 | 435 |
475 SetUpRegExp(); | 436 SetUpRegExp(); |
OLD | NEW |