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 var $regexpExec; | 5 var $regexpExec; |
6 var $regexpExecNoTests; | 6 var $regexpExecNoTests; |
7 var $regexpLastMatchInfo; | 7 var $regexpLastMatchInfo; |
8 var $regexpLastMatchInfoOverride; | 8 var $regexpLastMatchInfoOverride; |
9 var harmony_regexps = false; | 9 var harmony_regexps = false; |
10 var harmony_unicode_regexps = false; | 10 var harmony_unicode_regexps = false; |
11 | 11 |
12 (function() { | 12 (function() { |
13 | 13 |
14 %CheckIsBootstrapping(); | 14 %CheckIsBootstrapping(); |
15 | 15 |
16 var GlobalRegExp = global.RegExp; | 16 var GlobalRegExp = global.RegExp; |
17 var GlobalArray = global.Array; | |
18 | 17 |
19 // Property of the builtins object for recording the result of the last | 18 // Property of the builtins object for recording the result of the last |
20 // regexp match. The property $regexpLastMatchInfo includes the matchIndices | 19 // regexp match. The property $regexpLastMatchInfo includes the matchIndices |
21 // array of the last successful regexp match (an array of start/end index | 20 // array of the last successful regexp match (an array of start/end index |
22 // pairs for the match and all the captured substrings), the invariant is | 21 // pairs for the match and all the captured substrings), the invariant is |
23 // that there are at least two capture indeces. The array also contains | 22 // that there are at least two capture indeces. The array also contains |
24 // the subject string for the last successful match. | 23 // the subject string for the last successful match. |
25 $regexpLastMatchInfo = new InternalPackedArray( | 24 $regexpLastMatchInfo = new InternalPackedArray( |
26 2, // REGEXP_NUMBER_OF_CAPTURES | 25 2, // REGEXP_NUMBER_OF_CAPTURES |
27 "", // Last subject. | 26 "", // Last subject. |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 }; | 356 }; |
358 } | 357 } |
359 | 358 |
360 // ------------------------------------------------------------------- | 359 // ------------------------------------------------------------------- |
361 | 360 |
362 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); | 361 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); |
363 %AddNamedProperty( | 362 %AddNamedProperty( |
364 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); | 363 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); |
365 %SetCode(GlobalRegExp, RegExpConstructor); | 364 %SetCode(GlobalRegExp, RegExpConstructor); |
366 | 365 |
367 InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, GlobalArray( | 366 InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
368 "exec", RegExpExecJS, | 367 "exec", RegExpExecJS, |
369 "test", RegExpTest, | 368 "test", RegExpTest, |
370 "toString", RegExpToString, | 369 "toString", RegExpToString, |
371 "compile", RegExpCompileJS | 370 "compile", RegExpCompileJS |
372 )); | 371 ]); |
373 | 372 |
374 // The length of compile is 1 in SpiderMonkey. | 373 // The length of compile is 1 in SpiderMonkey. |
375 %FunctionSetLength(GlobalRegExp.prototype.compile, 1); | 374 %FunctionSetLength(GlobalRegExp.prototype.compile, 1); |
376 | 375 |
377 // The properties `input` and `$_` are aliases for each other. When this | 376 // The properties `input` and `$_` are aliases for each other. When this |
378 // value is set the value it is set to is coerced to a string. | 377 // value is set the value it is set to is coerced to a string. |
379 // Getter and setter for the input. | 378 // Getter and setter for the input. |
380 var RegExpGetInput = function() { | 379 var RegExpGetInput = function() { |
381 var regExpInput = LAST_INPUT($regexpLastMatchInfo); | 380 var regExpInput = LAST_INPUT($regexpLastMatchInfo); |
382 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; | 381 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 %DefineAccessorPropertyUnchecked(GlobalRegExp, '$' + i, | 436 %DefineAccessorPropertyUnchecked(GlobalRegExp, '$' + i, |
438 RegExpMakeCaptureGetter(i), NoOpSetter, | 437 RegExpMakeCaptureGetter(i), NoOpSetter, |
439 DONT_DELETE); | 438 DONT_DELETE); |
440 } | 439 } |
441 %ToFastProperties(GlobalRegExp); | 440 %ToFastProperties(GlobalRegExp); |
442 | 441 |
443 $regexpExecNoTests = RegExpExecNoTests; | 442 $regexpExecNoTests = RegExpExecNoTests; |
444 $regexpExec = DoRegExpExec; | 443 $regexpExec = DoRegExpExec; |
445 | 444 |
446 })(); | 445 })(); |
OLD | NEW |