Index: test/mjsunit/es6/regexp-tostring.js |
diff --git a/test/mjsunit/es6/regexp-tostring.js b/test/mjsunit/es6/regexp-tostring.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e6857ee89b8a2045dba7e7af10321ac65c5be93 |
--- /dev/null |
+++ b/test/mjsunit/es6/regexp-tostring.js |
@@ -0,0 +1,46 @@ |
+// Copyright 2016 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. |
+ |
+var log = []; |
+ |
+var fake = |
+ { |
+ pattern: function() { |
+ log.push("p"); |
+ return { |
+ toString: function() { |
+ log.push("ps"); |
+ return "pattern"; |
+ } |
+ }; |
+ }, |
+ flags: function() { |
+ log.push("f"); |
+ return { |
+ toString: function() { |
+ log.push("fs"); |
+ return "flags"; |
+ } |
+ }; |
+ } |
+ } |
+ |
+function testThrows(x) { |
+ try { |
+ RegExp.prototype.toString.call(x); |
+ } catch (e) { |
+ assertTrue(/incompatible receiver/.test(e.message)); |
+ return; |
+ } |
+ assertUnreachable(); |
+} |
+ |
+testThrows(1); |
+testThrows(null); |
+Number.prototype.pattern = () => "a"; |
+Number.prototype.flags = () => "b"; |
+testThrows(1); |
+ |
+assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake)); |
+assertEquals(["p", "ps", "f", "fs"], log); |