webdriver
webdriver copied to clipboard
`internal JSON clone algorithm` has to raise "javascript error" if object's `toJSON()` method throws
https://github.com/w3c/webdriver/issues/849 implemented the feature to call toJSON() for internal JSON clone algorithm if it exists on an object. But as seen while working on https://github.com/w3c/webdriver/pull/1709 it misses to catch errors potentially thrown by executing this method.
In such a situation the error as raised should be caught and re-thrown as javascript error.
The fundamental issue is that in order to actually do that we need to set up an execution environment and handle the fact that the return type is an ES completion record (i.e. the equivalent of a Result<T, E>). There's a few places where we just casually try to perform operations that could execute script without being specific about where we do it, or how errors are handled.