fix: support for v8.setHeapSnapshotNearHeapLimit api (#45632)

* fix: support for v8.setHeapSnapshotNearHeapLimit api

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* docs: add support

Co-authored-by: deepak1556 <hop2deep@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
trop[bot] 2025-02-17 13:23:38 +09:00 committed by GitHub
parent cf85d2d7c1
commit fa0da6f19f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 66 additions and 6 deletions

View file

@ -33,9 +33,15 @@ namespace electron {
namespace {
gin::IsolateHolder CreateIsolateHolder(v8::Isolate* isolate) {
gin::IsolateHolder CreateIsolateHolder(v8::Isolate* isolate,
size_t* max_young_generation_size) {
std::unique_ptr<v8::Isolate::CreateParams> create_params =
gin::IsolateHolder::getDefaultIsolateParams();
// The value is needed to adjust heap limit when capturing
// snapshot via v8.setHeapSnapshotNearHeapLimit(limit) or
// --heapsnapshot-near-heap-limit=max_count.
*max_young_generation_size =
create_params->constraints.max_young_generation_size_in_bytes();
// Align behavior with V8 Isolate default for Node.js.
// This is necessary for important aspects of Node.js
// including heap and cpu profilers to function properly.
@ -55,7 +61,8 @@ gin::IsolateHolder CreateIsolateHolder(v8::Isolate* isolate) {
JavascriptEnvironment::JavascriptEnvironment(uv_loop_t* event_loop,
bool setup_wasm_streaming)
: isolate_holder_{CreateIsolateHolder(
Initialize(event_loop, setup_wasm_streaming))},
Initialize(event_loop, setup_wasm_streaming),
&max_young_generation_size_)},
isolate_{isolate_holder_.isolate()},
locker_{isolate_} {
isolate_->Enter();