diff options
Diffstat (limited to 'deps/v8/src/string.js')
-rw-r--r-- | deps/v8/src/string.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/deps/v8/src/string.js b/deps/v8/src/string.js index 6f68ce089..297105d04 100644 --- a/deps/v8/src/string.js +++ b/deps/v8/src/string.js @@ -223,7 +223,7 @@ function StringReplace(search, replace) { // Delegate to one of the regular expression variants if necessary. if (IS_REGEXP(search)) { %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); - if (IS_FUNCTION(replace)) { + if (IS_SPEC_FUNCTION(replace)) { if (search.global) { return StringReplaceGlobalRegExpWithFunction(subject, search, replace); } else { @@ -250,7 +250,7 @@ function StringReplace(search, replace) { builder.addSpecialSlice(0, start); // Compute the string to replace with. - if (IS_FUNCTION(replace)) { + if (IS_SPEC_FUNCTION(replace)) { var receiver = %GetDefaultReceiver(replace); builder.add(%_CallFunction(receiver, search, @@ -440,13 +440,14 @@ function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) { i++; } } else { + var receiver = %GetDefaultReceiver(replace); while (i < len) { var elem = res[i]; if (!%_IsSmi(elem)) { // elem must be an Array. // Use the apply argument as backing for global RegExp properties. lastMatchInfoOverride = elem; - var func_result = replace.apply(null, elem); + var func_result = %Apply(replace, receiver, elem, 0, elem.length); res[i] = TO_STRING_INLINE(func_result); } i++; @@ -472,11 +473,11 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) { // The number of captures plus one for the match. var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; var replacement; + var receiver = %GetDefaultReceiver(replace); if (m == 1) { // No captures, only the match, which is always valid. var s = SubString(subject, index, endOfMatch); // Don't call directly to avoid exposing the built-in global object. - var receiver = %GetDefaultReceiver(replace); replacement = %_CallFunction(receiver, s, index, subject, replace); } else { @@ -487,7 +488,7 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) { parameters[j] = index; parameters[j + 1] = subject; - replacement = replace.apply(null, parameters); + replacement = %Apply(replace, receiver, parameters, 0, j + 2); } result.add(replacement); // The add method converts to string if necessary. |