@@ -22920,33 +22920,58 @@ TEST(ScriptPositionInfo) {
22920
22920
}
22921
22921
}
22922
22922
22923
- void CheckMagicComments(v8::Isolate* isolate, Local<Script> script,
22923
+ template <typename T>
22924
+ void CheckMagicComments(v8::Isolate* isolate, Local<T> unbound_script,
22924
22925
const char* expected_source_url,
22925
22926
const char* expected_source_mapping_url) {
22926
22927
if (expected_source_url != nullptr) {
22927
- v8::String::Utf8Value url(isolate,
22928
- script->GetUnboundScript()->GetSourceURL());
22928
+ v8::String::Utf8Value url(isolate, unbound_script->GetSourceURL());
22929
22929
CHECK_EQ(0, strcmp(expected_source_url, *url));
22930
22930
} else {
22931
- CHECK(script->GetUnboundScript() ->GetSourceURL()->IsUndefined());
22931
+ CHECK(unbound_script ->GetSourceURL()->IsUndefined());
22932
22932
}
22933
22933
if (expected_source_mapping_url != nullptr) {
22934
- v8::String::Utf8Value url(
22935
- isolate, script->GetUnboundScript()->GetSourceMappingURL());
22934
+ v8::String::Utf8Value url(isolate, unbound_script->GetSourceMappingURL());
22936
22935
CHECK_EQ(0, strcmp(expected_source_mapping_url, *url));
22937
22936
} else {
22938
- CHECK(script->GetUnboundScript() ->GetSourceMappingURL()->IsUndefined());
22937
+ CHECK(unbound_script ->GetSourceMappingURL()->IsUndefined());
22939
22938
}
22940
22939
}
22941
22940
22942
- void SourceURLHelper(v8::Isolate* isolate, const char* source ,
22941
+ void SourceURLHelper(v8::Isolate* isolate, const char* source_text ,
22943
22942
const char* expected_source_url,
22944
22943
const char* expected_source_mapping_url) {
22945
- Local<Script> script = v8_compile(source);
22946
- CheckMagicComments(isolate, script, expected_source_url,
22947
- expected_source_mapping_url);
22948
- }
22944
+ // Check scripts
22945
+ {
22946
+ Local<Script> script = v8_compile(source_text);
22947
+ CheckMagicComments(isolate, script->GetUnboundScript(), expected_source_url,
22948
+ expected_source_mapping_url);
22949
+ }
22949
22950
22951
+ // Check modules
22952
+ {
22953
+ Local<v8::String> source_str = v8_str(source_text);
22954
+ // Set a different resource name with the case above to invalidate the
22955
+ // cache.
22956
+ v8::ScriptOrigin origin(isolate,
22957
+ v8_str("module.js"), // resource name
22958
+ 0, // line offset
22959
+ 0, // column offset
22960
+ true, // is cross origin
22961
+ -1, // script id
22962
+ Local<Value>(), // source map URL
22963
+ false, // is opaque
22964
+ false, // is WASM
22965
+ true // is ES Module
22966
+ );
22967
+ v8::ScriptCompiler::Source source(source_str, origin, nullptr);
22968
+
22969
+ Local<v8::Module> module =
22970
+ v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
22971
+ CheckMagicComments(isolate, module->GetUnboundModuleScript(),
22972
+ expected_source_url, expected_source_mapping_url);
22973
+ }
22974
+ }
22950
22975
22951
22976
TEST(ScriptSourceURLAndSourceMappingURL) {
22952
22977
LocalContext env;
@@ -23245,8 +23270,8 @@ void RunStreamingTest(const char** chunks, v8::ScriptType type,
23245
23270
script.ToLocalChecked()->Run(env.local()).ToLocalChecked());
23246
23271
// All scripts are supposed to return the fixed value 13 when ran.
23247
23272
CHECK_EQ(13, result->Int32Value(env.local()).FromJust());
23248
- CheckMagicComments(isolate, script.ToLocalChecked(), expected_source_url ,
23249
- expected_source_mapping_url);
23273
+ CheckMagicComments(isolate, script.ToLocalChecked()->GetUnboundScript() ,
23274
+ expected_source_url, expected_source_mapping_url);
23250
23275
} else {
23251
23276
CHECK(script.IsEmpty());
23252
23277
}
0 commit comments