Commit 269840c4 authored by yangguo's avatar yangguo Committed by Commit bot

[regexp] Fix RegExp.prototype.toString.

Initial fix was simply wrong.

R=verwaest@chromium.org
BUG=v8:4524
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#33896}
parent 6b89c694
...@@ -282,7 +282,7 @@ function RegExpToString() { ...@@ -282,7 +282,7 @@ function RegExpToString() {
throw MakeTypeError( throw MakeTypeError(
kIncompatibleMethodReceiver, 'RegExp.prototype.toString', this); kIncompatibleMethodReceiver, 'RegExp.prototype.toString', this);
} }
return '/' + TO_STRING(this.pattern()) + '/' + TO_STRING(this.flags()); return '/' + TO_STRING(this.source) + '/' + TO_STRING(this.flags);
} }
var result = '/' + REGEXP_SOURCE(this) + '/'; var result = '/' + REGEXP_SOURCE(this) + '/';
if (REGEXP_GLOBAL(this)) result += 'g'; if (REGEXP_GLOBAL(this)) result += 'g';
......
...@@ -6,7 +6,7 @@ var log = []; ...@@ -6,7 +6,7 @@ var log = [];
var fake = var fake =
{ {
pattern: function() { get source() {
log.push("p"); log.push("p");
return { return {
toString: function() { toString: function() {
...@@ -15,7 +15,7 @@ var fake = ...@@ -15,7 +15,7 @@ var fake =
} }
}; };
}, },
flags: function() { get flags() {
log.push("f"); log.push("f");
return { return {
toString: function() { toString: function() {
...@@ -38,8 +38,8 @@ function testThrows(x) { ...@@ -38,8 +38,8 @@ function testThrows(x) {
testThrows(1); testThrows(1);
testThrows(null); testThrows(null);
Number.prototype.pattern = () => "a"; Number.prototype.source = "a";
Number.prototype.flags = () => "b"; Number.prototype.flags = "b";
testThrows(1); testThrows(1);
assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake)); assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake));
......
...@@ -719,9 +719,6 @@ assertThrows("RegExp.prototype.toString.call(0)", TypeError); ...@@ -719,9 +719,6 @@ assertThrows("RegExp.prototype.toString.call(0)", TypeError);
assertThrows("RegExp.prototype.toString.call('')", TypeError); assertThrows("RegExp.prototype.toString.call('')", TypeError);
assertThrows("RegExp.prototype.toString.call(false)", TypeError); assertThrows("RegExp.prototype.toString.call(false)", TypeError);
assertThrows("RegExp.prototype.toString.call(true)", TypeError); assertThrows("RegExp.prototype.toString.call(true)", TypeError);
assertThrows("RegExp.prototype.toString.call([])", TypeError);
assertThrows("RegExp.prototype.toString.call({})", TypeError);
assertThrows("RegExp.prototype.toString.call(function(){})", TypeError);
// Test mutually recursive capture and backreferences. // Test mutually recursive capture and backreferences.
assertEquals(["b", "", ""], /(\2)b(\1)/.exec("aba")); assertEquals(["b", "", ""], /(\2)b(\1)/.exec("aba"));
......
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