diff options
Diffstat (limited to 'deps/v8/src/regexp.js')
-rw-r--r-- | deps/v8/src/regexp.js | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/deps/v8/src/regexp.js b/deps/v8/src/regexp.js index 24e3309805..9367f15f91 100644 --- a/deps/v8/src/regexp.js +++ b/deps/v8/src/regexp.js @@ -257,6 +257,10 @@ function RegExpExec(string) { } +// One-element cache for the simplified test regexp. +var regexp_key; +var regexp_val; + // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be // that test is defined in terms of String.prototype.exec. However, it probably // means the original value of String.prototype.exec, which is what everybody @@ -281,9 +285,7 @@ function RegExpTest(string) { } var lastIndex = this.lastIndex; - var cache = regExpCache; - if (%_ObjectEquals(cache.type, 'test') && %_ObjectEquals(cache.regExp, this) && %_ObjectEquals(cache.subject, string) && @@ -291,6 +293,22 @@ function RegExpTest(string) { return cache.answer; } + // Remove irrelevant preceeding '.*' in a test regexp. The expression + // checks whether this.source starts with '.*' and that the third + // char is not a '?' + if (%_StringCharCodeAt(this.source,0) == 46 && // '.' + %_StringCharCodeAt(this.source,1) == 42 && // '*' + %_StringCharCodeAt(this.source,2) != 63) { // '?' + if (!%_ObjectEquals(regexp_key, this)) { + regexp_key = this; + regexp_val = new $RegExp(this.source.substring(2, this.source.length), + (this.global ? 'g' : '') + + (this.ignoreCase ? 'i' : '') + + (this.multiline ? 'm' : '')); + } + if (!regexp_val.test(s)) return false; + } + var length = s.length; var i = this.global ? TO_INTEGER(lastIndex) : 0; @@ -299,7 +317,7 @@ function RegExpTest(string) { cache.subject = s; cache.lastIndex = i; - if (i < 0 || i > s.length) { + if (i < 0 || i > length) { this.lastIndex = 0; cache.answer = false; return false; |