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; |
11 | 11 |
12 // ------------------------------------------------------------------- | 12 // ------------------------------------------------------------------- |
13 | 13 |
14 // A recursive descent parser for Patterns according to the grammar of | 14 // A recursive descent parser for Patterns according to the grammar of |
15 // ECMA-262 15.10.1, with deviations noted below. | 15 // ECMA-262 15.10.1, with deviations noted below. |
16 function DoConstructRegExp(object, pattern, flags) { | 16 function DoConstructRegExp(object, pattern, flags) { |
17 // RegExp : Called as constructor; see ECMA-262, section 15.10.4. | 17 // RegExp : Called as constructor; see ECMA-262, section 15.10.4. |
18 if (IS_REGEXP(pattern)) { | 18 if (IS_REGEXP(pattern)) { |
19 if (!IS_UNDEFINED(flags)) { | 19 if (!IS_UNDEFINED(flags)) { |
20 throw MakeTypeError('regexp_flags', []); | 20 throw MakeTypeError('regexp_flags', []); |
21 } | 21 } |
22 flags = (pattern.global ? 'g' : '') | 22 flags = (pattern.global ? 'g' : '') |
23 + (pattern.ignoreCase ? 'i' : '') | 23 + (pattern.ignoreCase ? 'i' : '') |
24 + (pattern.multiline ? 'm' : ''); | 24 + (pattern.multiline ? 'm' : ''); |
25 if (harmony_unicode) | 25 if (harmony_unicode_regexps) |
26 flags += (pattern.unicode ? 'u' : ''); | 26 flags += (pattern.unicode ? 'u' : ''); |
27 if (harmony_regexps) | 27 if (harmony_regexps) |
28 flags += (pattern.sticky ? 'y' : ''); | 28 flags += (pattern.sticky ? 'y' : ''); |
29 pattern = pattern.source; | 29 pattern = pattern.source; |
30 } | 30 } |
31 | 31 |
32 pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern); | 32 pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern); |
33 flags = IS_UNDEFINED(flags) ? '' : ToString(flags); | 33 flags = IS_UNDEFINED(flags) ? '' : ToString(flags); |
34 | 34 |
35 %RegExpInitializeAndCompile(object, pattern, flags); | 35 %RegExpInitializeAndCompile(object, pattern, flags); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 function RegExpToString() { | 231 function RegExpToString() { |
232 if (!IS_REGEXP(this)) { | 232 if (!IS_REGEXP(this)) { |
233 throw MakeTypeError('incompatible_method_receiver', | 233 throw MakeTypeError('incompatible_method_receiver', |
234 ['RegExp.prototype.toString', this]); | 234 ['RegExp.prototype.toString', this]); |
235 } | 235 } |
236 var result = '/' + this.source + '/'; | 236 var result = '/' + this.source + '/'; |
237 if (this.global) result += 'g'; | 237 if (this.global) result += 'g'; |
238 if (this.ignoreCase) result += 'i'; | 238 if (this.ignoreCase) result += 'i'; |
239 if (this.multiline) result += 'm'; | 239 if (this.multiline) result += 'm'; |
240 if (harmony_unicode && this.unicode) result += 'u'; | 240 if (harmony_unicode_regexps && this.unicode) result += 'u'; |
241 if (harmony_regexps && this.sticky) result += 'y'; | 241 if (harmony_regexps && this.sticky) result += 'y'; |
242 return result; | 242 return result; |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 // Getters for the static properties lastMatch, lastParen, leftContext, and | 246 // Getters for the static properties lastMatch, lastParen, leftContext, and |
247 // rightContext of the RegExp constructor. The properties are computed based | 247 // rightContext of the RegExp constructor. The properties are computed based |
248 // on the captures array of the last successful match and the subject string | 248 // on the captures array of the last successful match and the subject string |
249 // of the last successful match. | 249 // of the last successful match. |
250 function RegExpGetLastMatch() { | 250 function RegExpGetLastMatch() { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 430 |
431 for (var i = 1; i < 10; ++i) { | 431 for (var i = 1; i < 10; ++i) { |
432 %DefineAccessorPropertyUnchecked($RegExp, '$' + i, | 432 %DefineAccessorPropertyUnchecked($RegExp, '$' + i, |
433 RegExpMakeCaptureGetter(i), NoOpSetter, | 433 RegExpMakeCaptureGetter(i), NoOpSetter, |
434 DONT_DELETE); | 434 DONT_DELETE); |
435 } | 435 } |
436 %ToFastProperties($RegExp); | 436 %ToFastProperties($RegExp); |
437 } | 437 } |
438 | 438 |
439 SetUpRegExp(); | 439 SetUpRegExp(); |
OLD | NEW |