Commit f2bfa126 authored by yangguo's avatar yangguo Committed by Commit bot

Do not coerce lastIndex of a global RegExp in @@match and @@replace.

R=rossberg@chromium.org
BUG=v8:4471
LOG=N

Review URL: https://codereview.chromium.org/1410753002

Cr-Commit-Position: refs/heads/master@{#31330}
parent a805be73
......@@ -151,9 +151,6 @@ function StringMatchJS(regexp) {
var subject = TO_STRING(this);
if (IS_REGEXP(regexp)) {
// Emulate RegExp.prototype.exec's side effect in step 5, even though
// value is discarded.
var lastIndex = TO_INTEGER(regexp.lastIndex);
if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
var result = %StringMatch(subject, regexp, RegExpLastMatchInfo);
if (result !== null) $regexpLastMatchInfoOverride = null;
......@@ -222,10 +219,6 @@ function StringReplace(search, replace) {
// ...... string replace (with $-expansion)
if (IS_REGEXP(search)) {
// Emulate RegExp.prototype.exec's side effect in step 5, even if
// value is discarded.
var lastIndex = TO_INTEGER(search.lastIndex);
if (!IS_CALLABLE(replace)) {
replace = TO_STRING(replace);
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests that lastIndex of a global RegExp is overwritten as per
// ECMA-262 6.0 21.2.5.6 step 8.c.
var global = /./g;
global.lastIndex = { valueOf: function() { assertUnreachable(); } };
"x".match(global);
assertEquals(0, global.lastIndex);
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests that lastIndex of a global RegExp is overwritten as per
// ECMA-262 6.0 21.2.5.8 step 10.c.
var global = /./g;
global.lastIndex = { valueOf: function() { assertUnreachable(); } };
assertEquals("X", "x".replace(global, function(a) { return "X"; }));
assertEquals(0, global.lastIndex);
......@@ -35,14 +35,6 @@ function testSideEffects(subject, re) {
re.lastIndex = side_effect_object;
re.test(subject);
assertEquals(2, counter);
re.lastIndex = side_effect_object;
subject.match(re);
assertEquals(3, counter);
re.lastIndex = side_effect_object;
subject.replace(re, "");
assertEquals(4, counter);
}
testSideEffects("zzzz", /a/);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment