tc39 / proposal-cancelable-promises

Former home of the now-withdrawn cancelable promises proposal for JavaScript
Other
375 stars 29 forks source link

Make `await.cancelToken` a syntax error #39

Closed bergus closed 8 years ago

bergus commented 8 years ago

…when used outside of async functions. I'd like to see some kind of static semantic rule that only allows it in places where you also can find an await keyword. The current draft only throws a run-time ReferenceError when the property is used (evaluated) outside of an asynchronous execution context that has the necessary slot.

domenic commented 8 years ago

Good catch, I forgot to add this. new.target has some stuff prohibiting it at top level...

domenic commented 8 years ago

I looked in to doing this and I don't think it's generally possible. In scripts, await is not a keyword, so this would disallow perfectly valid code.

We may be able to do this in modules...

domenic commented 8 years ago

https://github.com/domenic/cancelable-promise/commit/eb656c603ba9a71e8233899e17132c4fe6631409 prohibits at top level in modules. Still working on how to prohibit inside non-async functions inside modules.

bergus commented 8 years ago

Yes, only in strict mode code, similar to how await is prohibited as an identifier name there (iirc). I guess the proposal did forget to mention that await.cancelToken only parses as a meta property in such code, and as a normal property access otherwise. For new.target, such a definition was not yet necessary.

domenic commented 8 years ago

No, strict mode code is allowed to use await.cancelToken as the property of an object named await. It's only module code where await is reserved as a keyword.

domenic commented 8 years ago

In general it seems like the spec is very borked right now though, as you pointed out. We only want to interpret this as a meta-property inside async functions...