Reviewers: adamk,

Description:
In RegExp, lastIndex is read with ToLength, not ToInteger

ES2015 made a change vs ES5, where the "lastIndex" property of a
RegExp (which can be modified by a user to start the next search at
a different location) is cast to an integer with ToLength rather
than ToInteger. The main difference is on negative numbers, and
this is tested by test262. This patch implements that change on
RegExps and enables the test262 test now that it passes.

R=adamk
LOG=Y
BUG=v8:4244

Please review this at https://codereview.chromium.org/1241713004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+6, -9 lines):
  M src/regexp.js
  M test/test262-es6/test262-es6.status


Index: src/regexp.js
diff --git a/src/regexp.js b/src/regexp.js
index bf75ca1b011e4f5a30013a84621a9d9e3b5a882b..6c6b11cfd624c7e5ff5a5aad5ef7e2bc2a50181c 100644
--- a/src/regexp.js
+++ b/src/regexp.js
@@ -154,9 +154,9 @@ function RegExpExecJS(string) {
   string = TO_STRING_INLINE(string);
   var lastIndex = this.lastIndex;

-  // Conversion is required by the ES5 specification (RegExp.prototype.exec
- // algorithm, step 5) even if the value is discarded for non-global RegExps.
-  var i = TO_INTEGER(lastIndex);
+  // Conversion is required by the ES6 specification (RegExpBuiltinExec
+ // algorithm, step 4) even if the value is discarded for non-global RegExps.
+  var i = $toLength(lastIndex);

   var updateLastIndex = this.global || (harmony_regexps && this.sticky);
   if (updateLastIndex) {
@@ -202,9 +202,9 @@ function RegExpTest(string) {

   var lastIndex = this.lastIndex;

-  // Conversion is required by the ES5 specification (RegExp.prototype.exec
- // algorithm, step 5) even if the value is discarded for non-global RegExps.
-  var i = TO_INTEGER(lastIndex);
+  // Conversion is required by the ES6 specification (RegExpBuiltinExec
+ // algorithm, step 4) even if the value is discarded for non-global RegExps.
+  var i = $toLength(lastIndex);

   if (this.global || (harmony_regexps && this.sticky)) {
     if (i < 0 || i > string.length) {
Index: test/test262-es6/test262-es6.status
diff --git a/test/test262-es6/test262-es6.status b/test/test262-es6/test262-es6.status index 62261f2b5c1e71011cbc9004586bcb0bbd8c4688..d96d06720ab7d6654e63ead3a6d1cb084339a92e 100644
--- a/test/test262-es6/test262-es6.status
+++ b/test/test262-es6/test262-es6.status
@@ -424,9 +424,6 @@
   # https://code.google.com/p/v8/issues/detail?id=4003
   'built-ins/RegExp/prototype/15.10.6': [FAIL],

-  # https://code.google.com/p/v8/issues/detail?id=4244
-  'built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T3': [FAIL],
-
   # https://code.google.com/p/v8/issues/detail?id=4006
   'built-ins/String/prototype/S15.5.4_A1': [FAIL],
   'built-ins/String/prototype/S15.5.4_A2': [FAIL],


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to