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

Unified Diff: src/js/regexp.js

Issue 1409013006: Revert of Implement flag and source getters on RegExp.prototype. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@rproto
Patch Set: 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
« no previous file with comments | « src/js/prologue.js ('k') | src/js/string.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/regexp.js
diff --git a/src/js/regexp.js b/src/js/regexp.js
index 30f5204e9d3ff171aa2c435518647533243b1f36..51c8ed0d6ee921a523ece0c1e885c6164534ce0d 100644
--- a/src/js/regexp.js
+++ b/src/js/regexp.js
@@ -16,8 +16,6 @@
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;
@@ -53,14 +51,14 @@
// RegExp : Called as constructor; see ECMA-262, section 15.10.4.
if (IS_REGEXP(pattern)) {
if (!IS_UNDEFINED(flags)) throw MakeTypeError(kRegExpFlags);
- flags = (REGEXP_GLOBAL(pattern) ? 'g' : '')
- + (REGEXP_IGNORE_CASE(pattern) ? 'i' : '')
- + (REGEXP_MULTILINE(pattern) ? 'm' : '');
+ flags = (pattern.global ? 'g' : '')
+ + (pattern.ignoreCase ? 'i' : '')
+ + (pattern.multiline ? 'm' : '');
if (FLAG_harmony_unicode_regexps)
- flags += (REGEXP_UNICODE(pattern) ? 'u' : '');
+ flags += (pattern.unicode ? 'u' : '');
if (FLAG_harmony_regexps)
- flags += (REGEXP_STICKY(pattern) ? 'y' : '');
- pattern = REGEXP_SOURCE(pattern);
+ flags += (pattern.sticky ? 'y' : '');
+ pattern = pattern.source;
}
pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern);
@@ -167,8 +165,7 @@
// algorithm, step 4) even if the value is discarded for non-global RegExps.
var i = TO_LENGTH_OR_INTEGER(lastIndex);
- var updateLastIndex = REGEXP_GLOBAL(this) ||
- (FLAG_harmony_regexps && REGEXP_STICKY(this));
+ var updateLastIndex = this.global || (FLAG_harmony_regexps && this.sticky);
if (updateLastIndex) {
if (i < 0 || i > string.length) {
this.lastIndex = 0;
@@ -215,7 +212,7 @@
// algorithm, step 4) even if the value is discarded for non-global RegExps.
var i = TO_LENGTH_OR_INTEGER(lastIndex);
- if (REGEXP_GLOBAL(this) || (FLAG_harmony_regexps && REGEXP_STICKY(this))) {
+ if (this.global || (FLAG_harmony_regexps && this.sticky)) {
if (i < 0 || i > string.length) {
this.lastIndex = 0;
return false;
@@ -234,11 +231,10 @@
// 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;
- var source = REGEXP_SOURCE(regexp);
- if (regexp.length >= 3 &&
- %_StringCharCodeAt(regexp, 0) == 46 && // '.'
- %_StringCharCodeAt(regexp, 1) == 42 && // '*'
- %_StringCharCodeAt(regexp, 2) != 63) { // '?'
+ if (regexp.source.length >= 3 &&
+ %_StringCharCodeAt(regexp.source, 0) == 46 && // '.'
+ %_StringCharCodeAt(regexp.source, 1) == 42 && // '*'
+ %_StringCharCodeAt(regexp.source, 2) != 63) { // '?'
regexp = TrimRegExp(regexp);
}
// matchIndices is either null or the RegExpLastMatchInfo array.
@@ -255,10 +251,9 @@
if (!%_ObjectEquals(regexp_key, regexp)) {
regexp_key = regexp;
regexp_val =
- new GlobalRegExp(
- %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length),
- (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i"
- : REGEXP_MULTILINE(regexp) ? "m" : ""));
+ new GlobalRegExp(%_SubString(regexp.source, 2, regexp.source.length),
+ (regexp.ignoreCase ? regexp.multiline ? "im" : "i"
+ : regexp.multiline ? "m" : ""));
}
return regexp_val;
}
@@ -269,12 +264,12 @@
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.toString', this);
}
- 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 (FLAG_harmony_unicode_regexps && REGEXP_UNICODE(this)) result += 'u';
- if (FLAG_harmony_regexps && REGEXP_STICKY(this)) result += 'y';
+ 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';
return result;
}
@@ -339,40 +334,6 @@
};
}
-
-// ES6 21.2.5.4, 21.2.5.5, 21.2.5.7, 21.2.5.12, 21.2.5.15.
-function GetRegExpFlagGetter(name, mask) {
- var getter = function() {
- if (!IS_SPEC_OBJECT(this)) {
- throw MakeTypeError(kRegExpNonObject, name, TO_STRING(this));
- }
- var flags = this[regExpFlagsSymbol];
- if (IS_UNDEFINED(flags)) {
- throw MakeTypeError(kRegExpNonRegExp, TO_STRING(this));
- }
- return !!(flags & mask);
- };
- %FunctionSetName(getter, name);
- %SetNativeFlag(getter);
- return getter;
-}
-
-
-// ES6 21.2.5.10.
-function RegExpGetSource() {
- if (!IS_SPEC_OBJECT(this)) {
- throw MakeTypeError(kRegExpNonObject, "RegExp.prototype.source",
- TO_STRING(this));
- }
- var source = this[regExpSourceSymbol];
- if (IS_UNDEFINED(source)) {
- throw MakeTypeError(kRegExpNonRegExp, TO_STRING(this));
- }
- return source;
-}
-
-%SetNativeFlag(RegExpGetSource);
-
// -------------------------------------------------------------------
%FunctionSetInstanceClassName(GlobalRegExp, 'RegExp');
@@ -387,18 +348,6 @@
"toString", RegExpToString,
"compile", RegExpCompileJS
]);
-
-%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "global",
- GetRegExpFlagGetter("RegExp.prototype.global", REGEXP_GLOBAL_MASK),
- DONT_ENUM);
-%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "ignoreCase",
- GetRegExpFlagGetter("RegExp.prototype.ignoreCase", REGEXP_IGNORE_CASE_MASK),
- DONT_ENUM);
-%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "multiline",
- GetRegExpFlagGetter("RegExp.prototype.multiline", REGEXP_MULTILINE_MASK),
- DONT_ENUM);
-%DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "source",
- RegExpGetSource, DONT_ENUM);
// The length of compile is 1 in SpiderMonkey.
%FunctionSetLength(GlobalRegExp.prototype.compile, 1);
@@ -473,7 +422,6 @@
// Exports
utils.Export(function(to) {
- to.GetRegExpFlagGetter = GetRegExpFlagGetter;
to.RegExpExec = DoRegExpExec;
to.RegExpExecNoTests = RegExpExecNoTests;
to.RegExpLastMatchInfo = RegExpLastMatchInfo;
« no previous file with comments | « src/js/prologue.js ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698