Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4884746

Browse filesBrowse files
targosnodejs-github-bot
authored andcommitted
deps: V8: cherry-pick c3dffe6e2bda
Original commit message: [api] Expose parsed module source map urls Source map urls can be parsed from the magic comments. Expose them with public apis on the UnboundModuleScript, similar to the UnboundScript. Change-Id: Ia5dfdc8ff25f825c9fa7d241d0d79ba20028586b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3917379 Reviewed-by: Camillo Bruni <cbruni@chromium.org> Commit-Queue: Chengzhong Wu (legendecas) <legendecas@gmail.com> Cr-Commit-Position: refs/heads/main@{#83527} Refs: v8/v8@c3dffe6 PR-URL: #44958 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 34ba631 commit 4884746
Copy full SHA for 4884746

File tree

Expand file treeCollapse file tree

5 files changed

+95
-32
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+95
-32
lines changed
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.14',
39+
'v8_embedder_string': '-node.15',
4040

4141
##### V8 defaults for Node.js #####
4242

Collapse file

‎deps/v8/include/v8-script.h‎

Copy file name to clipboardExpand all lines: deps/v8/include/v8-script.h
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ class V8_EXPORT UnboundScript {
9292
* A compiled JavaScript module, not yet tied to a Context.
9393
*/
9494
class V8_EXPORT UnboundModuleScript : public Data {
95-
// Only used as a container for code caching.
95+
public:
96+
/**
97+
* Data read from magic sourceURL comments.
98+
*/
99+
Local<Value> GetSourceURL();
100+
/**
101+
* Data read from magic sourceMappingURL comments.
102+
*/
103+
Local<Value> GetSourceMappingURL();
96104
};
97105

98106
/**
Collapse file

‎deps/v8/src/api/api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/api/api.cc
+44-16Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,32 @@ void ObjectTemplate::SetCodeLike() {
19361936

19371937
// --- S c r i p t s ---
19381938

1939-
// Internally, UnboundScript is a SharedFunctionInfo, and Script is a
1940-
// JSFunction.
1939+
// Internally, UnboundScript and UnboundModuleScript are SharedFunctionInfos,
1940+
// and Script is a JSFunction.
1941+
1942+
namespace {
1943+
inline Local<Value> GetSharedFunctionInfoSourceMappingURL(
1944+
i::Isolate* isolate, i::Handle<i::SharedFunctionInfo> obj) {
1945+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1946+
if (obj->script().IsScript()) {
1947+
i::Object url = i::Script::cast(obj->script()).source_mapping_url();
1948+
return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
1949+
} else {
1950+
return Local<String>();
1951+
}
1952+
}
1953+
1954+
inline Local<Value> GetSharedFunctionInfoSourceURL(
1955+
i::Isolate* isolate, i::Handle<i::SharedFunctionInfo> obj) {
1956+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1957+
if (obj->script().IsScript()) {
1958+
i::Object url = i::Script::cast(obj->script()).source_url();
1959+
return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
1960+
} else {
1961+
return Local<String>();
1962+
}
1963+
}
1964+
} // namespace
19411965

19421966
ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
19431967
BufferPolicy buffer_policy_)
@@ -2022,28 +2046,32 @@ Local<Value> UnboundScript::GetSourceURL() {
20222046
i::Handle<i::SharedFunctionInfo> obj =
20232047
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
20242048
i::Isolate* i_isolate = obj->GetIsolate();
2025-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
20262049
API_RCS_SCOPE(i_isolate, UnboundScript, GetSourceURL);
2027-
if (obj->script().IsScript()) {
2028-
i::Object url = i::Script::cast(obj->script()).source_url();
2029-
return Utils::ToLocal(i::Handle<i::Object>(url, i_isolate));
2030-
} else {
2031-
return Local<String>();
2032-
}
2050+
return GetSharedFunctionInfoSourceURL(i_isolate, obj);
20332051
}
20342052

20352053
Local<Value> UnboundScript::GetSourceMappingURL() {
20362054
i::Handle<i::SharedFunctionInfo> obj =
20372055
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
20382056
i::Isolate* i_isolate = obj->GetIsolate();
20392057
API_RCS_SCOPE(i_isolate, UnboundScript, GetSourceMappingURL);
2040-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
2041-
if (obj->script().IsScript()) {
2042-
i::Object url = i::Script::cast(obj->script()).source_mapping_url();
2043-
return Utils::ToLocal(i::Handle<i::Object>(url, i_isolate));
2044-
} else {
2045-
return Local<String>();
2046-
}
2058+
return GetSharedFunctionInfoSourceMappingURL(i_isolate, obj);
2059+
}
2060+
2061+
Local<Value> UnboundModuleScript::GetSourceURL() {
2062+
i::Handle<i::SharedFunctionInfo> obj =
2063+
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
2064+
i::Isolate* i_isolate = obj->GetIsolate();
2065+
API_RCS_SCOPE(i_isolate, UnboundModuleScript, GetSourceURL);
2066+
return GetSharedFunctionInfoSourceURL(i_isolate, obj);
2067+
}
2068+
2069+
Local<Value> UnboundModuleScript::GetSourceMappingURL() {
2070+
i::Handle<i::SharedFunctionInfo> obj =
2071+
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
2072+
i::Isolate* i_isolate = obj->GetIsolate();
2073+
API_RCS_SCOPE(i_isolate, UnboundModuleScript, GetSourceMappingURL);
2074+
return GetSharedFunctionInfoSourceMappingURL(i_isolate, obj);
20472075
}
20482076

20492077
MaybeLocal<Value> Script::Run(Local<Context> context) {
Collapse file

‎deps/v8/src/logging/runtime-call-stats.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/logging/runtime-call-stats.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ class RuntimeCallTimer final {
278278
V(Uint32Array_New) \
279279
V(Uint8Array_New) \
280280
V(Uint8ClampedArray_New) \
281+
V(UnboundModuleScript_GetSourceMappingURL) \
282+
V(UnboundModuleScript_GetSourceURL) \
281283
V(UnboundScript_GetColumnNumber) \
282284
V(UnboundScript_GetId) \
283285
V(UnboundScript_GetLineNumber) \
Collapse file

‎deps/v8/test/cctest/test-api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/test/cctest/test-api.cc
+39-14Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2295122976
TEST(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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.