Commit a2bf6f9
committed
Refactor console method decoration for snapshotting
The current console decoration scheme breaks V8 snapshot creation in
two ways:
1) The C++ lambdas used as decorators hold v8::Global handles to the
original console methods, but V8 does not support serializing Global
handles.
2) The decorator for each console method is created through
wrapSimpleFunction, which allocates an opaque JS wrapper using the
Wrappable path and binds that wrapper to the resulting V8 function
via V8::Function::New. The JS wrapper, which holds the C++ lambda,
belongs to the context. However, V8 snapshot forbids pointers from
isolate-level snapshot objects to context-level data. In this case,
the function/template machinery belongs to the isolate-level snapshot,
while the wrapper belongs to the context-level snapshot.
This patch addresses both issues:
- We preserve the original methods in a private, context-level
embedder-data slots instead of holding them in v8::Global handles.
This establishes edges from the context to those JS objects, so they
remain reachable and are automatically captured in the snapshot as
part of the context graph.
- We no longer use the Wrappable path for decoration. Instead, we create
the V8 functions directly with V8::Function::New and use a plain C++
functor that retrieves the required state from the context-level
embedder-data slot. This avoids creating JS wrappers that hold
references to C++ state.1 parent 5f8e696 commit a2bf6f9
3 files changed
Lines changed: 254 additions & 168 deletions
0 commit comments