-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Replace invalid import attributes assertion #9599
Replace invalid import attributes assertion #9599
Conversation
When creating a module script, there is no guarantee yet that the module's dependencies only have valid import attribute keys. Instead of asserting that only `type` is used, this commit introduces proper validation throwing a SyntaxError.
8a9bfcf
to
dda740d
Compare
Hmm no, I guess this is more like (1), but then adding an extra check to skip unnecessary work? Are there tests you've written that show the choice of (1) vs. (2)? |
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.
Editorial touchups in the note, and still trying to make sure I understand the relationship to tc39/proposal-import-attributes#144 and test coverage, but this seems pretty solid.
Right, this PR does (1). Consider these three examples: import "./valid.js";
import "INVALID-URL"; import "./valid.js";
import "./valid2.js" with { type: "invalid-type" }; import "./valid.js";
import "./valid2.js" with { invalid: "invalid-attribute" }; For the first two examples, HTML currently first loads the imported specifiers and the On the other hand, for the third example HTML does not currently do any pre-validation of import attribute keys before passing the Module Record to ECMA-262, and instead it relies on ECMA-262 to validate them. This means that:
This PR aligns the third case with the other twos, by also validating the attribute keys when validating the This PR does not just introduce that check, but it specifically introduces it as the first check. This aligns the errors priority of static imports with the one of dynamic imports, as mentioned in tc39/proposal-import-attributes#144 (comment). This can currently be tested (web-platform-tests/wpt#41581) because, following what ECMA-262 does, validation of unknown attribute keys throws a |
I pushed a new test to web-platform-tests/wpt#41581. The first two tests in each file verify the order in which the import declaration checks happen, while the third one verifies that the "unknown attributes check" is present. Before this PR, this code: import "./valid" with { unknown: "foo" };
import "INVALID"; would throw about the |
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.
Thanks for the additional explanation, and tests!
For any implementation which already has import attributes or assertions, but fails to implement this edge case correctly (per your tests), please file a bug and link to it in the OP. Otherwise, we can assume this will get done correctly as part of the general import attributes work. |
I am implementing this in Chromium. I'll check what's the status in Webkit and Gecko. Both Deno and Node.js do not support the new semantics yet. |
In the past six months, the old import assertions proposal has been renamed to "import attributes" with the follwing major changes: 1. the keyword is now `with` instead of `assert` 2. unknown assertions cause an error rather than being ignored (1) has been implemented in V8 at [v8-patch], under the `--harmony-import-attributes` flag. This patch implements (2), that due to how module loading is layered must be implemented in Chromium. Implementing this change uncovered a bogous assertion in the HTML spec: this patch implements the fix proposed at [html-assertion-fix], that adds a check for invalid attributes in the "create a JavaScript module script" algorithm. WPT have been merged at [wpt], and tests for the additional HTML PR are being reviewed at [wpt2]. This patch passes all the tests in the import-assertions and import-attributes folders. [v8-patch]: https://chromium.googlesource.com/v8/v8/+/a0fd3209dda8527d7da810abe231df27fffe789e [html-assertion-fix]: whatwg/html#9599 [wpt]: web-platform-tests/wpt#41156 [wpt2]: web-platform-tests/wpt#41581 Bug: v8:13856 Change-Id: I702985feb17af1c2fefee231be0dac66b3e6cc98 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4738316 Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org> Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/main@{#1192427}
…rrors order, a=testonly Automatic update from web-platform-tests Test import declaration errors order Follows whatwg/html#9599. -- wpt-commits: bcae71ef7480ab3ac284b22f7c3768ff366f9136 wpt-pr: 41581
…rrors order, a=testonly Automatic update from web-platform-tests Test import declaration errors order Follows whatwg/html#9599. -- wpt-commits: bcae71ef7480ab3ac284b22f7c3768ff366f9136 wpt-pr: 41581
When creating a module script, there is no guarantee yet that the module's dependencies only have valid import attribute keys. Instead of asserting that only
type
is used, this commit introduces proper validation throwing a SyntaxError.I was on the fence between SyntaxError and TypeError. ECMA-262 throws a SyntaxError for invalid attributes because it throws a SyntaxError for all the errors that happen before evaluation, but HTML throws a TypeError for invalid values of the
"type"
attribute. I ended up picking SyntaxError just because it's what ECMA-262 already does.I found this bug while updating the import attributes implementation in Chromium. I'm not sure if this need explicit implementer interest given that the previous spec was just wrong.
Closes tc39/proposal-import-attributes#144.
(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/webappapis.html ( diff )