-
Notifications
You must be signed in to change notification settings - Fork 20
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
Rationale for optional exception #16
Comments
Browsers require the ability to:
node requires the ability to:
The first item in each list, taken together, seems to require leaving the decision about whether to throw or not up to the host. Please let me know if I'm misunderstanding something about your OP. |
Thanks, @ljharb! That's a good summary of stakeholders' requirements, but it doesn't seem to address the behavior I'm wondering about. The option to "throw an exception" is only available in the presence of the explicit syntactic marker. Since the first item in each list describes its absense, neither appear to be related. |
@jugglinmike the second two items in both lists describe its presence. |
@ljharb That's true! I was focused on the first item in each list because I thought your explanation concerns them specifically. The second two items apply to the use of You and I talked about this in IRC; for others following along:
I'm still pressing on this error because I believe that behavior is already possible for hosts without the additional language currently in the proposal. My working example is the web platform feature Content-Security Policy. That's a case where browsers are already selectively fail to load modules according to their own internal priorities. As I understand it, this is allowed by ECMA262 via HostResolveImportedModule. By my reading, web browsers are essentially saying that CSP-violating module records "cannot be created." If that's true, then can't that same language also be used to justify the rejection of modules which hosts have classified to be "non-JSON"? |
In this case, the module itself can't be rejected, only the importing callsite. |
Would you mind giving an example of a case where the distinction is observable? |
In node, for example (assuming the assertion ends up being optional, which has always been the plan), that should provide a Promise of an array of two settlement objects, both fulfilled. |
This change from the Import Assertions proposal reads like it would allow hosts to create distinct module records for each of those two ImportCalls:
If so, couldn't browsers reject the module record itself (i.e. without the optional error here in JSON modules) and still implement the expected behavior? |
Yes, browsers need the capability to do that because of race conditions - two simultaneous |
Is it accurate to say that the exception we're discussing isn't observable and that it's present to allow hosts to conform to an optional constraint? |
It would certainly be observable on browsers if you controlled the server and the client. Whenever it's not observable, then engines are encouraged to conform to the stronger constraint. (It's certainly not something test262 should or can test, I think) |
It seems that it isn't possible for authors to differentiate between the following two compliant behaviors:
Is that right?
That's been my suspicion, as well! |
It’s not possible without a very obscure testing setup, and intimate knowledge of the engine’s internals, i think. |
The proposal includes the following text:
I don't see why the proposal allows implementers to optionally throw an exception. I've summarized my understanding below to help others find the hole in my reasoning (and potentially identify an opportunity to improve the proposal's documentation).
I'm aware of the security concerns that were initially raised about an early version of this proposal, but it's not clear if/how the optional exception is related. In that issue (and the subsequent conversations at TC39 plenary throughout 2020), it seemed sufficient to give authors a means to communicate the desire, "this resource should never be evaluated as JavaScript." That allows hosts to fail the import based on additional context (e.g. web browsers receiving HTTP responses with inappropriate
Content-Type
headers).The part where I get lost is why the proposal text explicitly allows an exception. Even without import assertions, web browsers are already rejecting modules at their own discretion (e.g. due to Content-Security Policy violations). I haven't been able to find any justification for that kind of rejection in ECMA262--the closest I could find was the exception for Module Records that "[do] not exist or cannot be created." My ignorance doesn't prove anything, of course (as demonstrated by the existence of square dancing), but it makes me wonder whether it's absent because it's not necessary. If it is present, I'd be curious to learn why it doesn't apply to this case.
Even if an error is specifically necessary for modules imported using this new syntax, it seems as though the expected exception (and the security guarantee) would be naturally enforced by the semantics of the
ParseJSONModule
abstract operation. In order to present any danger in this context, the source text would necessarily fail to parse as JSON, resulting in a SyntaxError.Thanks for the help!
The text was updated successfully, but these errors were encountered: