-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Normative: add import.meta #1892
Conversation
5d844e2
to
062e652
Compare
spec.html
Outdated
1. Set _module_.[[ImportMeta]] to _importMeta_. | ||
1. Return _importMeta_. | ||
1. Else, | ||
1. Assert: Type(_importMeta_) is Object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be asserted that it is an ordinary object? iow, a proxy wouldn’t be valid here.
I don't love that we're adding two hooks, where one is strictly more powerful than the other. What's the point of the restrictions on the return values of On a separate note, I don't think the module record alone as a parameter to one/both of these host hooks is sufficient. I imagine a host may want to make the value of |
I'd be fine with that too. One thing to note is that the HTML spec uses
Those use identical spec machinery, I would argue that should never be visible information (and I'm not sure how it would be exposed anyway, since both can happen to the same module)
I'm not entirely sure what that entails but a host has access to its own module graph.
Modules have a |
Do they? I'm not great with the module portion of the spec, but
Yes, but the module will only be evaluated once.
Sure, again thinking along the lines of module attributes, if a module is imported in more than one place with different sets of attribtues, I guess it would have a unique module record, so that should be sufficient for this use case. 👍
Ah, the |
@michaelficarra HostImportModuleDynamically paraphrased is "at some point in the future do your host specific magic and then call FinishDynamicImport" and FinishDynamicImport just the static logic plus fulfilling or rejecting a promise. Beyond that, your pattern idea here would seem to imply that one might do |
Also to be clear about the above, part of the "host specific magic" could be setting data in [[HostDefined]] which says whether it was static or dynamic. |
Okay I think I'm satisfied that the module record alone should be sufficient for these host hooks. Thanks for the explanations, @devsnek. I still don't think we should be adding two overlapping hooks for this feature, though. |
spec.html
Outdated
|
||
<p>The implementation of HostFinalizeImportMeta must conform to the following requirements:</p> | ||
<ul> | ||
<li>It must always complete normally (i.e., not return an abrupt completion).</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably say more about what it can do to the importMeta object that's passed in? It shouldn't, e.g., transmute it into an exotic object by mucking with the internal methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like that might need to be a more general forbidden extension then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the specific case of transmutation into an exotic sounds like a good general forbidden extension to have. Did we discuss the general invariants of this host hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as long as this hook doesn't make the object exotic, anything is fair game, including changing [[Prototype]].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as long as this hook doesn't make the object exotic, anything is fair game, including changing [[Prototype]].
That seems reasonable. Is this captured in the notes somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syg i couldn't find anything as explicit as my sentence above, but between issues and notes and light discussion with domenic that seems to be the understanding.
Layering wise there are some advantages in providing both low- and high-expressivity hooks. When reasoning about layered specs, if we know only the low-expressivity hook is implemented by the host spec, that's easier to reason about, right? Since HTML only uses the non-escape hatch, we don't have to really read HTML's implementation of the hook to know Let's chat about this on the next call. |
^ To this point, I'm not aware of any engines (except engine262) which implement both hooks, they just implement the finalize one. |
Yeah, that seems expected. My point was about reasoning about host specs, not so much implementations. |
Co-Authored-By: Domenic Denicola <[email protected]> Co-Authored-By: Sathya <[email protected]> Co-Authored-By: Peter Robins <[email protected]> Co-Authored-By: Gus Caplan <[email protected]>
Co-Authored-By: Domenic Denicola <[email protected]> Co-Authored-By: Sathya <[email protected]> Co-Authored-By: Peter Robins <[email protected]> Co-Authored-By: Gus Caplan <[email protected]>
This is the spec text for the stage 3 proposal
import.meta
.Tests are available in both test262 (tc39/test262#1888) and wpt (web-platform-tests/wpt#7888). Implementation status is very good (JavaScriptCore, QuickJS, SpiderMonkey, V8, Moddable XS, engine262, Babel, Rollup, probably more), and it is shipping in many browsers (87% on https://caniuse.com/#search=import.meta).