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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 DoConstructRegExp(this, pattern, flags); | 88 DoConstructRegExp(this, pattern, flags); |
89 } else { | 89 } else { |
90 // RegExp : Called as function; see ECMA-262, section 15.10.3.1. | 90 // RegExp : Called as function; see ECMA-262, section 15.10.3.1. |
91 if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) { | 91 if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) { |
92 return pattern; | 92 return pattern; |
93 } | 93 } |
94 return new $RegExp(pattern, flags); | 94 return new $RegExp(pattern, flags); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 | |
99 // Deprecated RegExp.prototype.compile method. We behave like the constructor | 98 // Deprecated RegExp.prototype.compile method. We behave like the constructor |
100 // were called again. In SpiderMonkey, this method returns the regexp object. | 99 // were called again. In SpiderMonkey, this method returns the regexp object. |
101 // In JSC, it returns undefined. For compatibility with JSC, we match their | 100 // In JSC, it returns undefined. For compatibility with JSC, we match their |
102 // behavior. | 101 // behavior. |
103 function CompileRegExp(pattern, flags) { | 102 function RegExpCompile(pattern, flags) { |
104 // Both JSC and SpiderMonkey treat a missing pattern argument as the | 103 // Both JSC and SpiderMonkey treat a missing pattern argument as the |
105 // empty subject string, and an actual undefined value passed as the | 104 // empty subject string, and an actual undefined value passed as the |
106 // pattern as the string 'undefined'. Note that JSC is inconsistent | 105 // pattern as the string 'undefined'. Note that JSC is inconsistent |
107 // here, treating undefined values differently in | 106 // here, treating undefined values differently in |
108 // RegExp.prototype.compile and in the constructor, where they are | 107 // RegExp.prototype.compile and in the constructor, where they are |
109 // the empty string. For compatibility with JSC, we match their | 108 // the empty string. For compatibility with JSC, we match their |
110 // behavior. | 109 // behavior. |
| 110 if (this == $RegExp.prototype) { |
| 111 // We don't allow recompiling RegExp.prototype. |
| 112 throw MakeTypeError('incompatible_method_receiver', |
| 113 ['RegExp.prototype.compile', this]); |
| 114 } |
111 if (IS_UNDEFINED(pattern) && %_ArgumentsLength() != 0) { | 115 if (IS_UNDEFINED(pattern) && %_ArgumentsLength() != 0) { |
112 DoConstructRegExp(this, 'undefined', flags); | 116 DoConstructRegExp(this, 'undefined', flags); |
113 } else { | 117 } else { |
114 DoConstructRegExp(this, pattern, flags); | 118 DoConstructRegExp(this, pattern, flags); |
115 } | 119 } |
116 } | 120 } |
117 | 121 |
118 | 122 |
119 function DoRegExpExec(regexp, string, index) { | 123 function DoRegExpExec(regexp, string, index) { |
120 var result = %_RegExpExec(regexp, string, index, lastMatchInfo); | 124 var result = %_RegExpExec(regexp, string, index, lastMatchInfo); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // Used internally by replace regexp with function. | 405 // Used internally by replace regexp with function. |
402 // The array has the format of an "apply" argument for a replacement | 406 // The array has the format of an "apply" argument for a replacement |
403 // function. | 407 // function. |
404 var lastMatchInfoOverride = null; | 408 var lastMatchInfoOverride = null; |
405 | 409 |
406 // ------------------------------------------------------------------- | 410 // ------------------------------------------------------------------- |
407 | 411 |
408 function SetUpRegExp() { | 412 function SetUpRegExp() { |
409 %CheckIsBootstrapping(); | 413 %CheckIsBootstrapping(); |
410 %FunctionSetInstanceClassName($RegExp, 'RegExp'); | 414 %FunctionSetInstanceClassName($RegExp, 'RegExp'); |
411 %FunctionSetPrototype($RegExp, new $Object()); | |
412 %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); | 415 %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); |
413 %SetCode($RegExp, RegExpConstructor); | 416 %SetCode($RegExp, RegExpConstructor); |
414 | 417 |
415 InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( | 418 InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( |
416 "exec", RegExpExec, | 419 "exec", RegExpExec, |
417 "test", RegExpTest, | 420 "test", RegExpTest, |
418 "toString", RegExpToString, | 421 "toString", RegExpToString, |
419 "compile", CompileRegExp | 422 "compile", RegExpCompile |
420 )); | 423 )); |
421 | 424 |
422 // The length of compile is 1 in SpiderMonkey. | 425 // The length of compile is 1 in SpiderMonkey. |
423 %FunctionSetLength($RegExp.prototype.compile, 1); | 426 %FunctionSetLength($RegExp.prototype.compile, 1); |
424 | 427 |
425 // The properties input, $input, and $_ are aliases for each other. When this | 428 // The properties input, $input, and $_ are aliases for each other. When this |
426 // value is set the value it is set to is coerced to a string. | 429 // value is set the value it is set to is coerced to a string. |
427 // Getter and setter for the input. | 430 // Getter and setter for the input. |
428 function RegExpGetInput() { | 431 function RegExpGetInput() { |
429 var regExpInput = LAST_INPUT(lastMatchInfo); | 432 var regExpInput = LAST_INPUT(lastMatchInfo); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 %DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext, DONT_ENUM | DONT
_DELETE); | 482 %DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext, DONT_ENUM | DONT
_DELETE); |
480 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 483 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
481 | 484 |
482 for (var i = 1; i < 10; ++i) { | 485 for (var i = 1; i < 10; ++i) { |
483 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); | 486 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); |
484 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 487 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
485 } | 488 } |
486 } | 489 } |
487 | 490 |
488 SetUpRegExp(); | 491 SetUpRegExp(); |
OLD | NEW |