New issue
Advanced search Search tips

Issue 2398 link

Starred by 12 users

Issue metadata

Status: Available
Owner: ----

Sign in to add a comment

executeAsyncScript should promise-call script, and handle rejected promise

Reported by, Apr 24 2018

Issue description

See for common issues.

Issue Description:
executeAsyncScript doesn't execute a `script` within a `new Promise` with a `Promise-call`, as defined in specification. Steps6 and 7 are not implemented properly:

As a result, current implementation doesn't take into account rejected promise, returned from `script`.


Steps to reproduce:
Test function, as in `execute_async_script_test.html`, that will fail, but should pass
function testScriptThrowsAsync() {
  var info = getAsyncScriptInfo();
  var script = "return Promise.reject('Catch me if you can!');"

  executeAsyncScript(script, [], true);
  assertEquals(StatusCode.JAVASCRIPT_ERROR, info.result.status);
  executeAsyncScript(script, [], false);
  assertEquals(StatusCode.UNKNOWN_ERROR, info.result.status);

How this issue could be fixed (just a partial implementation):
// Execute Async Script
return new Promise((resolve, reject) => {
  promiseCall(new Function(script), ...(args.concat(resolve)))

// Promise-Calling
function promiseCall(f, ...args) {
  try {
    return Promise.resolve(f(...args));
  } catch (e) {
    return Promise.reject(e);

I may be mistaken, I don't read specs often, but this is my current understanding.
Fix of this issue could drastically help to write tests and handle async errors!
Project Member

Comment 1 by, Apr 25 2018

Cc: Could you take a look at this some time? Thanks.
I could make a PR if this issue was confirmed :)
Project Member

Comment 4 by, Jul 26

Owner: ----
Status: Untriaged (was: Unconfirmed)
Project Member

Comment 5 by, Aug 22

Labels: StandardsCompliance Pri-2
Status: Available (was: Untriaged)
I agree that executeAsyncScript (and executeScript as well) is no spec compliant, and does not properly handle rejected promise. Sorry that I wasn't able to look at this earlier. If your offer to make a PR still stands, it will be most welcome. Thanks.

Sign in to add a comment