Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Unified Diff: src/js/regexp.js

Issue 1419823010: Implement flag and source getters on RegExp.prototype. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@rproto
Patch Set: new webkit expectations Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/js/regexp.js
diff --git a/src/js/regexp.js b/src/js/regexp.js
index 51c8ed0d6ee921a523ece0c1e885c6164534ce0d..62279dddfeb6c0267d4b54f341c63d27d8903e4b 100644
--- a/src/js/regexp.js
+++ b/src/js/regexp.js
@@ -9,18 +9,16 @@
// -------------------------------------------------------------------
// Imports
-var FLAG_harmony_regexps;
var FLAG_harmony_tolength;
-var FLAG_harmony_unicode_regexps;
var GlobalObject = global.Object;
var GlobalRegExp = global.RegExp;
var InternalPackedArray = utils.InternalPackedArray;
var MakeTypeError;
+var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
+var regExpSourceSymbol = utils.ImportNow("regexp_source_symbol");
utils.ImportFromExperimental(function(from) {
- FLAG_harmony_regexps = from.FLAG_harmony_regexps;
FLAG_harmony_tolength = from.FLAG_harmony_tolength;
- FLAG_harmony_unicode_regexps = from.FLAG_harmony_unicode_regexps;
});
utils.Import(function(from) {
@@ -51,14 +49,12 @@ function DoConstructRegExp(object, pattern, flags) {
// RegExp : Called as constructor; see ECMA-262, section 15.10.4.
if (IS_REGEXP(pattern)) {
if (!IS_UNDEFINED(flags)) throw MakeTypeError(kRegExpFlags);
- flags = (pattern.global ? 'g' : '')
- + (pattern.ignoreCase ? 'i' : '')
- + (pattern.multiline ? 'm' : '');
- if (FLAG_harmony_unicode_regexps)
- flags += (pattern.unicode ? 'u' : '');
- if (FLAG_harmony_regexps)
- flags += (pattern.sticky ? 'y' : '');
- pattern = pattern.source;
+ flags = (REGEXP_GLOBAL(pattern) ? 'g' : '')
+ + (REGEXP_IGNORE_CASE(pattern) ? 'i' : '')
+ + (REGEXP_MULTILINE(pattern) ? 'm' : '')
+ + (REGEXP_UNICODE(pattern) ? 'u' : '')
+ + (REGEXP_STICKY(pattern) ? 'y' : '');
+ pattern = REGEXP_SOURCE(pattern);
}
pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern);
@@ -142,9 +138,7 @@ function RegExpExecNoTests(regexp, string, start) {
var matchInfo = %_RegExpExec(regexp, string, start, RegExpLastMatchInfo);
if (matchInfo !== null) {
// ES6 21.2.5.2.2 step 18.
- if (FLAG_harmony_regexps && regexp.sticky) {
- regexp.lastIndex = matchInfo[CAPTURE1];
- }
+ if (REGEXP_STICKY(regexp)) regexp.lastIndex = matchInfo[CAPTURE1];
RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, string);
}
regexp.lastIndex = 0;
@@ -165,7 +159,7 @@ function RegExpExecJS(string) {
// algorithm, step 4) even if the value is discarded for non-global RegExps.
var i = TO_LENGTH_OR_INTEGER(lastIndex);
- var updateLastIndex = this.global || (FLAG_harmony_regexps && this.sticky);
+ var updateLastIndex = REGEXP_GLOBAL(this) || REGEXP_STICKY(this);
if (updateLastIndex) {
if (i < 0 || i > string.length) {
this.lastIndex = 0;
@@ -212,7 +206,7 @@ function RegExpTest(string) {
// algorithm, step 4) even if the value is discarded for non-global RegExps.
var i = TO_LENGTH_OR_INTEGER(lastIndex);
- if (this.global || (FLAG_harmony_regexps && this.sticky)) {
+ if (REGEXP_GLOBAL(this) || REGEXP_STICKY(this)) {
if (i < 0 || i > string.length) {
this.lastIndex = 0;
return false;
@@ -231,10 +225,11 @@ function RegExpTest(string) {
// checks whether this.source starts with '.*' and that the third char is
// not a '?'. But see https://code.google.com/p/v8/issues/detail?id=3560
var regexp = this;
- if (regexp.source.length >= 3 &&
- %_StringCharCodeAt(regexp.source, 0) == 46 && // '.'
- %_StringCharCodeAt(regexp.source, 1) == 42 && // '*'
- %_StringCharCodeAt(regexp.source, 2) != 63) { // '?'
+ var source = REGEXP_SOURCE(regexp);
+ if (regexp.length >= 3 &&
+ %_StringCharCodeAt(regexp, 0) == 46 && // '.'
+ %_StringCharCodeAt(regexp, 1) == 42 && // '*'
+ %_StringCharCodeAt(regexp, 2) != 63) { // '?'
regexp = TrimRegExp(regexp);
}
// matchIndices is either null or the RegExpLastMatchInfo array.
@@ -251,9 +246,10 @@ function TrimRegExp(regexp) {
if (!%_ObjectEquals(regexp_key, regexp)) {
regexp_key = regexp;
regexp_val =
- new GlobalRegExp(%_SubString(regexp.source, 2, regexp.source.length),
- (regexp.ignoreCase ? regexp.multiline ? "im" : "i"
- : regexp.multiline ? "m" : ""));
+ new GlobalRegExp(
+ %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length),
+ (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i"
+ : REGEXP_MULTILINE(regexp) ? "m" : ""));
}
return regexp_val;
}
@@ -264,12 +260,12 @@ function RegExpToString() {
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.toString', this);
}
- var result = '/' + this.source + '/';
- if (this.global) result += 'g';
- if (this.ignoreCase) result += 'i';
- if (this.multiline) result += 'm';
- if (FLAG_harmony_unicode_regexps && this.unicode) result += 'u';
- if (FLAG_harmony_regexps && this.sticky) result += 'y';
+ var result = '/' + REGEXP_SOURCE(this) + '/';
+ if (REGEXP_GLOBAL(this)) result += 'g';
+ if (REGEXP_IGNORE_CASE(this)) result += 'i';
+ if (REGEXP_MULTILINE(this)) result += 'm';
+ if (REGEXP_UNICODE(this)) result += 'u';
+ if (REGEXP_STICKY(this)) result += 'y';
return result;
}
@@ -334,6 +330,50 @@ function RegExpMakeCaptureGetter(n) {
};
}
+
+// ES6 21.2.5.4.
+function RegExpGetGlobal() {
+ if (!IS_REGEXP(this)) {
+ throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.global");
+ }
+ return !!REGEXP_GLOBAL(this);
+}
+%FunctionSetName(RegExpGetGlobal, "RegExp.prototype.global");
+%SetNativeFlag(RegExpGetGlobal);
+
+
+// ES6 21.2.5.5.
+function RegExpGetIgnoreCase() {
+ if (!IS_REGEXP(this)) {
+ throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.ignoreCase");
+ }
+ return !!REGEXP_IGNORE_CASE(this);
+}
+%FunctionSetName(RegExpGetIgnoreCase, "RegExp.prototype.ignoreCase");
+%SetNativeFlag(RegExpGetIgnoreCase);
+
+
+// ES6 21.2.5.7.
+function RegExpGetMultiline() {
+ if (!IS_REGEXP(this)) {
+ throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.multiline");
+ }
+ return !!REGEXP_MULTILINE(this);
+}
+%FunctionSetName(RegExpGetMultiline, "RegExp.prototype.multiline");
+%SetNativeFlag(RegExpGetMultiline);
+
+
+// ES6 21.2.5.10.
+function RegExpGetSource() {
+ if (!IS_REGEXP(this)) {
+ throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source");
+ }
+ return REGEXP_SOURCE(this);
+}
+%FunctionSetName(RegExpGetSource, "RegExp.prototype.source");
+%SetNativeFlag(RegExpGetSource);
+
// -------------------------------------------------------------------
%FunctionSetInstanceClassName(GlobalRegExp, 'RegExp');
@@ -349,6 +389,15 @@ utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [
"compile", RegExpCompileJS
]);
+%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "global",
+ RegExpGetGlobal, DONT_ENUM);
+%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "ignoreCase",
+ RegExpGetIgnoreCase, DONT_ENUM);
+%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "multiline",
+ RegExpGetMultiline, DONT_ENUM);
+%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "source",
+ RegExpGetSource, DONT_ENUM);
+
// The length of compile is 1 in SpiderMonkey.
%FunctionSetLength(GlobalRegExp.prototype.compile, 1);
« src/bootstrapper.cc ('K') | « src/js/prologue.js ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698