JDK-8157160 : JSON.stringify does not work on ScriptObjectMirror objects
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-05-17
  • Updated: 2016-10-13
  • Resolved: 2016-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u112Fixed 9 b120Fixed
Description
When JSON.stringify is called on a ScriptObjectMirror, we get undefined value. JSON.stringify is used as debug aid by nashorn users. ScriptObjectMirror being not handled by JSON.stringify makes it difficult.

D:\src\jdk9-dev\build\windows-x86_64-normal-server-release\images\jdk\bin>.\jjs
jjs> SM = javax.script.ScriptEngineManager
[JavaClass javax.script.ScriptEngineManager]
jjs> e = new SM().getEngineByName("nashorn")
jdk.nashorn.api.scripting.NashornScriptEngine@23348b5d
jjs> JSON.stringify(e.eval("({ foo: 343 })")) === undefined
true
jjs>

This issue was reported by Eric Pederson via nashorn-dev alias.

See also: http://mail.openjdk.java.net/pipermail/nashorn-dev/2016-May/006162.html