diff options
author | Refael Ackermann <refack@gmail.com> | 2014-09-29 13:20:04 +0400 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2014-10-08 15:35:57 +0400 |
commit | 939278ac059b44439d41aab12bf552c8ae3c52d0 (patch) | |
tree | 86c586915a96d308b1b04de679a8ae293caf3e41 /deps/v8/src/regexp.js | |
parent | 4412a71d76a0fa002f627ec21d2337e089da6764 (diff) | |
download | node-new-939278ac059b44439d41aab12bf552c8ae3c52d0.tar.gz |
deps: update v8 to 3.28.73
Reviewed-By: Fedor Indutny <fedor@indutny.com>
PR-URL: https://github.com/joyent/node/pull/8476
Diffstat (limited to 'deps/v8/src/regexp.js')
-rw-r--r-- | deps/v8/src/regexp.js | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/deps/v8/src/regexp.js b/deps/v8/src/regexp.js index 6a0e2b5d92..d7883fb693 100644 --- a/deps/v8/src/regexp.js +++ b/deps/v8/src/regexp.js @@ -80,7 +80,7 @@ function RegExpConstructor(pattern, flags) { // were called again. In SpiderMonkey, this method returns the regexp object. // In JSC, it returns undefined. For compatibility with JSC, we match their // behavior. -function RegExpCompile(pattern, flags) { +function RegExpCompileJS(pattern, flags) { // Both JSC and SpiderMonkey treat a missing pattern argument as the // empty subject string, and an actual undefined value passed as the // pattern as the string 'undefined'. Note that JSC is inconsistent @@ -108,23 +108,30 @@ function DoRegExpExec(regexp, string, index) { } -function BuildResultFromMatchInfo(lastMatchInfo, s) { - var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; - var start = lastMatchInfo[CAPTURE0]; - var end = lastMatchInfo[CAPTURE1]; - var result = %_RegExpConstructResult(numResults, start, s); - result[0] = %_SubString(s, start, end); +// This is kind of performance sensitive, so we want to avoid unnecessary +// type checks on inputs. But we also don't want to inline it several times +// manually, so we use a macro :-) +macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) + var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; + var start = MATCHINFO[CAPTURE0]; + var end = MATCHINFO[CAPTURE1]; + // Calculate the substring of the first match before creating the result array + // to avoid an unnecessary write barrier storing the first result. + var first = %_SubString(STRING, start, end); + var result = %_RegExpConstructResult(numResults, start, STRING); + result[0] = first; + if (numResults == 1) return result; var j = REGEXP_FIRST_CAPTURE + 2; for (var i = 1; i < numResults; i++) { - start = lastMatchInfo[j++]; + start = MATCHINFO[j++]; if (start != -1) { - end = lastMatchInfo[j]; - result[i] = %_SubString(s, start, end); + end = MATCHINFO[j]; + result[i] = %_SubString(STRING, start, end); } j++; } return result; -} +endmacro function RegExpExecNoTests(regexp, string, start) { @@ -132,7 +139,7 @@ function RegExpExecNoTests(regexp, string, start) { var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); if (matchInfo !== null) { lastMatchInfoOverride = null; - return BuildResultFromMatchInfo(matchInfo, string); + RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, string); } regexp.lastIndex = 0; return null; @@ -175,7 +182,7 @@ function RegExpExec(string) { if (global) { this.lastIndex = lastMatchInfo[CAPTURE1]; } - return BuildResultFromMatchInfo(matchIndices, string); + RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); } @@ -374,14 +381,14 @@ var lastMatchInfoOverride = null; function SetUpRegExp() { %CheckIsBootstrapping(); %FunctionSetInstanceClassName($RegExp, 'RegExp'); - %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); + %AddNamedProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); %SetCode($RegExp, RegExpConstructor); InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( "exec", RegExpExec, "test", RegExpTest, "toString", RegExpToString, - "compile", RegExpCompile + "compile", RegExpCompileJS )); // The length of compile is 1 in SpiderMonkey. @@ -399,12 +406,12 @@ function SetUpRegExp() { }; %OptimizeObjectForAddingMultipleProperties($RegExp, 22); - %DefineOrRedefineAccessorProperty($RegExp, 'input', RegExpGetInput, - RegExpSetInput, DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, '$_', RegExpGetInput, - RegExpSetInput, DONT_ENUM | DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, '$input', RegExpGetInput, - RegExpSetInput, DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, 'input', RegExpGetInput, + RegExpSetInput, DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$_', RegExpGetInput, + RegExpSetInput, DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$input', RegExpGetInput, + RegExpSetInput, DONT_ENUM | DONT_DELETE); // The properties multiline and $* are aliases for each other. When this // value is set in SpiderMonkey, the value it is set to is coerced to a @@ -418,40 +425,40 @@ function SetUpRegExp() { var RegExpGetMultiline = function() { return multiline; }; var RegExpSetMultiline = function(flag) { multiline = flag ? true : false; }; - %DefineOrRedefineAccessorProperty($RegExp, 'multiline', RegExpGetMultiline, - RegExpSetMultiline, DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, '$*', RegExpGetMultiline, - RegExpSetMultiline, - DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, 'multiline', RegExpGetMultiline, + RegExpSetMultiline, DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$*', RegExpGetMultiline, + RegExpSetMultiline, + DONT_ENUM | DONT_DELETE); var NoOpSetter = function(ignored) {}; // Static properties set by a successful match. - %DefineOrRedefineAccessorProperty($RegExp, 'lastMatch', RegExpGetLastMatch, - NoOpSetter, DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, '$&', RegExpGetLastMatch, - NoOpSetter, DONT_ENUM | DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, 'lastParen', RegExpGetLastParen, - NoOpSetter, DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, '$+', RegExpGetLastParen, - NoOpSetter, DONT_ENUM | DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, 'leftContext', - RegExpGetLeftContext, NoOpSetter, - DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, '$`', RegExpGetLeftContext, - NoOpSetter, DONT_ENUM | DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, 'rightContext', - RegExpGetRightContext, NoOpSetter, - DONT_DELETE); - %DefineOrRedefineAccessorProperty($RegExp, "$'", RegExpGetRightContext, - NoOpSetter, DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, 'lastMatch', RegExpGetLastMatch, + NoOpSetter, DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$&', RegExpGetLastMatch, + NoOpSetter, DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, 'lastParen', RegExpGetLastParen, + NoOpSetter, DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$+', RegExpGetLastParen, + NoOpSetter, DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, 'leftContext', + RegExpGetLeftContext, NoOpSetter, + DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$`', RegExpGetLeftContext, + NoOpSetter, DONT_ENUM | DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, 'rightContext', + RegExpGetRightContext, NoOpSetter, + DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, "$'", RegExpGetRightContext, + NoOpSetter, DONT_ENUM | DONT_DELETE); for (var i = 1; i < 10; ++i) { - %DefineOrRedefineAccessorProperty($RegExp, '$' + i, - RegExpMakeCaptureGetter(i), NoOpSetter, - DONT_DELETE); + %DefineAccessorPropertyUnchecked($RegExp, '$' + i, + RegExpMakeCaptureGetter(i), NoOpSetter, + DONT_DELETE); } %ToFastProperties($RegExp); } |