mirror of
https://github.com/electron/electron.git
synced 2026-01-10 07:58:08 -05:00
* chore: upgrade Node.js to v24.10.0 * chore: fixup crypto patch * chore: fixup crypto test patch * src: prepare for v8 sandboxing https://github.com/nodejs/node/pull/58376 * esm: fix module.exports export on CJS modules https://github.com/nodejs/node/pull/57366 * chore: fixup lazyload fs patch * esm: Source Phase Imports for WebAssembly https://github.com/nodejs/node/pull/56919 * module: remove --experimental-default-type https://github.com/nodejs/node/pull/56092 * lib,src: refactor assert to load error source from memory https://github.com/nodejs/node/pull/59751 * src: add source location to v8::TaskRunner https://github.com/nodejs/node/pull/54077 * src: remove dependency on wrapper-descriptor-based CppHeap https://github.com/nodejs/node/pull/54077 * src: do not use soon-to-be-deprecated V8 API https://github.com/nodejs/node/pull/53174 * src: stop using deprecated fields of v8::FastApiCallbackOptions https://github.com/nodejs/node/pull/54077 * test: update v8-stats test for V8 12.6 https://github.com/nodejs/node/pull/54077 * esm: unflag --experimental-wasm-modules https://github.com/nodejs/node/pull/57038 * test: adapt assert tests to stack trace changes https://github.com/nodejs/node/pull/58070 * src,test: unregister the isolate after disposal and before freeing https://github.com/nodejs/node/pull/58070 * src: use cppgc to manage ContextifyContext https://github.com/nodejs/node/pull/56522 * src: replace uses of FastApiTypedArray https://github.com/nodejs/node/pull/58070 * module: integrate TypeScript into compile cache https://github.com/nodejs/node/pull/56629 * deps: update ada to 3.2.7 https://github.com/nodejs/node/pull/59336 * src: make minor cleanups in encoding_binding.cc https://github.com/nodejs/node/pull/57448 * src: switch from `Get/SetPrototype` to `Get/SetPrototypeV2` https://github.com/nodejs/node/pull/55453 * src: use non-deprecated Get/SetPrototype methods https://github.com/nodejs/node/pull/59671 * src: simplify string_bytes with views https://github.com/nodejs/node/pull/54876 * src: improve utf8 string generation performance https://github.com/nodejs/node/pull/54873 * src: use non-deprecated Utf8LengthV2() method https://github.com/nodejs/node/pull/58070 * src: use non-deprecated WriteUtf8V2() method https://github.com/nodejs/node/pull/58070 * src: refactor WriteUCS2 and remove flags argument https://github.com/nodejs/node/pull/58163 * src: use String::WriteV2() in TwoByteValue https://github.com/nodejs/node/pull/58164 * node-api: use WriteV2 in napi_get_value_string_utf16 https://github.com/nodejs/node/pull/58165 * node-api: use WriteOneByteV2 in napi_get_value_string_latin1 https://github.com/nodejs/node/pull/58325 * src: migrate WriteOneByte to WriteOneByteV2 https://github.com/nodejs/node/pull/59634 * fs: introduce dirent\.parentPath https://github.com/nodejs/node/pull/50976 * src: avoid copy by using std::views::keys https://github.com/nodejs/node/pull/56080 * chore: fixup patch indices * fix: errant use of context->GetIsolate() * fix: tweak BoringSSL compat patch for new changes * fix: add back missing isolate dtor declaration * fixup! esm: fix module.exports export on CJS modules * cli: remove --no-experimental-fetch flag https://github.com/nodejs/node/pull/52611/files * esm: Source Phase Imports for WebAssembly https://github.com/nodejs/node/pull/56919 * fixup! src: prepare for v8 sandboxing * chore: bump @types/node to v24 * chore: fix const assignment in crypto test * fix: sandbox pointer patch issues * chore: rework source phase import patch * src: add percentage support to --max-old-space-size https://github.com/nodejs/node/pull/59082 * chore: fixup crypto tests * chore: HostImportModuleWithPhaseDynamically todo * fix: cjs esm failures * fix: v8::Object::Wrappable issues -b72a615754-490bac2496-4896a0dd69* chore: remove deleted specs * src: use v8::ExternalMemoryAccounter https://github.com/nodejs/node/pull/58070 * fs: port SonicBoom module to fs module as FastUtf8Stream https://github.com/nodejs/node/pull/58897 * chore: tweak sandboxed pr patch * test: disable parallel/test-os-checked-function * test: use WHATWG URL instead of url.parse * fix: OPENSSL_secure_zalloc doesn't work in BoringSSL * chore: fix accidental extra line * 7017517: [defer-import-eval] Parse import defer syntax https://chromium-review.googlesource.com/c/v8/v8/+/7017517
139 lines
5.6 KiB
Diff
139 lines
5.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samuel Attard <marshallofsound@electronjs.org>
|
|
Date: Wed, 8 Mar 2023 13:02:17 -0800
|
|
Subject: chore: expose ImportModuleDynamically and
|
|
HostInitializeImportMetaObjectCallback to embedders
|
|
|
|
This also subtly changes the behavior of shouldNotRegisterESMLoader to ensure that node sets up the handlers
|
|
internally but simply avoids setting its own handlers on the Isolate. This is so that Electron can set it to
|
|
its own blended handler between Node and Blink.
|
|
|
|
Not upstreamable.
|
|
|
|
diff --git a/lib/internal/modules/esm/utils.js b/lib/internal/modules/esm/utils.js
|
|
index 4a4279459341e87784ee8efa832dc74371c4a708..88d84786e72cf8712e0b9bda16c418d4087fe549 100644
|
|
--- a/lib/internal/modules/esm/utils.js
|
|
+++ b/lib/internal/modules/esm/utils.js
|
|
@@ -34,7 +34,7 @@ const {
|
|
ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING,
|
|
ERR_INVALID_ARG_VALUE,
|
|
} = require('internal/errors').codes;
|
|
-const { getOptionValue } = require('internal/options');
|
|
+const { getOptionValue, getEmbedderOptions } = require('internal/options');
|
|
const {
|
|
loadPreloadModules,
|
|
initializeFrozenIntrinsics,
|
|
@@ -291,12 +291,13 @@ let _forceDefaultLoader = false;
|
|
* @param {boolean} [forceDefaultLoader] - A boolean indicating disabling custom loaders.
|
|
*/
|
|
function initializeESM(forceDefaultLoader = false) {
|
|
+ const shouldSetOnIsolate = !getEmbedderOptions().shouldNotRegisterESMLoader;
|
|
_forceDefaultLoader = forceDefaultLoader;
|
|
initializeDefaultConditions();
|
|
// Setup per-realm callbacks that locate data or callbacks that we keep
|
|
// track of for different ESM modules.
|
|
- setInitializeImportMetaObjectCallback(initializeImportMetaObject);
|
|
- setImportModuleDynamicallyCallback(importModuleDynamicallyCallback);
|
|
+ setInitializeImportMetaObjectCallback(initializeImportMetaObject, shouldSetOnIsolate);
|
|
+ setImportModuleDynamicallyCallback(importModuleDynamicallyCallback, shouldSetOnIsolate);
|
|
}
|
|
|
|
/**
|
|
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
|
|
index 5783728da2894270f902f47b210008df0e911bde..8fed194cbae9ce75bd0805b4df30b4de64fbbefa 100644
|
|
--- a/src/module_wrap.cc
|
|
+++ b/src/module_wrap.cc
|
|
@@ -1097,7 +1097,7 @@ Maybe<ModuleWrap*> ModuleWrap::ResolveModule(
|
|
return Just(module_wrap);
|
|
}
|
|
|
|
-static MaybeLocal<Promise> ImportModuleDynamicallyWithPhase(
|
|
+MaybeLocal<Promise> ImportModuleDynamicallyWithPhase(
|
|
Local<Context> context,
|
|
Local<Data> host_defined_options,
|
|
Local<Value> resource_name,
|
|
@@ -1185,14 +1185,16 @@ void ModuleWrap::SetImportModuleDynamicallyCallback(
|
|
Realm* realm = Realm::GetCurrent(args);
|
|
HandleScope handle_scope(isolate);
|
|
|
|
- CHECK_EQ(args.Length(), 1);
|
|
+ CHECK_EQ(args.Length(), 2);
|
|
CHECK(args[0]->IsFunction());
|
|
Local<Function> import_callback = args[0].As<Function>();
|
|
realm->set_host_import_module_dynamically_callback(import_callback);
|
|
|
|
- isolate->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically);
|
|
- isolate->SetHostImportModuleWithPhaseDynamicallyCallback(
|
|
+ if (args[1]->IsBoolean() && args[1]->BooleanValue(isolate)) {
|
|
+ isolate->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically);
|
|
+ isolate->SetHostImportModuleWithPhaseDynamicallyCallback(
|
|
ImportModuleDynamicallyWithPhase);
|
|
+ }
|
|
}
|
|
|
|
void ModuleWrap::HostInitializeImportMetaObjectCallback(
|
|
@@ -1234,13 +1236,14 @@ void ModuleWrap::SetInitializeImportMetaObjectCallback(
|
|
Realm* realm = Realm::GetCurrent(args);
|
|
Isolate* isolate = realm->isolate();
|
|
|
|
- CHECK_EQ(args.Length(), 1);
|
|
+ CHECK_EQ(args.Length(), 2);
|
|
CHECK(args[0]->IsFunction());
|
|
Local<Function> import_meta_callback = args[0].As<Function>();
|
|
realm->set_host_initialize_import_meta_object_callback(import_meta_callback);
|
|
|
|
- isolate->SetHostInitializeImportMetaObjectCallback(
|
|
- HostInitializeImportMetaObjectCallback);
|
|
+ if (args[1]->IsBoolean() && args[1]->BooleanValue(isolate))
|
|
+ isolate->SetHostInitializeImportMetaObjectCallback(
|
|
+ HostInitializeImportMetaObjectCallback);
|
|
}
|
|
|
|
MaybeLocal<Value> ModuleWrap::SyntheticModuleEvaluationStepsCallback(
|
|
diff --git a/src/module_wrap.h b/src/module_wrap.h
|
|
index 03cf8d0e91d795aad6db9b11956d296ff4999f7e..45264c2ad58e37a73fd62addac7fb671eed6d502 100644
|
|
--- a/src/module_wrap.h
|
|
+++ b/src/module_wrap.h
|
|
@@ -8,6 +8,7 @@
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include "base_object.h"
|
|
+#include "node.h"
|
|
#include "v8-script.h"
|
|
|
|
namespace node {
|
|
@@ -92,7 +93,15 @@ struct ModuleCacheKey : public MemoryRetainer {
|
|
hash(hash) {}
|
|
};
|
|
|
|
-class ModuleWrap : public BaseObject {
|
|
+NODE_EXTERN v8::MaybeLocal<v8::Promise> ImportModuleDynamicallyWithPhase(
|
|
+ v8::Local<v8::Context> context,
|
|
+ v8::Local<v8::Data> host_defined_options,
|
|
+ v8::Local<v8::Value> resource_name,
|
|
+ v8::Local<v8::String> specifier,
|
|
+ v8::ModuleImportPhase phase,
|
|
+ v8::Local<v8::FixedArray> import_attributes);
|
|
+
|
|
+class NODE_EXTERN ModuleWrap : public BaseObject {
|
|
using ResolveCache =
|
|
std::unordered_map<ModuleCacheKey, uint32_t, ModuleCacheKey::Hash>;
|
|
|
|
@@ -157,6 +166,8 @@ class ModuleWrap : public BaseObject {
|
|
static void CreateRequiredModuleFacade(
|
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
+ static ModuleWrap* GetFromModule(node::Environment*, v8::Local<v8::Module>);
|
|
+
|
|
private:
|
|
ModuleWrap(Realm* realm,
|
|
v8::Local<v8::Object> object,
|
|
@@ -205,7 +216,6 @@ class ModuleWrap : public BaseObject {
|
|
v8::Local<v8::String> specifier,
|
|
v8::Local<v8::FixedArray> import_attributes,
|
|
v8::Local<v8::Module> referrer);
|
|
- static ModuleWrap* GetFromModule(node::Environment*, v8::Local<v8::Module>);
|
|
|
|
// This method may throw a JavaScript exception, so the return type is
|
|
// wrapped in a Maybe.
|