Skip to content

How do we allow users to opt into 'safe' resolution?  #9

@mgaudet

Description

@mgaudet

Just looking through the Firefox codebase by asserting when we get more than 1 argument to resolve, there's an example pattern which can bite us:

 // Return a Promise that resolves when the mutex is free.
  return new Promise(unlock => {
    // Overwrite the mutex variable with a chained-on, new Promise. The Promise
    // we returned to the caller can be called to resolve that new Promise
    // and unlock the mutex.
    sessionFileIOMutex = sessionFileIOMutex.then(() => {
      return new Promise(unlock);
    });
  });

The issue here being that unlock is actually being called as an executor, and is called with two arguments (resolve and reject)

A similar pattern you could imagine seeing would be

return new Promise(resolve => {
  setTimeout(() => someOtherGlobal = new Promise(resolve), 0);
});

Which means mostly that I think we'd want to be cautious about how we decide to opt in; either only take explicit booleans, or only take objects of a particular shape resolve(value, { safeResolveMode: true}))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions