@@ -22920,33 +22920,58 @@ TEST(ScriptPositionInfo) {
2292022920 }
2292122921}
2292222922
22923- void CheckMagicComments(v8::Isolate* isolate, Local<Script> script,
22923+ template <typename T>
22924+ void CheckMagicComments(v8::Isolate* isolate, Local<T> unbound_script,
2292422925 const char* expected_source_url,
2292522926 const char* expected_source_mapping_url) {
2292622927 if (expected_source_url != nullptr) {
22927- v8::String::Utf8Value url(isolate,
22928- script->GetUnboundScript()->GetSourceURL());
22928+ v8::String::Utf8Value url(isolate, unbound_script->GetSourceURL());
2292922929 CHECK_EQ(0, strcmp(expected_source_url, *url));
2293022930 } else {
22931- CHECK(script->GetUnboundScript() ->GetSourceURL()->IsUndefined());
22931+ CHECK(unbound_script ->GetSourceURL()->IsUndefined());
2293222932 }
2293322933 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());
2293622935 CHECK_EQ(0, strcmp(expected_source_mapping_url, *url));
2293722936 } else {
22938- CHECK(script->GetUnboundScript() ->GetSourceMappingURL()->IsUndefined());
22937+ CHECK(unbound_script ->GetSourceMappingURL()->IsUndefined());
2293922938 }
2294022939}
2294122940
22942- void SourceURLHelper(v8::Isolate* isolate, const char* source ,
22941+ void SourceURLHelper(v8::Isolate* isolate, const char* source_text ,
2294322942 const char* expected_source_url,
2294422943 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+ }
2294922950
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+ }
2295022975
2295122976TEST(ScriptSourceURLAndSourceMappingURL) {
2295222977 LocalContext env;
@@ -23245,8 +23270,8 @@ void RunStreamingTest(const char** chunks, v8::ScriptType type,
2324523270 script.ToLocalChecked()->Run(env.local()).ToLocalChecked());
2324623271 // All scripts are supposed to return the fixed value 13 when ran.
2324723272 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);
2325023275 } else {
2325123276 CHECK(script.IsEmpty());
2325223277 }
0 commit comments