Array.prototype.slice.call method may throw ClassCastException
Attila Szegedi
attila.szegedi at oracle.com
Sat May 25 14:55:58 PDT 2013
The relevant part here is "Whether the |slice| function can be applied successfully to a host object is implementation-dependent." DOM objects are host objects. Slice will work for array-like built-in JS objects, though. We might investigate whether we have a fundamental architectural issue that prevents us from having it work on host objects.
Attila.
Sent from my iPad
On 2013.05.25., at 21:02, nobuoka <nobuoka+dev at vividcode.info> wrote:
> 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