Reviewers: Rico,

Message:
Small JS-change.

Description:
Simplified replace JS a little.

Please review this at http://codereview.chromium.org/1994019/show

Affected files:
  M src/string.js


Index: src/string.js
diff --git a/src/string.js b/src/string.js
index 9433249188c9fccf26f42513a9bb011f1724c4a9..7ff0e46498bc1e79c833a1069b6c9a7e21330d47 100644
--- a/src/string.js
+++ b/src/string.js
@@ -396,9 +396,9 @@ function CaptureString(string, lastCaptureInfo, index) {
   var scaled = index << 1;
   // Compute start and end.
   var start = lastCaptureInfo[CAPTURE(scaled)];
+  // If start isn't valid, return undefined.
+  if (start < 0) return;
   var end = lastCaptureInfo[CAPTURE(scaled + 1)];
-  // If either start or end is missing return undefined.
-  if (start < 0 || end < 0) return;
   return SubString(string, start, end);
 };

@@ -516,9 +516,10 @@ function ApplyReplacementFunction(replace, matchInfo, subject) {
   // The number of captures plus one for the match.
   var m = NUMBER_OF_CAPTURES(matchInfo) >> 1;
   if (m == 1) {
-    var s = CaptureString(subject, matchInfo, 0);
+    // No captures, only the match, which is always valid.
+    var s = SubString(subject, index, matchInfo[CAPTURE1]);
     // Don't call directly to avoid exposing the built-in global object.
-    return replace.call(null, s, index, subject);
+    return %_CallFunction(global, s, index, subject, replace);
   }
   var parameters = $Array(m + 2);
   for (var j = 0; j < m; j++) {


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to