From 842bd96e1f97a4170d88a8cb9d09d3d383a42d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 11 Oct 2022 09:00:17 +0200 Subject: [PATCH 1/4] deps: V8: cherry-pick 8b8703953616 Original commit message: [API] Remove second OnCriticalMemoryPressure Remove the deprecated OnCriticalMemoryPressure method with receives an informative parameter. R=mlippautz@chromium.org Bug: chromium:634547 Change-Id: I932c3b5030291294dd340362f0b20d374e3067c0 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3780533 Reviewed-by: Michael Lippautz Commit-Queue: Clemens Backes Cr-Commit-Position: refs/heads/main@{#83254} Refs: https://github.com/v8/v8/commit/8b870395361633a134a257c604470378d06335ed --- common.gypi | 2 +- deps/v8/include/v8-platform.h | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/common.gypi b/common.gypi index 5f629c49634b2c..3f708d89b1ef38 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.11', + 'v8_embedder_string': '-node.12', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8-platform.h b/deps/v8/include/v8-platform.h index 5d34372df50c2b..7b2c81d136401c 100644 --- a/deps/v8/include/v8-platform.h +++ b/deps/v8/include/v8-platform.h @@ -943,18 +943,6 @@ class Platform { */ virtual void OnCriticalMemoryPressure() {} - /** - * Enables the embedder to respond in cases where V8 can't allocate large - * memory regions. The |length| parameter is the amount of memory needed. - * Returns true if memory is now available. Returns false if no memory could - * be made available. V8 will retry allocations until this method returns - * false. - * - * Embedder overrides of this function must NOT call back into V8. - */ - V8_DEPRECATED("Use the method without informative parameter") - virtual bool OnCriticalMemoryPressure(size_t length) { return false; } - /** * Gets the number of worker threads used by * Call(BlockingTask)OnWorkerThread(). This can be used to estimate the number From 82fb1af3a88db596215f59be57e5dc90bc061aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 11 Oct 2022 09:04:31 +0200 Subject: [PATCH 2/4] deps: V8: cherry-pick 3d59a3c2c164 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: Add option to report discarded allocations in sampling heap profiler A couple of customers have asked about using devtools to get information about temporary allocations, with the goal of reducing GC time and/or peak memory usage. Currently, the sampling heap profiler reports only objects which are still alive at the end of the profiling session. In this change, I propose adding configuration options when starting the sampling heap profiler so that it can optionally include information about objects which were discarded by the GC before the end of the profiling session. A user could run the sampling heap profiler in several different modes depending on their goals: 1. To find memory leaks or determine which functions contribute most to steady-state memory consumption, the current default mode is best. 2. To find functions which cause large temporary memory spikes or large GC pauses, the user can request data about both live objects and those collected by major GC. 3. To tune for minimal GC activity in latency-sensitive applications like real-time audio processing, the user can request data about every allocation, including objects collected by major or minor GC. 4. I'm not sure why anybody would want data about objects collected by minor GC and not objects collected by major GC, but it's also a valid flags combination. Change-Id: If55d5965a1de04fed3ae640a02ca369723f64fdf Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3868522 Reviewed-by: Michael Lippautz Reviewed-by: Camillo Bruni Reviewed-by: Simon Zünd Commit-Queue: Seth Brenith Cr-Commit-Position: refs/heads/main@{#83202} Refs: https://github.com/v8/v8/commit/3d59a3c2c16405eea59263300c5591c3283a2a0e --- common.gypi | 2 +- deps/v8/include/js_protocol.pdl | 16 +++++ deps/v8/include/v8-profiler.h | 8 +-- deps/v8/src/heap/heap.cc | 2 + deps/v8/src/heap/heap.h | 6 ++ .../inspector/v8-heap-profiler-agent-impl.cc | 26 +++++++- .../inspector/v8-heap-profiler-agent-impl.h | 4 +- .../v8/src/profiler/sampling-heap-profiler.cc | 13 ++++ .../sampling-heap-profiler-flags-expected.txt | 6 ++ .../sampling-heap-profiler-flags.js | 61 +++++++++++++++++++ 10 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags-expected.txt create mode 100644 deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js diff --git a/common.gypi b/common.gypi index 3f708d89b1ef38..0e5ce682494601 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.12', + 'v8_embedder_string': '-node.13', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/js_protocol.pdl b/deps/v8/include/js_protocol.pdl index 8d8211bf989f13..2d560435522769 100644 --- a/deps/v8/include/js_protocol.pdl +++ b/deps/v8/include/js_protocol.pdl @@ -766,6 +766,22 @@ experimental domain HeapProfiler # Average sample interval in bytes. Poisson distribution is used for the intervals. The # default value is 32768 bytes. optional number samplingInterval + # By default, the sampling heap profiler reports only objects which are + # still alive when the profile is returned via getSamplingProfile or + # stopSampling, which is useful for determining what functions contribute + # the most to steady-state memory usage. This flag instructs the sampling + # heap profiler to also include information about objects discarded by + # major GC, which will show which functions cause large temporary memory + # usage or long GC pauses. + optional boolean includeObjectsCollectedByMajorGC + # By default, the sampling heap profiler reports only objects which are + # still alive when the profile is returned via getSamplingProfile or + # stopSampling, which is useful for determining what functions contribute + # the most to steady-state memory usage. This flag instructs the sampling + # heap profiler to also include information about objects discarded by + # minor GC, which is useful when tuning a latency-sensitive application + # for minimal GC activity. + optional boolean includeObjectsCollectedByMinorGC command startTrackingHeapObjects parameters diff --git a/deps/v8/include/v8-profiler.h b/deps/v8/include/v8-profiler.h index 8894641993e42a..6145a2257ad05b 100644 --- a/deps/v8/include/v8-profiler.h +++ b/deps/v8/include/v8-profiler.h @@ -903,6 +903,8 @@ class V8_EXPORT HeapProfiler { enum SamplingFlags { kSamplingNoFlags = 0, kSamplingForceGC = 1 << 0, + kSamplingIncludeObjectsCollectedByMajorGC = 1 << 1, + kSamplingIncludeObjectsCollectedByMinorGC = 1 << 2, }; /** @@ -1097,10 +1099,8 @@ class V8_EXPORT HeapProfiler { * |stack_depth| parameter controls the maximum number of stack frames to be * captured on each allocation. * - * NOTE: This is a proof-of-concept at this point. Right now we only sample - * newspace allocations. Support for paged space allocation (e.g. pre-tenured - * objects, large objects, code objects, etc.) and native allocations - * doesn't exist yet, but is anticipated in the future. + * NOTE: Support for native allocations doesn't exist yet, but is anticipated + * in the future. * * Objects allocated before the sampling is started will not be included in * the profile. diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index 5a307ff9e1306b..d966d979c87c99 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -1819,6 +1819,8 @@ bool Heap::CollectGarbage(AllocationSpace space, collector = SelectGarbageCollector(space, gc_reason, &collector_reason); + current_or_last_garbage_collector_ = collector; + if (collector == GarbageCollector::MARK_COMPACTOR && incremental_marking()->IsMinorMarking()) { CollectGarbage(NEW_SPACE, GarbageCollectionReason::kFinalizeMinorMC); diff --git a/deps/v8/src/heap/heap.h b/deps/v8/src/heap/heap.h index daca78390179bf..6e270f246df648 100644 --- a/deps/v8/src/heap/heap.h +++ b/deps/v8/src/heap/heap.h @@ -1455,6 +1455,10 @@ class Heap { bool is_current_gc_forced() const { return is_current_gc_forced_; } + GarbageCollector current_or_last_garbage_collector() const { + return current_or_last_garbage_collector_; + } + // Returns whether the currently in-progress GC should avoid increasing the // ages on any objects that live for a set number of collections. bool ShouldCurrentGCKeepAgesUnchanged() const { @@ -2389,6 +2393,8 @@ class Heap { bool is_current_gc_forced_ = false; bool is_current_gc_for_heap_profiler_ = false; + GarbageCollector current_or_last_garbage_collector_ = + GarbageCollector::SCAVENGER; ExternalStringTable external_string_table_; diff --git a/deps/v8/src/inspector/v8-heap-profiler-agent-impl.cc b/deps/v8/src/inspector/v8-heap-profiler-agent-impl.cc index 13dfd69bbeb587..4e8197fdec5c41 100644 --- a/deps/v8/src/inspector/v8-heap-profiler-agent-impl.cc +++ b/deps/v8/src/inspector/v8-heap-profiler-agent-impl.cc @@ -29,6 +29,7 @@ static const char allocationTrackingEnabled[] = "allocationTrackingEnabled"; static const char samplingHeapProfilerEnabled[] = "samplingHeapProfilerEnabled"; static const char samplingHeapProfilerInterval[] = "samplingHeapProfilerInterval"; +static const char samplingHeapProfilerFlags[] = "samplingHeapProfilerFlags"; } // namespace HeapProfilerAgentState class HeapSnapshotProgress final : public v8::ActivityControl { @@ -208,7 +209,16 @@ void V8HeapProfilerAgentImpl::restore() { double samplingInterval = m_state->doubleProperty( HeapProfilerAgentState::samplingHeapProfilerInterval, -1); DCHECK_GE(samplingInterval, 0); - startSampling(Maybe(samplingInterval)); + int flags = m_state->integerProperty( + HeapProfilerAgentState::samplingHeapProfilerFlags, 0); + startSampling( + Maybe(samplingInterval), + Maybe( + flags & + v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMajorGC), + Maybe( + flags & + v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMinorGC)); } } @@ -387,7 +397,9 @@ void V8HeapProfilerAgentImpl::stopTrackingHeapObjectsInternal() { } Response V8HeapProfilerAgentImpl::startSampling( - Maybe samplingInterval) { + Maybe samplingInterval, + Maybe includeObjectsCollectedByMajorGC, + Maybe includeObjectsCollectedByMinorGC) { v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); if (!profiler) return Response::ServerError("Cannot access v8 heap profiler"); const unsigned defaultSamplingInterval = 1 << 15; @@ -400,9 +412,17 @@ Response V8HeapProfilerAgentImpl::startSampling( samplingIntervalValue); m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, true); + int flags = v8::HeapProfiler::kSamplingForceGC; + if (includeObjectsCollectedByMajorGC.fromMaybe(false)) { + flags |= v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMajorGC; + } + if (includeObjectsCollectedByMinorGC.fromMaybe(false)) { + flags |= v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMinorGC; + } + m_state->setInteger(HeapProfilerAgentState::samplingHeapProfilerFlags, flags); profiler->StartSamplingHeapProfiler( static_cast(samplingIntervalValue), 128, - v8::HeapProfiler::kSamplingForceGC); + static_cast(flags)); return Response::Success(); } diff --git a/deps/v8/src/inspector/v8-heap-profiler-agent-impl.h b/deps/v8/src/inspector/v8-heap-profiler-agent-impl.h index 0387a006b81417..61c6b6af53b9d5 100644 --- a/deps/v8/src/inspector/v8-heap-profiler-agent-impl.h +++ b/deps/v8/src/inspector/v8-heap-profiler-agent-impl.h @@ -56,7 +56,9 @@ class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend { Response getHeapObjectId(const String16& objectId, String16* heapSnapshotObjectId) override; - Response startSampling(Maybe samplingInterval) override; + Response startSampling(Maybe samplingInterval, + Maybe includeObjectsCollectedByMajorGC, + Maybe includeObjectsCollectedByMinorGC) override; Response stopSampling( std::unique_ptr*) override; Response getSamplingProfile( diff --git a/deps/v8/src/profiler/sampling-heap-profiler.cc b/deps/v8/src/profiler/sampling-heap-profiler.cc index 45c72ec20294fa..b38d235e988e61 100644 --- a/deps/v8/src/profiler/sampling-heap-profiler.cc +++ b/deps/v8/src/profiler/sampling-heap-profiler.cc @@ -95,6 +95,19 @@ void SamplingHeapProfiler::SampleObject(Address soon_object, size_t size) { void SamplingHeapProfiler::OnWeakCallback( const WeakCallbackInfo& data) { Sample* sample = data.GetParameter(); + Heap* heap = reinterpret_cast(data.GetIsolate())->heap(); + bool is_minor_gc = + heap->current_or_last_garbage_collector() == GarbageCollector::SCAVENGER; + bool should_keep_sample = + is_minor_gc + ? (sample->profiler->flags_ & + v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMinorGC) + : (sample->profiler->flags_ & + v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMajorGC); + if (should_keep_sample) { + sample->global.Reset(); + return; + } AllocationNode* node = sample->owner; DCHECK_GT(node->allocations_[sample->size], 0); node->allocations_[sample->size]--; diff --git a/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags-expected.txt b/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags-expected.txt new file mode 100644 index 00000000000000..9d66bce04389d9 --- /dev/null +++ b/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags-expected.txt @@ -0,0 +1,6 @@ +Checks sampling heap profiler methods. +Retained size is less than 10KB: true +Including major GC increases size: true +Minor GC collected more: true +Total allocation is greater than 100KB: true +Successfully finished diff --git a/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js b/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js new file mode 100644 index 00000000000000..7a1ffa9472b78b --- /dev/null +++ b/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js @@ -0,0 +1,61 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --sampling-heap-profiler-suppress-randomness + +(async function() { + let {contextGroup, Protocol} = InspectorTest.start('Checks sampling heap profiler methods.'); + + contextGroup.addScript(` + function generateTrash() { + var arr = new Array(100); + for (var i = 0; i < 3000; ++i) { + var s = {a:i, b: new Array(100).fill(42)}; + arr[i % 100] = s; + } + return arr[30]; + } + //# sourceURL=test.js`); + + Protocol.HeapProfiler.enable(); + + await Protocol.HeapProfiler.startSampling({ + samplingInterval: 1e4, + includeObjectsCollectedByMajorGC: false, + includeObjectsCollectedByMinorGC: false, + }); + await Protocol.Runtime.evaluate({ expression: 'generateTrash()' }); + const profile1 = await Protocol.HeapProfiler.stopSampling(); + const size1 = nodeSize(profile1.result.profile.head); + InspectorTest.log('Retained size is less than 10KB:', size1 < 10000); + + await Protocol.HeapProfiler.startSampling({ + samplingInterval: 100, + includeObjectsCollectedByMajorGC: true, + includeObjectsCollectedByMinorGC: false, + }); + await Protocol.Runtime.evaluate({ expression: 'generateTrash()' }); + const profile2 = await Protocol.HeapProfiler.stopSampling(); + const size2 = nodeSize(profile2.result.profile.head); + InspectorTest.log('Including major GC increases size:', size1 < size2); + + await Protocol.HeapProfiler.startSampling({ + samplingInterval: 100, + includeObjectsCollectedByMajorGC: true, + includeObjectsCollectedByMinorGC: true, + }); + await Protocol.Runtime.evaluate({ expression: 'generateTrash()' }); + const profile3 = await Protocol.HeapProfiler.stopSampling(); + const size3 = nodeSize(profile3.result.profile.head); + InspectorTest.log('Minor GC collected more:', size3 > size2); + InspectorTest.log('Total allocation is greater than 100KB:', size3 > 100000); + + InspectorTest.log('Successfully finished'); + InspectorTest.completeTest(); + + function nodeSize(node) { + return node.children.reduce((res, child) => res + nodeSize(child), + node.callFrame.functionName === 'generateTrash' ? node.selfSize : 0); + } +})(); From 775476cce083555a2642232c4d9087764e2a33e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 11 Oct 2022 09:05:51 +0200 Subject: [PATCH 3/4] deps: V8: cherry-pick e7f0f26f5ef3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: Don't run sampling-heap-profiler-flags with stress-incremental-marking This test observes GC behavior and needs the garbage collector to work in a somewhat predictable way. Bug: v8:13286 Change-Id: I24e6a4f33a644b5f1845cd34558da03fc196f7e5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3898721 Commit-Queue: Seth Brenith Reviewed-by: Simon Zünd Cr-Commit-Position: refs/heads/main@{#83218} Refs: https://github.com/v8/v8/commit/e7f0f26f5ef34db70e944218e72febb4fbe7eaa8 --- common.gypi | 2 +- .../inspector/heap-profiler/sampling-heap-profiler-flags.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 0e5ce682494601..2a06e7d1401df0 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.13', + 'v8_embedder_string': '-node.14', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js b/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js index 7a1ffa9472b78b..89aa552b18712b 100644 --- a/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js +++ b/deps/v8/test/inspector/heap-profiler/sampling-heap-profiler-flags.js @@ -3,6 +3,7 @@ // found in the LICENSE file. // Flags: --sampling-heap-profiler-suppress-randomness +// Flags: --no-stress-incremental-marking (async function() { let {contextGroup, Protocol} = InspectorTest.start('Checks sampling heap profiler methods.'); From ae1d02cca04f75c1935fac9df7ef1fc6cda215b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 11 Oct 2022 09:07:46 +0200 Subject: [PATCH 4/4] 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 Commit-Queue: Chengzhong Wu (legendecas) Cr-Commit-Position: refs/heads/main@{#83527} Refs: https://github.com/v8/v8/commit/c3dffe6e2bdab79bb5bfb94be9fcc6a16adf6cf5 --- common.gypi | 2 +- deps/v8/include/v8-script.h | 10 +++- deps/v8/src/api/api.cc | 60 +++++++++++++++++------- deps/v8/src/logging/runtime-call-stats.h | 2 + deps/v8/test/cctest/test-api.cc | 53 +++++++++++++++------ 5 files changed, 95 insertions(+), 32 deletions(-) diff --git a/common.gypi b/common.gypi index 2a06e7d1401df0..ccfd1bccb167d7 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.14', + 'v8_embedder_string': '-node.15', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8-script.h b/deps/v8/include/v8-script.h index dbd98ed55b4ce0..e2ba845268d921 100644 --- a/deps/v8/include/v8-script.h +++ b/deps/v8/include/v8-script.h @@ -92,7 +92,15 @@ class V8_EXPORT UnboundScript { * A compiled JavaScript module, not yet tied to a Context. */ class V8_EXPORT UnboundModuleScript : public Data { - // Only used as a container for code caching. + public: + /** + * Data read from magic sourceURL comments. + */ + Local GetSourceURL(); + /** + * Data read from magic sourceMappingURL comments. + */ + Local GetSourceMappingURL(); }; /** diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 608da3369fabaf..cf755cafc2cb41 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -1936,8 +1936,32 @@ void ObjectTemplate::SetCodeLike() { // --- S c r i p t s --- -// Internally, UnboundScript is a SharedFunctionInfo, and Script is a -// JSFunction. +// Internally, UnboundScript and UnboundModuleScript are SharedFunctionInfos, +// and Script is a JSFunction. + +namespace { +inline Local GetSharedFunctionInfoSourceMappingURL( + i::Isolate* isolate, i::Handle obj) { + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + if (obj->script().IsScript()) { + i::Object url = i::Script::cast(obj->script()).source_mapping_url(); + return Utils::ToLocal(i::Handle(url, isolate)); + } else { + return Local(); + } +} + +inline Local GetSharedFunctionInfoSourceURL( + i::Isolate* isolate, i::Handle obj) { + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + if (obj->script().IsScript()) { + i::Object url = i::Script::cast(obj->script()).source_url(); + return Utils::ToLocal(i::Handle(url, isolate)); + } else { + return Local(); + } +} +} // namespace ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_, BufferPolicy buffer_policy_) @@ -2022,14 +2046,8 @@ Local UnboundScript::GetSourceURL() { i::Handle obj = i::Handle::cast(Utils::OpenHandle(this)); i::Isolate* i_isolate = obj->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); API_RCS_SCOPE(i_isolate, UnboundScript, GetSourceURL); - if (obj->script().IsScript()) { - i::Object url = i::Script::cast(obj->script()).source_url(); - return Utils::ToLocal(i::Handle(url, i_isolate)); - } else { - return Local(); - } + return GetSharedFunctionInfoSourceURL(i_isolate, obj); } Local UnboundScript::GetSourceMappingURL() { @@ -2037,13 +2055,23 @@ Local UnboundScript::GetSourceMappingURL() { i::Handle::cast(Utils::OpenHandle(this)); i::Isolate* i_isolate = obj->GetIsolate(); API_RCS_SCOPE(i_isolate, UnboundScript, GetSourceMappingURL); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); - if (obj->script().IsScript()) { - i::Object url = i::Script::cast(obj->script()).source_mapping_url(); - return Utils::ToLocal(i::Handle(url, i_isolate)); - } else { - return Local(); - } + return GetSharedFunctionInfoSourceMappingURL(i_isolate, obj); +} + +Local UnboundModuleScript::GetSourceURL() { + i::Handle obj = + i::Handle::cast(Utils::OpenHandle(this)); + i::Isolate* i_isolate = obj->GetIsolate(); + API_RCS_SCOPE(i_isolate, UnboundModuleScript, GetSourceURL); + return GetSharedFunctionInfoSourceURL(i_isolate, obj); +} + +Local UnboundModuleScript::GetSourceMappingURL() { + i::Handle obj = + i::Handle::cast(Utils::OpenHandle(this)); + i::Isolate* i_isolate = obj->GetIsolate(); + API_RCS_SCOPE(i_isolate, UnboundModuleScript, GetSourceMappingURL); + return GetSharedFunctionInfoSourceMappingURL(i_isolate, obj); } MaybeLocal Script::Run(Local context) { diff --git a/deps/v8/src/logging/runtime-call-stats.h b/deps/v8/src/logging/runtime-call-stats.h index e6998d4bfb1330..4c02309b7493dd 100644 --- a/deps/v8/src/logging/runtime-call-stats.h +++ b/deps/v8/src/logging/runtime-call-stats.h @@ -278,6 +278,8 @@ class RuntimeCallTimer final { V(Uint32Array_New) \ V(Uint8Array_New) \ V(Uint8ClampedArray_New) \ + V(UnboundModuleScript_GetSourceMappingURL) \ + V(UnboundModuleScript_GetSourceURL) \ V(UnboundScript_GetColumnNumber) \ V(UnboundScript_GetId) \ V(UnboundScript_GetLineNumber) \ diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index 759851f6997596..51294fccc8d888 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -22920,33 +22920,58 @@ TEST(ScriptPositionInfo) { } } -void CheckMagicComments(v8::Isolate* isolate, Local