SWT Browser when is executed JavaScript "successful"?

529 Views Asked by At

I was wondering - when calling the org.eclipse.swt.browser.Browser method execute,

  • How is the return boolean determined?
  • When is the javaScript execution considered "successful"?
  • In particular, what happens when I start some asynchronous function and wait for the response?
  • Will the browser wait for the callback?
  • Is success based on an empty call stack and no errors?

Thanks in advance!

edit:
I just checked: the browser does not wait for callbacks to be called

1

There are 1 best solutions below

5
Baz On BEST ANSWER

As far as I can tell from digging in the source code, the result will be decided by either of the following methods:

  • Firefox: JS_EvaluateScriptForPrincipals

    If the script compiles and executes successfully, *rval receives the value from the last-executed expression statement processed in the script, and JS_EvaluateScriptForPrincipals or JS_EvaluateUCScriptForPrincipals returns JS_TRUE. Otherwise it returns JS_FALSE, and the value left in *rval is undefined.

  • WebKit: JSEvaluateScript

    The value that results from evaluating script, or NULL if an exception is thrown.

So it sounds like, if there's no error, true will be returned.


As far as the async part of your question is concerned, the Browser will not wait for the execution of the async task. What you can do, however, is define a BrowserFunction (as shown in this example) and call that method from JavaScript when you're done with your async task.