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() {
throw MakeTypeError(
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) + '/';
if (REGEXP_GLOBAL(this)) result += 'g';
......
......@@ -6,7 +6,7 @@ var log = [];
var fake =
{
pattern: function() {
get source() {
log.push("p");
return {
toString: function() {
......@@ -15,7 +15,7 @@ var fake =
}
};
},
flags: function() {
get flags() {
log.push("f");
return {
toString: function() {
......@@ -38,8 +38,8 @@ function testThrows(x) {
testThrows(1);
testThrows(null);
Number.prototype.pattern = () => "a";
Number.prototype.flags = () => "b";
Number.prototype.source = "a";
Number.prototype.flags = "b";
testThrows(1);
assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake));
......
......@@ -719,9 +719,6 @@ assertThrows("RegExp.prototype.toString.call(0)", TypeError);
assertThrows("RegExp.prototype.toString.call('')", TypeError);
assertThrows("RegExp.prototype.toString.call(false)", 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.
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