| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var GlobalRegExp = global.RegExp; | 14 var GlobalRegExp = global.RegExp; |
| 15 var GlobalRegExpPrototype = GlobalRegExp.prototype; |
| 15 var MakeTypeError; | 16 var MakeTypeError; |
| 16 var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol"); | 17 var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol"); |
| 17 | 18 |
| 18 utils.Import(function(from) { | 19 utils.Import(function(from) { |
| 19 MakeTypeError = from.MakeTypeError; | 20 MakeTypeError = from.MakeTypeError; |
| 20 }); | 21 }); |
| 21 | 22 |
| 22 // ------------------------------------------------------------------- | 23 // ------------------------------------------------------------------- |
| 23 | 24 |
| 24 // ES6 draft 12-06-13, section 21.2.5.3 | 25 // ES6 draft 12-06-13, section 21.2.5.3 |
| 25 // + https://bugs.ecmascript.org/show_bug.cgi?id=3423 | 26 // + https://bugs.ecmascript.org/show_bug.cgi?id=3423 |
| 26 function RegExpGetFlags() { | 27 function RegExpGetFlags() { |
| 27 if (!IS_RECEIVER(this)) { | 28 if (!IS_RECEIVER(this)) { |
| 28 throw MakeTypeError( | 29 throw MakeTypeError( |
| 29 kRegExpNonObject, "RegExp.prototype.flags", TO_STRING(this)); | 30 kRegExpNonObject, "RegExp.prototype.flags", TO_STRING(this)); |
| 30 } | 31 } |
| 31 var result = ''; | 32 var result = ''; |
| 32 if (this.global) result += 'g'; | 33 if (this.global) result += 'g'; |
| 33 if (this.ignoreCase) result += 'i'; | 34 if (this.ignoreCase) result += 'i'; |
| 34 if (this.multiline) result += 'm'; | 35 if (this.multiline) result += 'm'; |
| 35 if (this.unicode) result += 'u'; | 36 if (this.unicode) result += 'u'; |
| 36 if (this.sticky) result += 'y'; | 37 if (this.sticky) result += 'y'; |
| 37 return result; | 38 return result; |
| 38 } | 39 } |
| 39 | 40 |
| 41 const kRegExpPrototypeStickyGetter = 11; |
| 40 | 42 |
| 41 // ES6 21.2.5.12. | 43 // ES6 21.2.5.12. |
| 42 function RegExpGetSticky() { | 44 function RegExpGetSticky() { |
| 43 if (!IS_REGEXP(this)) { | 45 if (!IS_REGEXP(this)) { |
| 46 // Compat fix: RegExp.prototype.sticky == undefined; UseCounter tracks it |
| 47 // TODO(littledan): Remove this workaround or standardize it |
| 48 if (this === GlobalRegExpPrototype) { |
| 49 %IncrementUseCounter(kRegExpPrototypeStickyGetter); |
| 50 return UNDEFINED; |
| 51 } |
| 44 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky"); | 52 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky"); |
| 45 } | 53 } |
| 46 return !!REGEXP_STICKY(this); | 54 return !!REGEXP_STICKY(this); |
| 47 } | 55 } |
| 48 %FunctionSetName(RegExpGetSticky, "RegExp.prototype.sticky"); | 56 %FunctionSetName(RegExpGetSticky, "RegExp.prototype.sticky"); |
| 49 %SetNativeFlag(RegExpGetSticky); | 57 %SetNativeFlag(RegExpGetSticky); |
| 50 | 58 |
| 51 | 59 |
| 52 // ES6 21.2.5.15. | 60 // ES6 21.2.5.15. |
| 53 function RegExpGetUnicode() { | 61 function RegExpGetUnicode() { |
| 54 if (!IS_REGEXP(this)) { | 62 if (!IS_REGEXP(this)) { |
| 55 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.unicode"); | 63 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.unicode"); |
| 56 } | 64 } |
| 57 return !!REGEXP_UNICODE(this); | 65 return !!REGEXP_UNICODE(this); |
| 58 } | 66 } |
| 59 %FunctionSetName(RegExpGetUnicode, "RegExp.prototype.unicode"); | 67 %FunctionSetName(RegExpGetUnicode, "RegExp.prototype.unicode"); |
| 60 %SetNativeFlag(RegExpGetUnicode); | 68 %SetNativeFlag(RegExpGetUnicode); |
| 61 | 69 |
| 62 utils.InstallGetter(GlobalRegExp.prototype, 'flags', RegExpGetFlags); | 70 utils.InstallGetter(GlobalRegExp.prototype, 'flags', RegExpGetFlags); |
| 63 utils.InstallGetter(GlobalRegExp.prototype, 'sticky', RegExpGetSticky); | 71 utils.InstallGetter(GlobalRegExp.prototype, 'sticky', RegExpGetSticky); |
| 64 utils.InstallGetter(GlobalRegExp.prototype, 'unicode', RegExpGetUnicode); | 72 utils.InstallGetter(GlobalRegExp.prototype, 'unicode', RegExpGetUnicode); |
| 65 | 73 |
| 66 }) | 74 }) |
| OLD | NEW |