JDK-8006183 : Browser environment simulators for JS engines
  • Type: Task
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2013-01-14
  • Updated: 2017-07-05
  • Resolved: 2017-07-05
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.
Other
tbd_majorResolved
Related Reports
Relates :  
Description
Add support for running browser simulation environments on top of Nashorn. One such environment commonly used on Rhino is env.js (www.envjs.com). There is also one that is part of CometD project's test code (http://cometd.org).

This used to be NASHORN-641 (http://kenai.com/jira/browse/NASHORN-641)
Comments
First of all: Great work! I was planning to use env.js for a long time, but I would never be able to convert the rhino version to nashorn version myself. The env.nashorn.1.2-debug.js by Hannes from Feb 13, 2013 was great start. I ported my knockout.js for Java to run on top of Nashorn and env.nashorn.js. I have found just three problems. I sketch them here, let me know if you want me to report separate issue(s) for them. +++ 1 +++ compareDocumentPosition is badly implemented. I had to remove it to let knockout.js rev. 2.2.1 work: http://source.apidesign.org/hg/html~html4j/rev/e4dad7683970 +++ 2 +++ (simulated and reported as JDK-8046013) there is some problem with "with" on ScriptObjectMirror, it throws "Cannot apply "with" to non script object", but the object itself seems scripted "enough" to me. I don't understand the details yet. To reproduce you could: $ hg clone http://source.apidesign.org/hg/html~html4j/ $ cd html~html4j $ hg up -C be623953a38b $ mvn clean install After a while and running on JDK8b132 you should see a failure like: displayContentOfArrayOfPeople(net.java.html.boot.script.ko4j.KOCase) Time elapsed: 0.146 sec <<< FAILURE! javax.script.ScriptException: Error: Unable to parse bindings. Message: TypeError: Cannot apply "with" to non script object; Bindings value: text: $data.firstName, click: $root.removePerson in <eval> at line number 1941 at column number 16 at jdk.nashorn.internal.scripts.Script$\^eval\_$4._L5$_L7$_L21$_L1903$_L1936(<eval>:1941) at jdk.nashorn.internal.scripts.Script$\^eval\_$4._L5$_L7$_L21$_L1903$_L1919(<eval>:1921) at jdk.nashorn.internal.scripts.Script$\^eval\_$4._L5$_L7$_L21$_L1965$applyBindingsToNodeInternal$_L2057(<eval>:2072) the problem is with "$data". After adding some debugging messages: var bindingFunction = function ($context,$element) { with($context){with($data||{}){return{'text': $data.firstName,'click': $root.removePerson, '_ko_property_writers' : { 'text' : function(__ko_value) { Object($data).firstName = __ko_value; }, 'click' : function(__ko_value) { Object($root).removePerson = __ko_value; } } }}} } with (bindingContext) { console.log('what is the data: ' + typeof $data + " str: " + $data.toString() + " val: " + Object.getOwnPropertyNames($data)); with ($data) { // this line is never reached } } ... I can see following output...: what is the data: object str: [object Object] val: ko-fx.model,fullName,sexType,firstName,lastName,sex,address,changeSex ...looks to me like real JavaScript object. Similar code works in JavaFX WebView, so I'd expect some problem with conversion of objects when they flow between JS->Java and back. +++ 3 +++ XHR implementation in env.nashorn.js seems to be unusable for the second time. Somehow it calls back the callback function registered on the first instance, not the second one. I can provide details, but I workarounded that for now. I know this is probably not the most important issue to solve, but help with "Cannot apply "with" to non script object" would be really welcomed, as I don't have workaround yet.
05-06-2014

The attached versions of env.nashorn should be working with current Nashorn. How do we want to maintain these? Should we file a 3rd party software request?
03-05-2013

See JDK-8010797 for original email from Simone Bordet that triggered this bug.
03-05-2013

Uploading new versions of env.nashorn.*.js with working sync() and spawn().
13-02-2013

Uploading versions of env.rhino.1.2.js modified to run on Nashorn. env.nashorn.1.2.js is a modified version of the latest release (obtained from http://www.envjs.com/dist/env.rhino.1.2.js). env.nashorn.1.2-debug.js was built from source and differs in two ways from env.nashorn.1.2.js: - The HTTP parser code translated by GWT is not obfuscated. - Several try-catch statements have been disabled to let exceptions bubble to the top. See http://www.envjs.com/doc/guides for how to use env.js.
14-01-2013