mirror of
https://github.com/electron/electron.git
synced 2026-10-28 19:54:46 +08:00
Emit the bundles under gen/internal/electron/js2c so js2c gives them internal/electron/js2c/* ids: they leave module.builtinModules, cannot be required or fetched with process.getBuiltinModule() from app code (which crashed under ELECTRON_RUN_AS_NODE), and parallel/test-process-get-builtin is re-enabled.
50 lines
2.0 KiB
C++
50 lines
2.0 KiB
C++
// Copyright (c) 2026 Anthropic, PBC.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_COMMON_NODE_NATIVES_CODE_CACHE_H_
|
|
#define ELECTRON_SHELL_COMMON_NODE_NATIVES_CODE_CACHE_H_
|
|
|
|
#include <vector>
|
|
|
|
namespace node::builtins {
|
|
struct CodeCacheInfo;
|
|
} // namespace node::builtins
|
|
|
|
namespace electron {
|
|
|
|
// V8's code cache key includes the non-default flag set and the snapshot's
|
|
// read-only checksum, both of which differ per process type, so one cache
|
|
// variant is generated per flavor and each process consumes the matching one.
|
|
enum class Js2cCacheFlavor {
|
|
kSandbox, // sandboxed renderer (no Node env)
|
|
kRenderer, // normal renderer
|
|
// Every process whose isolate is created from the embedded Node startup
|
|
// snapshot (browser, node-service utility, ELECTRON_RUN_AS_NODE), or the
|
|
// browser process / ELECTRON_RUN_AS_NODE on builds without one.
|
|
kBrowser,
|
|
// The node-service utility process when bootstrapped from scratch, and
|
|
// --type-less processes that boot from the v8 context snapshot although the
|
|
// build embeds a Node snapshot (custom V8 snapshot loaded).
|
|
kUtility,
|
|
kWorker,
|
|
};
|
|
|
|
// `has_node_env` distinguishes a sandboxed renderer (false) from a normal
|
|
// one (true): pass `node::Environment::GetCurrent(context) != nullptr`.
|
|
Js2cCacheFlavor CurrentProcessJs2cCacheFlavor(bool has_node_env = true);
|
|
|
|
// Build-time V8 code cache for the embedded internal/electron/js2c/* bundles --
|
|
// plus, for flavors whose Node environment is bootstrapped from scratch rather
|
|
// than deserialized from the embedded Node startup snapshot, Node's own
|
|
// builtins -- fed to the BuiltinLoader so they are deserialized rather than
|
|
// parsed + compiled from source on startup. Empty when no generated cache was
|
|
// built; V8 also gracefully falls back to compiling from source on a
|
|
// stale/mismatched blob.
|
|
const std::vector<node::builtins::CodeCacheInfo>& GetNativesCodeCache(
|
|
Js2cCacheFlavor flavor);
|
|
|
|
} // namespace electron
|
|
|
|
#endif // ELECTRON_SHELL_COMMON_NODE_NATIVES_CODE_CACHE_H_
|