Array.prototype.slice.call method may throw ClassCastException

nobuoka nobuoka+dev at vividcode.info
Sat May 25 12:02:02 PDT 2013


Hello,

I use Nashorn with JavaFX on JDK 8 build b91.

When I run the following script, the ClassCastException occur.
I think this may be bug, so I report it.

// This code is a part of JavaFX application (run by `jss -fx
filename.js` command)
//
// `doc` is org.w3c.dom.Document object returned from
// javafx.scene.web.WebEngine#getDocument method
var elems = doc.querySelectorAll("a");
Array.prototype.slice.call(elems); // exception occur

> Exception in thread "JavaFX Application Thread"
java.lang.ClassCastException: com.sun.webkit.dom.JSObject cannot be cast
to jdk.nashorn.internal.runtime.ScriptObject

(The method call `Array.prototype.slice.call(elems)` is commonly used
idiom to
convert W3C DOM NodeList object to Array object.)

Note that ECMA-262 5.1th says: The |slice| function is intentionally
generic; it does not require that
its *this* value be an Array object. Therefore it can be transferred to
other kinds of objects for
use as a method. Whether the |slice| function can be applied
successfully to a host object is
implementation-dependent.
( http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.10 )

Regards,


More information about the nashorn-dev mailing list