-
Notifications
You must be signed in to change notification settings - Fork 106
Investigate usage of modified intrinsics with await
#65
Comments
This makes the most sense to me, consider people doing
Most likely yes, though that's an esoteric case that I don't expect to be an issue anyway.
Why? I don't understand why this is desirable. You can modify the original
This sounds OK, but again, why? I'm not sure I understand the use cases here. |
Very interesting questions. Currently, most |
That's a very good point, for the very least it should delegate to |
The sole use cases I'm asking about is for libraries like |
I don't think the spec should cater to people who are overriding globals but not overriding their accompanying syntax. In other words, if you want to use a version of Promise that is not implemented by your JS engine, then you should use a version of async/await that is not implemented by your engine. Even more explicitly: if you're using the shim, also use a transpiler. (And you probably want to override every web API that returns a promise while you're at it, because those also don't use overridden globals.) |
The es-shims are only concerned with the language, not with browsers - certainly shims for those would need to use the global The This issue is to simply confirm how it should be spec'ed in this proposal. For what it's worth, the spec always caters to people who are overriding globals, whether they override their accompanying syntax or not - that's why most things are configurable, even if they're not writable or enumerable, like |
async functions must not use any overridden global.Promise to create their return value, and await syntax must not use any overridden Promise.resolve to resolve its argument. The spec does not cater to overridden builtins, and I'm very surprised you've gotten that mistaken impression. Thinking the configurability of properties has anything to do with how syntax generates objects betrays a fundamental misunderstanding of ES. RegExp literals don't return overridden RegExp constructor instances. Number or Boolean literals, when wrapped, don't use overridden global.Number or global.Boolean. The |
You're totally right - but if I modify the |
Oh, for sure, I don't see how it would even be possible to prevent that. |
The one remaining question though is that even if it's the native I'm specifically looking at http://www.ecma-international.org/ecma-262/6.0/#sec-promise-executor step 8, which leads to http://www.ecma-international.org/ecma-262/6.0/#sec-createresolvingfunctions step 2, which leads to http://www.ecma-international.org/ecma-262/6.0/#sec-promise-resolve-functions step 8, which does a |
Changes to %Promise% and %PromisePrototype% should not affect async function and |
Yes I think this is the most consistent behavior. You delegate to |
It won't use |
This is a difference between |
Great! So that means that returning from an Similarly, if I do something along the lines of: var OriginalPromise = Promise;
var MiddleMan = function () {};
Object.setPrototypeOf(OriginalPromise, MiddleMan);
MiddleMan.prototype = OriginalPromise.prototype;
OriginalPromise.prototype.constructor = MiddleMan;
Promise = MiddleMan; then I'm going to close this since this has answered my original question perfectly. |
Yeah, I believe it should work fine for your use case. You can try in Edge if you have a windows machine ;) |
Per discussion:
Promise = class MyPromise extends Promise {} ; async function foo() {}
- is the Promise returned byfoo()
aMyPromise
? Or is it the original, now mostly-otherwise-inaccessiblePromise
?await foo;
Under what circumstances does this call.then
on the object, thusPromise#then
(which may be modified)? If I modifyPromise.prototype.then
, should that be called whenawait foo
, or not? What if I delete theconstructor
property onfoo
?The use cases I'm thinking of are:
Promise
in such a way as its impossible for users to ever retrieve the original (I do this now withRegExp
andNumber
, for example, in thees6-shim
), andawait
andasync
functions should work with the modified global.Promise.prototype.then
such thatawait foo
will always invoke my replacement function.The text was updated successfully, but these errors were encountered: