Skip to content

Commit 4b4d7ee

Browse files
authored
Add diagnostic logging to determine import assertion use (#3389)
1 parent 795e7d7 commit 4b4d7ee

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/workerd/jsg/modules.c++

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ v8::MaybeLocal<v8::Module> resolveCallback(v8::Local<v8::Context> context,
2222
auto& js = jsg::Lock::from(context->GetIsolate());
2323
v8::MaybeLocal<v8::Module> result;
2424

25+
// TODO(new-module-registry): The specification for import assertions strongly
26+
// recommends that embedders reject import attributes and types they do not
27+
// understand/implement. This is because import attributes can alter the
28+
// interpretation of a module and are considered to be part of the unique
29+
// key for caching a module.
30+
// Throwing an error for things we do not understand is the safest thing to do.
31+
// However, historically we have not followed this guideline in the spec and
32+
// it's not clear if enforcing that constraint would be breaking so let's
33+
// first try to determine if anyone is making use of import assertions.
34+
// If we're lucky, we won't receive any hits on this and we can start
35+
// enforcing the rule without a compat flag.
36+
if (import_assertions->Length() > 0) {
37+
LOG_NOSENTRY(WARNING, "Import attributes specified (and ignored) on static import");
38+
}
39+
2540
js.tryCatch([&] {
2641
auto registry = getModulesForResolveCallback(js.v8Isolate);
2742
KJ_REQUIRE(registry != nullptr, "didn't expect resolveCallback() now");

src/workerd/jsg/modules.h

+15
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,21 @@ v8::MaybeLocal<v8::Promise> dynamicImportCallback(v8::Local<v8::Context> context
645645
auto registry = ModuleRegistry::from(js);
646646
auto& wrapper = TypeWrapper::from(js.v8Isolate);
647647

648+
// TODO(new-module-registry): The specification for import assertions strongly
649+
// recommends that embedders reject import attributes and types they do not
650+
// understand/implement. This is because import attributes can alter the
651+
// interpretation of a module and are considered to be part of the unique
652+
// key for caching a module.
653+
// Throwing an error for things we do not understand is the safest thing to do.
654+
// However, historically we have not followed this guideline in the spec and
655+
// it's not clear if enforcing that constraint would be breaking so let's
656+
// first try to determine if anyone is making use of import assertions.
657+
// If we're lucky, we won't receive any hits on this and we can start
658+
// enforcing the rule without a compat flag.
659+
if (import_assertions->Length() > 0) {
660+
LOG_NOSENTRY(WARNING, "Import attributes specified (and ignored) on dynamic import");
661+
}
662+
648663
// TODO(cleanup): This could probably be simplified using jsg::Promise
649664
const auto makeRejected = [&](auto reason) {
650665
v8::Local<v8::Promise::Resolver> resolver;

0 commit comments

Comments
 (0)