Revision: 11637 Author: [email protected] Date: Wed May 23 13:48:08 2012 Log: Fix RegExp.prototype.toString for incompatible receivers.
BUG=v8:1981 TEST=mjsunit/regexp Review URL: https://chromiumcodereview.appspot.com/10426005 Patch from Ioseb Dzmanashvili <[email protected]>. http://code.google.com/p/v8/source/detail?r=11637 Modified: /branches/bleeding_edge/src/regexp.js /branches/bleeding_edge/test/mjsunit/regexp.js ======================================= --- /branches/bleeding_edge/src/regexp.js Mon Apr 23 06:59:43 2012 +++ /branches/bleeding_edge/src/regexp.js Wed May 23 13:48:08 2012 @@ -278,6 +278,10 @@ 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'; ======================================= --- /branches/bleeding_edge/test/mjsunit/regexp.js Thu Mar 15 10:21:42 2012 +++ /branches/bleeding_edge/test/mjsunit/regexp.js Wed May 23 13:48:08 2012 @@ -705,3 +705,14 @@ // Test trimmed regular expression for RegExp.test(). assertTrue(/.*abc/.test("abc")); assertFalse(/.*\d+/.test("q")); + +// Test that RegExp.prototype.toString() throws TypeError for +// incompatible receivers (ES5 section 15.10.6 and 15.10.6.4). +assertThrows("RegExp.prototype.toString.call(null)", TypeError); +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); -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
