Index: src/string.js |
diff --git a/src/string.js b/src/string.js |
index a464f7ffa376f1cc4775fe3ece89ba5363ec20b5..03064beb43d106fc12c68eba7c93e664d03706ef 100644 |
--- a/src/string.js |
+++ b/src/string.js |
@@ -266,6 +266,10 @@ function StringReplace(search, replace) { |
// Compute the string to replace with. |
if (IS_SPEC_FUNCTION(replace)) { |
var receiver = %GetDefaultReceiver(replace); |
+ // Prepare break slots for debugger step in. |
+ if (%DebugStepIntoBuiltinCallback(replace)) { |
+ %PrepareBreakSlotsForCallback(replace); |
+ } |
builder.add(%_CallFunction(receiver, |
search, |
start, |
@@ -434,24 +438,47 @@ function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) { |
var match_start = 0; |
var override = new InternalArray(null, 0, subject); |
var receiver = %GetDefaultReceiver(replace); |
- while (i < len) { |
- var elem = res[i]; |
- if (%_IsSmi(elem)) { |
- if (elem > 0) { |
- match_start = (elem >> 11) + (elem & 0x7ff); |
+ if (%DebugStepIntoBuiltinCallback(replace)) { |
+ while (i < len) { |
+ var elem = res[i]; |
+ if (%_IsSmi(elem)) { |
+ if (elem > 0) { |
+ match_start = (elem >> 11) + (elem & 0x7ff); |
+ } else { |
+ match_start = res[++i] - elem; |
+ } |
} else { |
- match_start = res[++i] - elem; |
+ override[0] = elem; |
+ override[1] = match_start; |
+ lastMatchInfoOverride = override; |
+ %PrepareBreakSlotsForCallback(replace); |
+ var func_result = |
+ %_CallFunction(receiver, elem, match_start, subject, replace); |
+ res[i] = TO_STRING_INLINE(func_result); |
+ match_start += elem.length; |
} |
- } else { |
- override[0] = elem; |
- override[1] = match_start; |
- lastMatchInfoOverride = override; |
- var func_result = |
- %_CallFunction(receiver, elem, match_start, subject, replace); |
- res[i] = TO_STRING_INLINE(func_result); |
- match_start += elem.length; |
+ i++; |
+ } |
+ } else { |
+ while (i < len) { |
+ var elem = res[i]; |
+ if (%_IsSmi(elem)) { |
+ if (elem > 0) { |
+ match_start = (elem >> 11) + (elem & 0x7ff); |
+ } else { |
+ match_start = res[++i] - elem; |
+ } |
+ } else { |
+ override[0] = elem; |
+ override[1] = match_start; |
+ lastMatchInfoOverride = override; |
+ var func_result = |
+ %_CallFunction(receiver, elem, match_start, subject, replace); |
+ res[i] = TO_STRING_INLINE(func_result); |
+ match_start += elem.length; |
+ } |
+ i++; |
} |
- i++; |
} |
} else { |
var receiver = %GetDefaultReceiver(replace); |
@@ -491,9 +518,12 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) { |
if (m == 1) { |
// No captures, only the match, which is always valid. |
var s = SubString(subject, index, endOfMatch); |
+ // Prepare break slots for debugger step in. |
+ if (%DebugStepIntoBuiltinCallback(replace)) { |
+ %PrepareBreakSlotsForCallback(replace); |
+ } |
// Don't call directly to avoid exposing the built-in global object. |
- replacement = |
- %_CallFunction(receiver, s, index, subject, replace); |
+ replacement = %_CallFunction(receiver, s, index, subject, replace); |
} else { |
var parameters = new InternalArray(m + 2); |
for (var j = 0; j < m; j++) { |