OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Expect $Object = global.Object; | 28 // Expect $Object = global.Object; |
29 // Expect $Array = global.Array; | 29 // Expect $Array = global.Array; |
30 | 30 |
31 const $RegExp = global.RegExp; | 31 var $RegExp = global.RegExp; |
32 | 32 |
33 // A recursive descent parser for Patterns according to the grammar of | 33 // A recursive descent parser for Patterns according to the grammar of |
34 // ECMA-262 15.10.1, with deviations noted below. | 34 // ECMA-262 15.10.1, with deviations noted below. |
35 function DoConstructRegExp(object, pattern, flags) { | 35 function DoConstructRegExp(object, pattern, flags) { |
36 // RegExp : Called as constructor; see ECMA-262, section 15.10.4. | 36 // RegExp : Called as constructor; see ECMA-262, section 15.10.4. |
37 if (IS_REGEXP(pattern)) { | 37 if (IS_REGEXP(pattern)) { |
38 if (!IS_UNDEFINED(flags)) { | 38 if (!IS_UNDEFINED(flags)) { |
39 throw MakeTypeError('regexp_flags', []); | 39 throw MakeTypeError('regexp_flags', []); |
40 } | 40 } |
41 flags = (pattern.global ? 'g' : '') | 41 flags = (pattern.global ? 'g' : '') |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 "toString", RegExpToString, | 406 "toString", RegExpToString, |
407 "compile", RegExpCompile | 407 "compile", RegExpCompile |
408 )); | 408 )); |
409 | 409 |
410 // The length of compile is 1 in SpiderMonkey. | 410 // The length of compile is 1 in SpiderMonkey. |
411 %FunctionSetLength($RegExp.prototype.compile, 1); | 411 %FunctionSetLength($RegExp.prototype.compile, 1); |
412 | 412 |
413 // The properties input, $input, and $_ are aliases for each other. When this | 413 // The properties input, $input, and $_ are aliases for each other. When this |
414 // value is set the value it is set to is coerced to a string. | 414 // value is set the value it is set to is coerced to a string. |
415 // Getter and setter for the input. | 415 // Getter and setter for the input. |
416 function RegExpGetInput() { | 416 var RegExpGetInput = function() { |
417 var regExpInput = LAST_INPUT(lastMatchInfo); | 417 var regExpInput = LAST_INPUT(lastMatchInfo); |
418 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; | 418 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; |
419 } | 419 }; |
420 function RegExpSetInput(string) { | 420 var RegExpSetInput = function(string) { |
421 LAST_INPUT(lastMatchInfo) = ToString(string); | 421 LAST_INPUT(lastMatchInfo) = ToString(string); |
422 } | 422 }; |
423 | 423 |
424 %DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE); | 424 %DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE); |
425 %DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE); | 425 %DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE); |
426 %DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, | 426 %DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, |
427 DONT_ENUM | DONT_DELETE); | 427 DONT_ENUM | DONT_DELETE); |
428 %DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, | 428 %DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, |
429 DONT_ENUM | DONT_DELETE); | 429 DONT_ENUM | DONT_DELETE); |
430 %DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, | 430 %DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, |
431 DONT_ENUM | DONT_DELETE); | 431 DONT_ENUM | DONT_DELETE); |
432 %DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, | 432 %DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, |
433 DONT_ENUM | DONT_DELETE); | 433 DONT_ENUM | DONT_DELETE); |
434 | 434 |
435 // The properties multiline and $* are aliases for each other. When this | 435 // The properties multiline and $* are aliases for each other. When this |
436 // value is set in SpiderMonkey, the value it is set to is coerced to a | 436 // value is set in SpiderMonkey, the value it is set to is coerced to a |
437 // boolean. We mimic that behavior with a slight difference: in SpiderMonkey | 437 // boolean. We mimic that behavior with a slight difference: in SpiderMonkey |
438 // the value of the expression 'RegExp.multiline = null' (for instance) is the | 438 // the value of the expression 'RegExp.multiline = null' (for instance) is the |
439 // boolean false (i.e., the value after coercion), while in V8 it is the value | 439 // boolean false (i.e., the value after coercion), while in V8 it is the value |
440 // null (i.e., the value before coercion). | 440 // null (i.e., the value before coercion). |
441 | 441 |
442 // Getter and setter for multiline. | 442 // Getter and setter for multiline. |
443 var multiline = false; | 443 var multiline = false; |
444 function RegExpGetMultiline() { return multiline; } | 444 var RegExpGetMultiline = function() { return multiline; }; |
445 function RegExpSetMultiline(flag) { multiline = flag ? true : false; } | 445 var RegExpSetMultiline = function(flag) { multiline = flag ? true : false; }; |
446 | 446 |
447 %DefineAccessor($RegExp, 'multiline', GETTER, RegExpGetMultiline, | 447 %DefineAccessor($RegExp, 'multiline', GETTER, RegExpGetMultiline, |
448 DONT_DELETE); | 448 DONT_DELETE); |
449 %DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, | 449 %DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, |
450 DONT_DELETE); | 450 DONT_DELETE); |
451 %DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, | 451 %DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, |
452 DONT_ENUM | DONT_DELETE); | 452 DONT_ENUM | DONT_DELETE); |
453 %DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, | 453 %DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, |
454 DONT_ENUM | DONT_DELETE); | 454 DONT_ENUM | DONT_DELETE); |
455 | 455 |
456 | 456 |
457 function NoOpSetter(ignored) {} | 457 var NoOpSetter = function(ignored) {}; |
458 | 458 |
459 | 459 |
460 // Static properties set by a successful match. | 460 // Static properties set by a successful match. |
461 %DefineAccessor($RegExp, 'lastMatch', GETTER, RegExpGetLastMatch, | 461 %DefineAccessor($RegExp, 'lastMatch', GETTER, RegExpGetLastMatch, |
462 DONT_DELETE); | 462 DONT_DELETE); |
463 %DefineAccessor($RegExp, 'lastMatch', SETTER, NoOpSetter, DONT_DELETE); | 463 %DefineAccessor($RegExp, 'lastMatch', SETTER, NoOpSetter, DONT_DELETE); |
464 %DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch, | 464 %DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch, |
465 DONT_ENUM | DONT_DELETE); | 465 DONT_ENUM | DONT_DELETE); |
466 %DefineAccessor($RegExp, '$&', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 466 %DefineAccessor($RegExp, '$&', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
467 %DefineAccessor($RegExp, 'lastParen', GETTER, RegExpGetLastParen, | 467 %DefineAccessor($RegExp, 'lastParen', GETTER, RegExpGetLastParen, |
(...skipping 16 matching lines...) Expand all Loading... |
484 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 484 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
485 | 485 |
486 for (var i = 1; i < 10; ++i) { | 486 for (var i = 1; i < 10; ++i) { |
487 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), | 487 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), |
488 DONT_DELETE); | 488 DONT_DELETE); |
489 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 489 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
490 } | 490 } |
491 } | 491 } |
492 | 492 |
493 SetUpRegExp(); | 493 SetUpRegExp(); |
OLD | NEW |