Files
Shelley Vohr b8cf2969e1 refactor: look up internalBinding and linked bindings without patching Node (#53528)
* refactor: look up internalBinding and linked bindings without patching Node

asar-fs-wrapper takes internalBinding from require('internal/bootstrap/realm');
sandboxed preloads resolve linked bindings through NodeBindings::GetLinkedBinding(),
backed by accessors the NODE_LINKED_BINDING_CONTEXT_AWARE macro now emits. Drops
the two Node patches that exposed process.internalBinding and
node::binding::get_linked_module().

* chore: clang-format

* fix: only run the node_init preload in the principal realm

Node runs the embedder preload for ShadowRealms too. The bundle used to bail
there by accident (process.internalBinding was undefined); now that
internalBinding resolves it got as far as require('child_process') and hit the
PipeWrap template CHECK. Skip non-principal realms explicitly, which also lets
parallel/test-shadow-realm-custom-loaders run again.

* chore: clang-format
2026-09-05 11:00:15 +02:00

55 lines
1.7 KiB
C

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_NODE_INCLUDES_H_
#define ELECTRON_SHELL_COMMON_NODE_INCLUDES_H_
// Include common headers for using node APIs.
#ifdef NODE_SHARED_MODE
#define BUILDING_NODE_EXTENSION
#endif
#undef debug_string // This is defined in macOS SDK in AssertMacros.h.
#undef require_string // This is defined in macOS SDK in AssertMacros.h.
#include "electron/push_and_undef_node_defines.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#include "env-inl.h"
#include "env.h"
#include "node.h"
#include "node_buffer.h"
#include "node_builtins.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_object_wrap.h"
#include "node_options-inl.h"
#include "node_options.h"
#include "node_platform.h"
#include "node_report.h"
#include "tracing/agent.h"
#pragma clang diagnostic pop
#include "electron/pop_node_defines.h"
// Undefine these defines from libuv which conflict with other headers
#undef RB_BLACK
#undef RB_RED
// Alternative to NODE_BINDING_CONTEXT_AWARE_X.
// Allows to explicitly register builtin bindings instead of using
// __attribute__((constructor)), and to look one up without a node::Environment
// (NodeBindings::GetLinkedBinding).
#define NODE_LINKED_BINDING_CONTEXT_AWARE(modname, regfunc) \
NODE_BINDING_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_LINKED) \
node::node_module* get_linked_module_##modname() { \
return &_module; \
}
#endif // ELECTRON_SHELL_COMMON_NODE_INCLUDES_H_