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 3// found in the LICENSE file. 4 5(function(global, utils) { 6 7'use strict'; 8 9%CheckIsBootstrapping(); 10 11// ------------------------------------------------------------------- 12// Imports 13 14var GlobalRegExp = global.RegExp; 15var GlobalRegExpPrototype = GlobalRegExp.prototype; 16var MakeTypeError; 17var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol"); 18 19utils.Import(function(from) { 20 MakeTypeError = from.MakeTypeError; 21}); 22 23// ------------------------------------------------------------------- 24 25// ES6 draft 12-06-13, section 21.2.5.3 26// + https://bugs.ecmascript.org/show_bug.cgi?id=3423 27function RegExpGetFlags() { 28 if (!IS_RECEIVER(this)) { 29 throw MakeTypeError( 30 kRegExpNonObject, "RegExp.prototype.flags", TO_STRING(this)); 31 } 32 var result = ''; 33 if (this.global) result += 'g'; 34 if (this.ignoreCase) result += 'i'; 35 if (this.multiline) result += 'm'; 36 if (this.unicode) result += 'u'; 37 if (this.sticky) result += 'y'; 38 return result; 39} 40 41// ES6 21.2.5.12. 42function RegExpGetSticky() { 43 if (!IS_REGEXP(this)) { 44 // Compat fix: RegExp.prototype.sticky == undefined; UseCounter tracks it 45 // TODO(littledan): Remove this workaround or standardize it 46 if (this === GlobalRegExpPrototype) { 47 %IncrementUseCounter(kRegExpPrototypeStickyGetter); 48 return UNDEFINED; 49 } 50 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky"); 51 } 52 return !!REGEXP_STICKY(this); 53} 54%FunctionSetName(RegExpGetSticky, "RegExp.prototype.sticky"); 55%SetNativeFlag(RegExpGetSticky); 56 57utils.InstallGetter(GlobalRegExp.prototype, 'flags', RegExpGetFlags); 58utils.InstallGetter(GlobalRegExp.prototype, 'sticky', RegExpGetSticky); 59 60}) 61