mirrored from https://chromium.googlesource.com/v8/v8.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the
RegExp.prototype.flags
getter
TEST=mjsunit/harmony BUG=v8:3751 LOG=N Review URL: https://codereview.chromium.org/770333005 Cr-Commit-Position: refs/heads/master@{#25762}
- Loading branch information
1 parent
059482b
commit 33f0cf5
Showing
6 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2014 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
'use strict'; | ||
|
||
var $RegExp = global.RegExp; | ||
|
||
// ------------------------------------------------------------------- | ||
|
||
// ES6 draft 12-06-13, section 21.2.5.3 | ||
// + https://bugs.ecmascript.org/show_bug.cgi?id=3423 | ||
function RegExpGetFlags() { | ||
if (!IS_SPEC_OBJECT(this)) { | ||
throw MakeTypeError('flags_getter_non_object', | ||
[%ToString(this)]); | ||
} | ||
var result = ''; | ||
if (this.global) result += 'g'; | ||
if (this.ignoreCase) result += 'i'; | ||
if (this.multiline) result += 'm'; | ||
if (this.unicode) result += 'u'; | ||
if (this.sticky) result += 'y'; | ||
return result; | ||
} | ||
|
||
function ExtendRegExpPrototype() { | ||
%CheckIsBootstrapping(); | ||
|
||
%DefineAccessorPropertyUnchecked($RegExp.prototype, 'flags', RegExpGetFlags, | ||
null, DONT_ENUM | DONT_DELETE); | ||
%SetNativeFlag(RegExpGetFlags); | ||
} | ||
|
||
ExtendRegExpPrototype(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2014 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Flags: --harmony-regexps | ||
|
||
delete RegExp.prototype.flags; | ||
RegExp.prototype.flags = 'setter should be undefined'; | ||
|
||
assertEquals('', RegExp('').flags); | ||
assertEquals('', /./.flags); | ||
assertEquals('gimy', RegExp('', 'ygmi').flags); | ||
assertEquals('gimy', /foo/ymig.flags); | ||
|
||
// TODO(dslomov): When support for the `u` flag is added, uncomment the first | ||
// line below and remove the second line. | ||
//assertEquals(RegExp('', 'yumig').flags, 'gimuy'); | ||
assertThrows(function() { RegExp('', 'yumig').flags; }, SyntaxError); | ||
|
||
var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); | ||
assertFalse(descriptor.configurable); | ||
assertFalse(descriptor.enumerable); | ||
assertInstanceof(descriptor.get, Function); | ||
assertEquals(undefined, descriptor.set); | ||
|
||
function testGenericFlags(object) { | ||
return descriptor.get.call(object); | ||
} | ||
|
||
assertEquals('', testGenericFlags({})); | ||
assertEquals('i', testGenericFlags({ ignoreCase: true })); | ||
assertEquals('uy', testGenericFlags({ global: 0, sticky: 1, unicode: 1 })); | ||
assertEquals('m', testGenericFlags({ __proto__: { multiline: true } })); | ||
assertThrows(function() { testGenericFlags(); }, TypeError); | ||
assertThrows(function() { testGenericFlags(undefined); }, TypeError); | ||
assertThrows(function() { testGenericFlags(null); }, TypeError); | ||
assertThrows(function() { testGenericFlags(true); }, TypeError); | ||
assertThrows(function() { testGenericFlags(false); }, TypeError); | ||
assertThrows(function() { testGenericFlags(''); }, TypeError); | ||
assertThrows(function() { testGenericFlags(42); }, TypeError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters