Reviewers: ,
Description:
Fixed RegExp.prototype.toString.call bug not throwing TypeError when non
RegExp
object was passed.
Bug report: http://code.google.com/p/v8/issues/detail?id=1981
BUG=1981
TEST=
Please review this at https://chromiumcodereview.appspot.com/10423008/
SVN Base: git://github.com/v8/v8.git@master
Affected files:
M src/regexp.js
M test/mjsunit/regexp.js
Index: src/regexp.js
diff --git a/src/regexp.js b/src/regexp.js
index
a574f62bf6a040b808bc40ea380f8a497f2261fe..44f8dd1234d9055afecd6be061839725b65f7d7d
100644
--- a/src/regexp.js
+++ b/src/regexp.js
@@ -278,6 +278,10 @@ function TrimRegExp(regexp) {
function RegExpToString() {
+ if (!IS_REGEXP(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['RegExp.prototype.toString', this]);
+ }
var result = '/' + this.source + '/';
if (this.global) result += 'g';
if (this.ignoreCase) result += 'i';
Index: test/mjsunit/regexp.js
diff --git a/test/mjsunit/regexp.js b/test/mjsunit/regexp.js
index
ec82c96e094efe1f32e9cf1789bc0ea6e82fc9f2..fe6b7052ab5a94a8ede5eacd3dd2cc5b05f95f8a
100644
--- a/test/mjsunit/regexp.js
+++ b/test/mjsunit/regexp.js
@@ -705,3 +705,13 @@ assertThrows("RegExp('(?!*)')");
// Test trimmed regular expression for RegExp.test().
assertTrue(/.*abc/.test("abc"));
assertFalse(/.*\d+/.test("q"));
+
+// ES5.1, 15.10.6 conformance tests
+assertThrows("RegExp.prototype.toString.call(null)");
+assertThrows("RegExp.prototype.toString.call(0)");
+assertThrows("RegExp.prototype.toString.call('')");
+assertThrows("RegExp.prototype.toString.call(false)");
+assertThrows("RegExp.prototype.toString.call(true)");
+assertThrows("RegExp.prototype.toString.call([])");
+assertThrows("RegExp.prototype.toString.call({})");
+assertThrows("RegExp.prototype.toString.call(function(){})");
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev