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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 function RegExpGetInput() { |
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 function RegExpSetInput(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 %DefineOrRedefineAccessorProperty($RegExp, 'input', GETTER, RegExpGetInput, |
425 %DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE); | 425 DONT_DELETE); |
426 %DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, | 426 %DefineOrRedefineAccessorProperty($RegExp, 'input', SETTER, RegExpSetInput, |
427 DONT_ENUM | DONT_DELETE); | 427 DONT_DELETE); |
428 %DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, | 428 %DefineOrRedefineAccessorProperty($RegExp, '$_', GETTER, RegExpGetInput, |
429 DONT_ENUM | DONT_DELETE); | 429 DONT_ENUM | DONT_DELETE); |
430 %DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, | 430 %DefineOrRedefineAccessorProperty($RegExp, '$_', SETTER, RegExpSetInput, |
431 DONT_ENUM | DONT_DELETE); | 431 DONT_ENUM | DONT_DELETE); |
432 %DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, | 432 %DefineOrRedefineAccessorProperty($RegExp, '$input', GETTER, RegExpGetInput, |
433 DONT_ENUM | DONT_DELETE); | 433 DONT_ENUM | DONT_DELETE); |
434 %DefineOrRedefineAccessorProperty($RegExp, '$input', SETTER, RegExpSetInput, | |
435 DONT_ENUM | DONT_DELETE); | |
434 | 436 |
435 // The properties multiline and $* are aliases for each other. When this | 437 // 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 | 438 // 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 | 439 // boolean. We mimic that behavior with a slight difference: in SpiderMonkey |
438 // the value of the expression 'RegExp.multiline = null' (for instance) is the | 440 // 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 | 441 // boolean false (i.e., the value after coercion), while in V8 it is the value |
440 // null (i.e., the value before coercion). | 442 // null (i.e., the value before coercion). |
441 | 443 |
442 // Getter and setter for multiline. | 444 // Getter and setter for multiline. |
443 var multiline = false; | 445 var multiline = false; |
444 function RegExpGetMultiline() { return multiline; } | 446 function RegExpGetMultiline() { return multiline; } |
445 function RegExpSetMultiline(flag) { multiline = flag ? true : false; } | 447 function RegExpSetMultiline(flag) { multiline = flag ? true : false; } |
446 | 448 |
447 %DefineAccessor($RegExp, 'multiline', GETTER, RegExpGetMultiline, | 449 %DefineOrRedefineAccessorProperty($RegExp, 'multiline', GETTER, |
448 DONT_DELETE); | 450 RegExpGetMultiline, DONT_DELETE); |
449 %DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, | 451 %DefineOrRedefineAccessorProperty($RegExp, 'multiline', SETTER, |
450 DONT_DELETE); | 452 RegExpSetMultiline, DONT_DELETE); |
451 %DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, | 453 %DefineOrRedefineAccessorProperty($RegExp, '$*', GETTER, RegExpGetMultiline, |
452 DONT_ENUM | DONT_DELETE); | 454 DONT_ENUM | DONT_DELETE); |
453 %DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, | 455 %DefineOrRedefineAccessorProperty($RegExp, '$*', SETTER, RegExpSetMultiline, |
454 DONT_ENUM | DONT_DELETE); | 456 DONT_ENUM | DONT_DELETE); |
455 | 457 |
456 | 458 |
457 function NoOpSetter(ignored) {} | 459 function NoOpSetter(ignored) {} |
458 | 460 |
459 | 461 |
460 // Static properties set by a successful match. | 462 // Static properties set by a successful match. |
461 %DefineAccessor($RegExp, 'lastMatch', GETTER, RegExpGetLastMatch, | 463 %DefineOrRedefineAccessorProperty($RegExp, 'lastMatch', GETTER, |
462 DONT_DELETE); | 464 RegExpGetLastMatch, DONT_DELETE); |
463 %DefineAccessor($RegExp, 'lastMatch', SETTER, NoOpSetter, DONT_DELETE); | 465 %DefineOrRedefineAccessorProperty($RegExp, 'lastMatch', SETTER, NoOpSetter, |
464 %DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch, | 466 DONT_DELETE); |
465 DONT_ENUM | DONT_DELETE); | 467 %DefineOrRedefineAccessorProperty($RegExp, '$&', GETTER, RegExpGetLastMatch, |
466 %DefineAccessor($RegExp, '$&', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 468 DONT_ENUM | DONT_DELETE); |
467 %DefineAccessor($RegExp, 'lastParen', GETTER, RegExpGetLastParen, | 469 %DefineOrRedefineAccessorProperty($RegExp, '$&', SETTER, NoOpSetter, |
468 DONT_DELETE); | 470 DONT_ENUM | DONT_DELETE); |
469 %DefineAccessor($RegExp, 'lastParen', SETTER, NoOpSetter, DONT_DELETE); | 471 %DefineOrRedefineAccessorProperty($RegExp, 'lastParen', GETTER, |
Michael Starzinger
2012/02/21 12:14:28
Should fit into two lines.
Sven Panne
2012/02/21 12:23:31
Done.
| |
470 %DefineAccessor($RegExp, '$+', GETTER, RegExpGetLastParen, | 472 RegExpGetLastParen, |
471 DONT_ENUM | DONT_DELETE); | 473 DONT_DELETE); |
472 %DefineAccessor($RegExp, '$+', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 474 %DefineOrRedefineAccessorProperty($RegExp, 'lastParen', SETTER, NoOpSetter, |
473 %DefineAccessor($RegExp, 'leftContext', GETTER, RegExpGetLeftContext, | 475 DONT_DELETE); |
474 DONT_DELETE); | 476 %DefineOrRedefineAccessorProperty($RegExp, '$+', GETTER, RegExpGetLastParen, |
475 %DefineAccessor($RegExp, 'leftContext', SETTER, NoOpSetter, DONT_DELETE); | 477 DONT_ENUM | DONT_DELETE); |
476 %DefineAccessor($RegExp, '$`', GETTER, RegExpGetLeftContext, | 478 %DefineOrRedefineAccessorProperty($RegExp, '$+', SETTER, NoOpSetter, |
477 DONT_ENUM | DONT_DELETE); | 479 DONT_ENUM | DONT_DELETE); |
478 %DefineAccessor($RegExp, '$`', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 480 %DefineOrRedefineAccessorProperty($RegExp, 'leftContext', GETTER, |
479 %DefineAccessor($RegExp, 'rightContext', GETTER, RegExpGetRightContext, | 481 RegExpGetLeftContext, DONT_DELETE); |
480 DONT_DELETE); | 482 %DefineOrRedefineAccessorProperty($RegExp, 'leftContext', SETTER, NoOpSetter, |
481 %DefineAccessor($RegExp, 'rightContext', SETTER, NoOpSetter, DONT_DELETE); | 483 DONT_DELETE); |
482 %DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext, | 484 %DefineOrRedefineAccessorProperty($RegExp, '$`', GETTER, RegExpGetLeftContext, |
483 DONT_ENUM | DONT_DELETE); | 485 DONT_ENUM | DONT_DELETE); |
484 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 486 %DefineOrRedefineAccessorProperty($RegExp, '$`', SETTER, NoOpSetter, |
487 DONT_ENUM | DONT_DELETE); | |
488 %DefineOrRedefineAccessorProperty($RegExp, 'rightContext', GETTER, | |
489 RegExpGetRightContext, DONT_DELETE); | |
490 %DefineOrRedefineAccessorProperty($RegExp, 'rightContext', SETTER, NoOpSetter, | |
491 DONT_DELETE); | |
492 %DefineOrRedefineAccessorProperty($RegExp, "$'", GETTER, | |
493 RegExpGetRightContext, | |
494 DONT_ENUM | DONT_DELETE); | |
495 %DefineOrRedefineAccessorProperty($RegExp, "$'", SETTER, NoOpSetter, | |
496 DONT_ENUM | DONT_DELETE); | |
485 | 497 |
486 for (var i = 1; i < 10; ++i) { | 498 for (var i = 1; i < 10; ++i) { |
487 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), | 499 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, GETTER, |
488 DONT_DELETE); | 500 RegExpMakeCaptureGetter(i), DONT_DELETE); |
489 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 501 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, SETTER, NoOpSetter, |
502 DONT_DELETE); | |
490 } | 503 } |
491 } | 504 } |
492 | 505 |
493 SetUpRegExp(); | 506 SetUpRegExp(); |
OLD | NEW |