Index: src/regexp.js |
diff --git a/src/regexp.js b/src/regexp.js |
index d8e3ea49bec7e236a0d7dc1dcf4a624b460679eb..628fdd2a3de13746c4324e09de4916edf9309641 100644 |
--- a/src/regexp.js |
+++ b/src/regexp.js |
@@ -22,6 +22,8 @@ function DoConstructRegExp(object, pattern, flags) { |
flags = (pattern.global ? 'g' : '') |
+ (pattern.ignoreCase ? 'i' : '') |
+ (pattern.multiline ? 'm' : ''); |
+ if (%HarmonyRegExps()) |
Yang
2014/09/15 09:23:16
While I'm fine with this (will be removed eventual
Erik Corry
2014/09/16 17:49:40
Done.
|
+ flags += (pattern.sticky ? 'y' : ''); |
pattern = pattern.source; |
} |
@@ -31,6 +33,7 @@ function DoConstructRegExp(object, pattern, flags) { |
var global = false; |
var ignoreCase = false; |
var multiline = false; |
+ var sticky = false; |
for (var i = 0; i < flags.length; i++) { |
var c = %_CallFunction(flags, i, StringCharAt); |
switch (c) { |
@@ -52,12 +55,18 @@ function DoConstructRegExp(object, pattern, flags) { |
} |
multiline = true; |
break; |
+ case 'y': |
+ if (!%HarmonyRegExps() || sticky) { |
+ throw MakeSyntaxError("invalid_regexp_flags", [flags]); |
+ } |
+ sticky = true; |
+ break; |
default: |
throw MakeSyntaxError("invalid_regexp_flags", [flags]); |
} |
} |
- %RegExpInitializeObject(object, pattern, global, ignoreCase, multiline); |
+ %RegExpInitializeObject(object, pattern, global, ignoreCase, multiline, sticky); |
// Call internal function to compile the pattern. |
%RegExpCompile(object, pattern, flags); |
@@ -227,7 +236,8 @@ function RegExpTest(string) { |
// The expression checks whether this.source starts with '.*' and |
// that the third char is not a '?'. |
var regexp = this; |
- if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.' |
+ if (!this.sticky && |
Yang
2014/09/15 09:23:16
We also need to record .lastIndex for sticky. If I
Erik Corry
2014/09/16 17:49:40
Done, and also added string length check.
|
+ %_StringCharCodeAt(regexp.source, 0) == 46 && // '.' |
%_StringCharCodeAt(regexp.source, 1) == 42 && // '*' |
%_StringCharCodeAt(regexp.source, 2) != 63) { // '?' |
regexp = TrimRegExp(regexp); |
@@ -264,6 +274,7 @@ function RegExpToString() { |
if (this.global) result += 'g'; |
if (this.ignoreCase) result += 'i'; |
if (this.multiline) result += 'm'; |
+ if (%HarmonyRegExps() && this.sticky) result += 'y'; |
return result; |
} |