8186180: Symbol.__proto__ results in error with format string placeholder
authorhannesw
Fri, 22 Sep 2017 11:52:38 +0200
changeset 47246 82d45783c133
parent 47245 7490a799fccf
child 47247 42bc5bf0c654
8186180: Symbol.__proto__ results in error with format string placeholder Reviewed-by: sundar, hannesw Contributed-by: priya.lakshmi.muthuswamy@oracle.com
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeSymbol.java
test/nashorn/script/basic/es6/JDK-8186180.js
test/nashorn/script/basic/es6/JDK-8186180.js.EXPECTED
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeSymbol.java	Fri Sep 22 11:48:57 2017 +0200
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeSymbol.java	Fri Sep 22 11:52:38 2017 +0200
@@ -93,7 +93,7 @@
         } else if (self instanceof NativeSymbol) {
             return ((NativeSymbol) self).symbol;
         } else {
-            throw typeError("not.a.symbol");
+            throw typeError("not.a.symbol", ScriptRuntime.safeToString(self));
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/es6/JDK-8186180.js	Fri Sep 22 11:52:38 2017 +0200
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8186180: Symbol.__proto__ results in error with format string placeholder
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+var sym = Symbol('foo');
+try {
+    print(sym.__proto__);
+} catch (e) {
+    print(e);
+}
+try {
+    print(Symbol.prototype.toString());
+} catch (e) {
+    print(e);
+}
+print(Symbol('foo').toString());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/es6/JDK-8186180.js.EXPECTED	Fri Sep 22 11:52:38 2017 +0200
@@ -0,0 +1,3 @@
+TypeError: [object Symbol] is not a symbol.
+TypeError: [object Symbol] is not a symbol.
+Symbol(foo)