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 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
8 | 8 |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 // Imports | 10 // Imports |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 regexp_val = | 263 regexp_val = |
264 new GlobalRegExp( | 264 new GlobalRegExp( |
265 %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length), | 265 %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length), |
266 (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i" | 266 (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i" |
267 : REGEXP_MULTILINE(regexp) ? "m" : "")); | 267 : REGEXP_MULTILINE(regexp) ? "m" : "")); |
268 } | 268 } |
269 return regexp_val; | 269 return regexp_val; |
270 } | 270 } |
271 | 271 |
272 | 272 |
273 const kRegExpPrototypeToString = 12; | |
274 | |
275 function RegExpToString() { | 273 function RegExpToString() { |
276 if (!IS_REGEXP(this)) { | 274 if (!IS_REGEXP(this)) { |
277 // RegExp.prototype.toString() returns '/(?:)/' as a compatibility fix; | |
278 // a UseCounter is incremented to track it. | |
279 // TODO(littledan): Remove this workaround or standardize it | |
280 if (this === GlobalRegExpPrototype) { | |
281 %IncrementUseCounter(kRegExpPrototypeToString); | |
282 return '/(?:)/'; | |
283 } | |
284 throw MakeTypeError(kIncompatibleMethodReceiver, | 275 throw MakeTypeError(kIncompatibleMethodReceiver, |
285 'RegExp.prototype.toString', this); | 276 'RegExp.prototype.toString', this); |
286 } | 277 } |
287 var result = '/' + REGEXP_SOURCE(this) + '/'; | 278 var result = '/' + REGEXP_SOURCE(this) + '/'; |
288 if (REGEXP_GLOBAL(this)) result += 'g'; | 279 if (REGEXP_GLOBAL(this)) result += 'g'; |
289 if (REGEXP_IGNORE_CASE(this)) result += 'i'; | 280 if (REGEXP_IGNORE_CASE(this)) result += 'i'; |
290 if (REGEXP_MULTILINE(this)) result += 'm'; | 281 if (REGEXP_MULTILINE(this)) result += 'm'; |
291 if (REGEXP_UNICODE(this)) result += 'u'; | 282 if (REGEXP_UNICODE(this)) result += 'u'; |
292 if (REGEXP_STICKY(this)) result += 'y'; | 283 if (REGEXP_STICKY(this)) result += 'y'; |
293 return result; | 284 return result; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source"); | 484 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source"); |
494 } | 485 } |
495 return REGEXP_SOURCE(this); | 486 return REGEXP_SOURCE(this); |
496 } | 487 } |
497 %FunctionSetName(RegExpGetSource, "RegExp.prototype.source"); | 488 %FunctionSetName(RegExpGetSource, "RegExp.prototype.source"); |
498 %SetNativeFlag(RegExpGetSource); | 489 %SetNativeFlag(RegExpGetSource); |
499 | 490 |
500 // ------------------------------------------------------------------- | 491 // ------------------------------------------------------------------- |
501 | 492 |
502 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); | 493 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); |
503 const GlobalRegExpPrototype = new GlobalObject(); | 494 %FunctionSetPrototype(GlobalRegExp, new GlobalObject()); |
504 %FunctionSetPrototype(GlobalRegExp, GlobalRegExpPrototype); | |
505 %AddNamedProperty( | 495 %AddNamedProperty( |
506 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); | 496 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); |
507 %SetCode(GlobalRegExp, RegExpConstructor); | 497 %SetCode(GlobalRegExp, RegExpConstructor); |
508 | 498 |
509 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ | 499 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
510 "exec", RegExpExecJS, | 500 "exec", RegExpExecJS, |
511 "test", RegExpTest, | 501 "test", RegExpTest, |
512 "toString", RegExpToString, | 502 "toString", RegExpToString, |
513 "compile", RegExpCompileJS, | 503 "compile", RegExpCompileJS, |
514 matchSymbol, RegExpMatch, | 504 matchSymbol, RegExpMatch, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // Exports | 563 // Exports |
574 | 564 |
575 utils.Export(function(to) { | 565 utils.Export(function(to) { |
576 to.RegExpExec = DoRegExpExec; | 566 to.RegExpExec = DoRegExpExec; |
577 to.RegExpExecNoTests = RegExpExecNoTests; | 567 to.RegExpExecNoTests = RegExpExecNoTests; |
578 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 568 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
579 to.RegExpTest = RegExpTest; | 569 to.RegExpTest = RegExpTest; |
580 }); | 570 }); |
581 | 571 |
582 }) | 572 }) |
OLD | NEW |