Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[If changing import() proves not backwards compatible] Alternative proposal #1

Open
Jamesernator opened this issue Mar 17, 2019 · 1 comment

Comments

@Jamesernator
Copy link

This proposal currently depends on the fact that changing import() is backwards compatible. However if it proves not to be I would like to propose an alternative that delegates the un-thening to the producer rather than the consumer.

The proposal is very simple: just add a an internal slot to promise instances [[OriginalResolveValue]] that is the value that was originally passed into resolve. Then we could have a single static function on Promise, e.g. Promise.originalValue that returns a new promise that boxes the [[OriginalResolveValue]].

e.g.:

const thenable = {
  then() {
    throw new Error("Oh dear")
  },
}

const promise = Promise.resolve(thenable)

const unwrappedPromise = Promise.originalValue(promise)

const { value: originalThenable } = await unwrappedPromise

originalThenable === thenable // true

The main downside is that .then() would still be invoked but this means it wouldn't be a breaking change for existing code.

@ljharb
Copy link

ljharb commented Mar 17, 2019

It should not be possible to do this unless the promise has explicitly opted in; i can think of all sorts of security issues/encapsulation violations that would occur. If it can’t be done on the producing end it probably shouldn’t be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants