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 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 264 } |
265 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); | 265 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) | 269 // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) |
270 function RegExpSubclassExec(regexp, string) { | 270 function RegExpSubclassExec(regexp, string) { |
271 var exec = regexp.exec; | 271 var exec = regexp.exec; |
272 if (IS_CALLABLE(exec)) { | 272 if (IS_CALLABLE(exec)) { |
273 var result = %_Call(exec, regexp, string); | 273 var result = %_Call(exec, regexp, string); |
274 if (!IS_OBJECT(result) && !IS_NULL(result)) { | 274 if (!IS_RECEIVER(result) && !IS_NULL(result)) { |
275 throw MakeTypeError(kInvalidRegExpExecResult); | 275 throw MakeTypeError(kInvalidRegExpExecResult); |
276 } | 276 } |
277 return result; | 277 return result; |
278 } | 278 } |
279 return %_Call(RegExpExecJS, regexp, string); | 279 return %_Call(RegExpExecJS, regexp, string); |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 // One-element cache for the simplified test regexp. | 283 // One-element cache for the simplified test regexp. |
284 var regexp_key; | 284 var regexp_key; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 this.lastIndex = 0; | 334 this.lastIndex = 0; |
335 return false; | 335 return false; |
336 } | 336 } |
337 return true; | 337 return true; |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 | 341 |
342 // ES#sec-regexp.prototype.test RegExp.prototype.test ( S ) | 342 // ES#sec-regexp.prototype.test RegExp.prototype.test ( S ) |
343 function RegExpSubclassTest(string) { | 343 function RegExpSubclassTest(string) { |
344 if (!IS_OBJECT(this)) { | 344 if (!IS_RECEIVER(this)) { |
345 throw MakeTypeError(kIncompatibleMethodReceiver, | 345 throw MakeTypeError(kIncompatibleMethodReceiver, |
346 'RegExp.prototype.test', this); | 346 'RegExp.prototype.test', this); |
347 } | 347 } |
348 string = TO_STRING(string); | 348 string = TO_STRING(string); |
349 var match = RegExpSubclassExec(this, string); | 349 var match = RegExpSubclassExec(this, string); |
350 return !IS_NULL(match); | 350 return !IS_NULL(match); |
351 } | 351 } |
352 %FunctionRemovePrototype(RegExpSubclassTest); | 352 %FunctionRemovePrototype(RegExpSubclassTest); |
353 | 353 |
354 function TrimRegExp(regexp) { | 354 function TrimRegExp(regexp) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 if (!REGEXP_GLOBAL(this)) return RegExpExecNoTests(this, subject, 0); | 545 if (!REGEXP_GLOBAL(this)) return RegExpExecNoTests(this, subject, 0); |
546 this.lastIndex = 0; | 546 this.lastIndex = 0; |
547 var result = %StringMatch(subject, this, RegExpLastMatchInfo); | 547 var result = %StringMatch(subject, this, RegExpLastMatchInfo); |
548 return result; | 548 return result; |
549 } | 549 } |
550 | 550 |
551 | 551 |
552 // ES#sec-regexp.prototype-@@match | 552 // ES#sec-regexp.prototype-@@match |
553 // RegExp.prototype [ @@match ] ( string ) | 553 // RegExp.prototype [ @@match ] ( string ) |
554 function RegExpSubclassMatch(string) { | 554 function RegExpSubclassMatch(string) { |
555 if (!IS_OBJECT(this)) { | 555 if (!IS_RECEIVER(this)) { |
556 throw MakeTypeError(kIncompatibleMethodReceiver, | 556 throw MakeTypeError(kIncompatibleMethodReceiver, |
557 "RegExp.prototype.@@match", this); | 557 "RegExp.prototype.@@match", this); |
558 } | 558 } |
559 string = TO_STRING(string); | 559 string = TO_STRING(string); |
560 var global = this.global; | 560 var global = this.global; |
561 if (!global) return RegExpSubclassExec(this, string); | 561 if (!global) return RegExpSubclassExec(this, string); |
562 var unicode = this.unicode; | 562 var unicode = this.unicode; |
563 this.lastIndex = 0; | 563 this.lastIndex = 0; |
564 var array = []; | 564 var array = []; |
565 var n = 0; | 565 var n = 0; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 function SetAdvancedStringIndex(regexp, string, unicode) { | 856 function SetAdvancedStringIndex(regexp, string, unicode) { |
857 var lastIndex = regexp.lastIndex; | 857 var lastIndex = regexp.lastIndex; |
858 regexp.lastIndex = lastIndex + | 858 regexp.lastIndex = lastIndex + |
859 AdvanceStringIndex(string, lastIndex, unicode); | 859 AdvanceStringIndex(string, lastIndex, unicode); |
860 } | 860 } |
861 | 861 |
862 | 862 |
863 // ES#sec-regexp.prototype-@@replace | 863 // ES#sec-regexp.prototype-@@replace |
864 // RegExp.prototype [ @@replace ] ( string, replaceValue ) | 864 // RegExp.prototype [ @@replace ] ( string, replaceValue ) |
865 function RegExpSubclassReplace(string, replace) { | 865 function RegExpSubclassReplace(string, replace) { |
866 if (!IS_OBJECT(this)) { | 866 if (!IS_RECEIVER(this)) { |
867 throw MakeTypeError(kIncompatibleMethodReceiver, | 867 throw MakeTypeError(kIncompatibleMethodReceiver, |
868 "RegExp.prototype.@@replace", this); | 868 "RegExp.prototype.@@replace", this); |
869 } | 869 } |
870 string = TO_STRING(string); | 870 string = TO_STRING(string); |
871 var length = string.length; | 871 var length = string.length; |
872 var functionalReplace = IS_CALLABLE(replace); | 872 var functionalReplace = IS_CALLABLE(replace); |
873 if (!functionalReplace) replace = TO_STRING(replace); | 873 if (!functionalReplace) replace = TO_STRING(replace); |
874 var global = this.global; | 874 var global = this.global; |
875 if (global) { | 875 if (global) { |
876 var unicode = this.unicode; | 876 var unicode = this.unicode; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 } | 937 } |
938 var match = DoRegExpExec(this, TO_STRING(string), 0); | 938 var match = DoRegExpExec(this, TO_STRING(string), 0); |
939 if (match) return match[CAPTURE0]; | 939 if (match) return match[CAPTURE0]; |
940 return -1; | 940 return -1; |
941 } | 941 } |
942 | 942 |
943 | 943 |
944 // ES#sec-regexp.prototype-@@search | 944 // ES#sec-regexp.prototype-@@search |
945 // RegExp.prototype [ @@search ] ( string ) | 945 // RegExp.prototype [ @@search ] ( string ) |
946 function RegExpSubclassSearch(string) { | 946 function RegExpSubclassSearch(string) { |
947 if (!IS_OBJECT(this)) { | 947 if (!IS_RECEIVER(this)) { |
948 throw MakeTypeError(kIncompatibleMethodReceiver, | 948 throw MakeTypeError(kIncompatibleMethodReceiver, |
949 "RegExp.prototype.@@search", this); | 949 "RegExp.prototype.@@search", this); |
950 } | 950 } |
951 string = TO_STRING(string); | 951 string = TO_STRING(string); |
952 var previousLastIndex = this.lastIndex; | 952 var previousLastIndex = this.lastIndex; |
953 this.lastIndex = 0; | 953 this.lastIndex = 0; |
954 var result = RegExpSubclassExec(this, string); | 954 var result = RegExpSubclassExec(this, string); |
955 this.lastIndex = previousLastIndex; | 955 this.lastIndex = previousLastIndex; |
956 if (IS_NULL(result)) return -1; | 956 if (IS_NULL(result)) return -1; |
957 return result.index; | 957 return result.index; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 to.RegExpSubclassMatch = RegExpSubclassMatch; | 1163 to.RegExpSubclassMatch = RegExpSubclassMatch; |
1164 to.RegExpSubclassReplace = RegExpSubclassReplace; | 1164 to.RegExpSubclassReplace = RegExpSubclassReplace; |
1165 to.RegExpSubclassSearch = RegExpSubclassSearch; | 1165 to.RegExpSubclassSearch = RegExpSubclassSearch; |
1166 to.RegExpSubclassSplit = RegExpSubclassSplit; | 1166 to.RegExpSubclassSplit = RegExpSubclassSplit; |
1167 to.RegExpSubclassTest = RegExpSubclassTest; | 1167 to.RegExpSubclassTest = RegExpSubclassTest; |
1168 to.RegExpTest = RegExpTest; | 1168 to.RegExpTest = RegExpTest; |
1169 to.IsRegExp = IsRegExp; | 1169 to.IsRegExp = IsRegExp; |
1170 }); | 1170 }); |
1171 | 1171 |
1172 }) | 1172 }) |
OLD | NEW |