src: initial support for ESM in embedder API by joyeecheung · Pull Request #61548 · nodejs/node
added
c++
labels
joyeecheung
changed the title
src: add support for ESM in embedder API
src: initial support for ESM in embedder API
addaleax
added
the
semver-major
label
joyeecheung
removed
the
semver-major
label
joyeecheung
added
commit-queue
and removed commit-queue
labels
This patch extends `LoadEnvironment` to support loading ES modules,
and adds the following new types:
```cpp
enum class ModuleFormat : uint8_t {
kCommonJS,
kModule,
};
// Data for specifying an entry point script for LoadEnvironment().
// This class uses an opaque layout to allow future additions without
// breaking ABI. Use the setter methods to configure the entry point.
class ModuleData {
void set_source(std::string_view source);
void set_format(ModuleFormat format);
void set_resource_name(std::string_view name);
std::string_view source() const;
ModuleFormat format() const;
std::string_view resource_name() const;
};
class StartExecutionCallbackInfoWithModule {
void set_env(Environment* env);
void set_process_object(v8::Local<v8::Object> process_object);
void set_native_require(v8::Local<v8::Function> native_require);
void set_run_module(v8::Local<v8::Function> run_module);
void set_data(void* data);
Environment* env();
v8::Local<v8::Object> process();
v8::Local<v8::Function> native_require();
v8::Local<v8::Function> run_module();
void* data();
};
```
And two new `LoadEnvironment()` overloads:
```cpp
// Run entry point with ModuleData configuration
MaybeLocal<Value> LoadEnvironment(
Environment* env,
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);
// Callback-based with new StartExecutionCallbackInfoWithModule
MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallbackWithModule cb,
EmbedderPreloadCallback preload = nullptr,
void* callback_data = nullptr);
```
nodejs-github-bot pushed a commit that referenced this pull request
This patch extends `LoadEnvironment` to support loading ES modules,
and adds the following new types:
```cpp
enum class ModuleFormat : uint8_t {
kCommonJS,
kModule,
};
// Data for specifying an entry point script for LoadEnvironment().
// This class uses an opaque layout to allow future additions without
// breaking ABI. Use the setter methods to configure the entry point.
class ModuleData {
void set_source(std::string_view source);
void set_format(ModuleFormat format);
void set_resource_name(std::string_view name);
std::string_view source() const;
ModuleFormat format() const;
std::string_view resource_name() const;
};
class StartExecutionCallbackInfoWithModule {
void set_env(Environment* env);
void set_process_object(v8::Local<v8::Object> process_object);
void set_native_require(v8::Local<v8::Function> native_require);
void set_run_module(v8::Local<v8::Function> run_module);
void set_data(void* data);
Environment* env();
v8::Local<v8::Object> process();
v8::Local<v8::Function> native_require();
v8::Local<v8::Function> run_module();
void* data();
};
```
And two new `LoadEnvironment()` overloads:
```cpp
// Run entry point with ModuleData configuration
MaybeLocal<Value> LoadEnvironment(
Environment* env,
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);
// Callback-based with new StartExecutionCallbackInfoWithModule
MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallbackWithModule cb,
EmbedderPreloadCallback preload = nullptr,
void* callback_data = nullptr);
```
PR-URL: #61548
Refs: #53565
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
aduh95 pushed a commit that referenced this pull request
This patch extends `LoadEnvironment` to support loading ES modules,
and adds the following new types:
```cpp
enum class ModuleFormat : uint8_t {
kCommonJS,
kModule,
};
// Data for specifying an entry point script for LoadEnvironment().
// This class uses an opaque layout to allow future additions without
// breaking ABI. Use the setter methods to configure the entry point.
class ModuleData {
void set_source(std::string_view source);
void set_format(ModuleFormat format);
void set_resource_name(std::string_view name);
std::string_view source() const;
ModuleFormat format() const;
std::string_view resource_name() const;
};
class StartExecutionCallbackInfoWithModule {
void set_env(Environment* env);
void set_process_object(v8::Local<v8::Object> process_object);
void set_native_require(v8::Local<v8::Function> native_require);
void set_run_module(v8::Local<v8::Function> run_module);
void set_data(void* data);
Environment* env();
v8::Local<v8::Object> process();
v8::Local<v8::Function> native_require();
v8::Local<v8::Function> run_module();
void* data();
};
```
And two new `LoadEnvironment()` overloads:
```cpp
// Run entry point with ModuleData configuration
MaybeLocal<Value> LoadEnvironment(
Environment* env,
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);
// Callback-based with new StartExecutionCallbackInfoWithModule
MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallbackWithModule cb,
EmbedderPreloadCallback preload = nullptr,
void* callback_data = nullptr);
```
PR-URL: #61548
Refs: #53565
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
aduh95 added a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) #61415 net: * (SEMVER-MINOR) add `setTOS` and `getTOS` to `Socket` (Amol Yadav) #61503 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 * improve `TextEncoder` encode performance with `simdutf` (Mert Can Altin) #61496 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) #60426 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) #61367 url: * update Ada to v3.4.2 and support Unicode 17 (Yagiz Nizipli) #61593 PR-URL: #61635
aduh95 added a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) #61415 net: * (SEMVER-MINOR) add `setTOS` and `getTOS` to `Socket` (Amol Yadav) #61503 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 * improve `TextEncoder` encode performance with `simdutf` (Mert Can Altin) #61496 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) #60426 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) #61367 url: * update Ada to v3.4.2 and support Unicode 17 (Yagiz Nizipli) #61593 PR-URL: #61635
aduh95 added a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) #61415 net: * (SEMVER-MINOR) add `setTOS` and `getTOS` to `Socket` (Amol Yadav) #61503 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 * improve `TextEncoder` encode performance with `simdutf` (Mert Can Altin) #61496 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) #60426 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) #61367 url: * update Ada to v3.4.2 and support Unicode 17 (Yagiz Nizipli) #61593 PR-URL: #61635
aduh95 pushed a commit that referenced this pull request
This patch extends `LoadEnvironment` to support loading ES modules,
and adds the following new types:
```cpp
enum class ModuleFormat : uint8_t {
kCommonJS,
kModule,
};
// Data for specifying an entry point script for LoadEnvironment().
// This class uses an opaque layout to allow future additions without
// breaking ABI. Use the setter methods to configure the entry point.
class ModuleData {
void set_source(std::string_view source);
void set_format(ModuleFormat format);
void set_resource_name(std::string_view name);
std::string_view source() const;
ModuleFormat format() const;
std::string_view resource_name() const;
};
class StartExecutionCallbackInfoWithModule {
void set_env(Environment* env);
void set_process_object(v8::Local<v8::Object> process_object);
void set_native_require(v8::Local<v8::Function> native_require);
void set_run_module(v8::Local<v8::Function> run_module);
void set_data(void* data);
Environment* env();
v8::Local<v8::Object> process();
v8::Local<v8::Function> native_require();
v8::Local<v8::Function> run_module();
void* data();
};
```
And two new `LoadEnvironment()` overloads:
```cpp
// Run entry point with ModuleData configuration
MaybeLocal<Value> LoadEnvironment(
Environment* env,
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);
// Callback-based with new StartExecutionCallbackInfoWithModule
MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallbackWithModule cb,
EmbedderPreloadCallback preload = nullptr,
void* callback_data = nullptr);
```
PR-URL: #61548
Refs: #53565
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
aduh95 pushed a commit that referenced this pull request
This patch extends `LoadEnvironment` to support loading ES modules,
and adds the following new types:
```cpp
enum class ModuleFormat : uint8_t {
kCommonJS,
kModule,
};
// Data for specifying an entry point script for LoadEnvironment().
// This class uses an opaque layout to allow future additions without
// breaking ABI. Use the setter methods to configure the entry point.
class ModuleData {
void set_source(std::string_view source);
void set_format(ModuleFormat format);
void set_resource_name(std::string_view name);
std::string_view source() const;
ModuleFormat format() const;
std::string_view resource_name() const;
};
class StartExecutionCallbackInfoWithModule {
void set_env(Environment* env);
void set_process_object(v8::Local<v8::Object> process_object);
void set_native_require(v8::Local<v8::Function> native_require);
void set_run_module(v8::Local<v8::Function> run_module);
void set_data(void* data);
Environment* env();
v8::Local<v8::Object> process();
v8::Local<v8::Function> native_require();
v8::Local<v8::Function> run_module();
void* data();
};
```
And two new `LoadEnvironment()` overloads:
```cpp
// Run entry point with ModuleData configuration
MaybeLocal<Value> LoadEnvironment(
Environment* env,
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);
// Callback-based with new StartExecutionCallbackInfoWithModule
MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallbackWithModule cb,
EmbedderPreloadCallback preload = nullptr,
void* callback_data = nullptr);
```
PR-URL: #61548
Refs: #53565
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
nodejs-github-bot added a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add trackPromises option to createHook() (Joyee Cheung) #61415 build,deps: * replace cjs-module-lexer with merve (Yagiz Nizipli) #61456 deps: * (SEMVER-MINOR) add LIEF as a dependency (Joyee Cheung) #61167 * (SEMVER-MINOR) add tools and scripts to pull LIEF as a dependency (Joyee Cheung) #61167 events: * (SEMVER-MINOR) repurpose `events.listenerCount()` to accept EventTargets (René) #60214 fs: * (SEMVER-MINOR) add ignore option to fs.watch (Matteo Collina) #61433 http: * (SEMVER-MINOR) add http.setGlobalProxyFromEnv() (Joyee Cheung) #60953 module: * (SEMVER-MINOR) allow subpath imports that start with `#/` (Jan Martin) #60864 process: * (SEMVER-MINOR) preserve AsyncLocalStorage in queueMicrotask only when needed (Gürgün Dayıoğlu) #60913 sea: * (SEMVER-MINOR) split sea binary manipulation code (Joyee Cheung) #61167 sqlite: * (SEMVER-MINOR) enable defensive mode by default (Bart Louwers) #61266 * (SEMVER-MINOR) add sqlite prepare options args (Guilherme Araújo) #61311 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 stream: * (SEMVER-MINOR) add bytes() method to stream/consumers (wantaek) #60426 * (SEMVER-MINOR) do not pass `readable.compose()` output via `Readable.from()` (René) #60907 test: * (SEMVER-MINOR) use fixture directories for sea tests (Joyee Cheung) #61167 test_runner: * (SEMVER-MINOR) add env option to run function (Ethan Arrowood) #61367 * (SEMVER-MINOR) support expecting a test-case to fail (Jacob Smith) #60669 util: * (SEMVER-MINOR) add convertProcessSignalToExitCode utility (Erick Wendel) #60963 PR-URL: #61924
aduh95 pushed a commit that referenced this pull request
This patch extends `LoadEnvironment` to support loading ES modules,
and adds the following new types:
```cpp
enum class ModuleFormat : uint8_t {
kCommonJS,
kModule,
};
// Data for specifying an entry point script for LoadEnvironment().
// This class uses an opaque layout to allow future additions without
// breaking ABI. Use the setter methods to configure the entry point.
class ModuleData {
void set_source(std::string_view source);
void set_format(ModuleFormat format);
void set_resource_name(std::string_view name);
std::string_view source() const;
ModuleFormat format() const;
std::string_view resource_name() const;
};
class StartExecutionCallbackInfoWithModule {
void set_env(Environment* env);
void set_process_object(v8::Local<v8::Object> process_object);
void set_native_require(v8::Local<v8::Function> native_require);
void set_run_module(v8::Local<v8::Function> run_module);
void set_data(void* data);
Environment* env();
v8::Local<v8::Object> process();
v8::Local<v8::Function> native_require();
v8::Local<v8::Function> run_module();
void* data();
};
```
And two new `LoadEnvironment()` overloads:
```cpp
// Run entry point with ModuleData configuration
MaybeLocal<Value> LoadEnvironment(
Environment* env,
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);
// Callback-based with new StartExecutionCallbackInfoWithModule
MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallbackWithModule cb,
EmbedderPreloadCallback preload = nullptr,
void* callback_data = nullptr);
```
PR-URL: #61548
Refs: #53565
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
aduh95 added a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) #61415 build,deps: * replace cjs-module-lexer with merve (Yagiz Nizipli) #61456 deps: * (SEMVER-MINOR) add LIEF as a dependency (Joyee Cheung) #61167 events: * (SEMVER-MINOR) repurpose `events.listenerCount()` to accept `EventTarget`s (René) #60214 fs: * (SEMVER-MINOR) add `ignore` option to `fs.watch` (Matteo Collina) #61433 http: * (SEMVER-MINOR) add `http.setGlobalProxyFromEnv()` (Joyee Cheung) #60953 module: * (SEMVER-MINOR) allow subpath imports that start with `#/` (Jan Martin) #60864 process: * (SEMVER-MINOR) preserve `AsyncLocalStorage` in `queueMicrotask` only when needed (Gürgün Dayıoğlu) #60913 sea: * (SEMVER-MINOR) split sea binary manipulation code (Joyee Cheung) #61167 sqlite: * (SEMVER-MINOR) enable defensive mode by default (Bart Louwers) #61266 * (SEMVER-MINOR) add sqlite prepare options args (Guilherme Araújo) #61311 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) #60426 * (SEMVER-MINOR) do not pass `readable.compose()` output via `Readable.from()` (René) #60907 test: * (SEMVER-MINOR) use fixture directories for sea tests (Joyee Cheung) #61167 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) #61367 * (SEMVER-MINOR) support expecting a test-case to fail (Jacob Smith) #60669 util: * (SEMVER-MINOR) add `convertProcessSignalToExitCode` utility (Erick Wendel) #60963 PR-URL: #61924
aduh95 added a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) #61415 build,deps: * replace cjs-module-lexer with merve (Yagiz Nizipli) #61456 deps: * (SEMVER-MINOR) add LIEF as a dependency (Joyee Cheung) #61167 events: * (SEMVER-MINOR) repurpose `events.listenerCount()` to accept `EventTarget`s (René) #60214 fs: * (SEMVER-MINOR) add `ignore` option to `fs.watch` (Matteo Collina) #61433 http: * (SEMVER-MINOR) add `http.setGlobalProxyFromEnv()` (Joyee Cheung) #60953 module: * (SEMVER-MINOR) allow subpath imports that start with `#/` (Jan Martin) #60864 process: * (SEMVER-MINOR) preserve `AsyncLocalStorage` in `queueMicrotask` only when needed (Gürgün Dayıoğlu) #60913 sea: * (SEMVER-MINOR) split sea binary manipulation code (Joyee Cheung) #61167 sqlite: * (SEMVER-MINOR) enable defensive mode by default (Bart Louwers) #61266 * (SEMVER-MINOR) add sqlite prepare options args (Guilherme Araújo) #61311 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) #60426 * (SEMVER-MINOR) do not pass `readable.compose()` output via `Readable.from()` (René) #60907 test: * (SEMVER-MINOR) use fixture directories for sea tests (Joyee Cheung) #61167 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) #61367 * (SEMVER-MINOR) support expecting a test-case to fail (Jacob Smith) #60669 util: * (SEMVER-MINOR) add `convertProcessSignalToExitCode` utility (Erick Wendel) #60963 PR-URL: #61924
aduh95 added a commit to aduh95/node that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) nodejs#61415 build,deps: * replace cjs-module-lexer with merve (Yagiz Nizipli) nodejs#61456 deps: * (SEMVER-MINOR) add LIEF as a dependency (Joyee Cheung) nodejs#61167 events: * (SEMVER-MINOR) repurpose `events.listenerCount()` to accept `EventTarget`s (René) nodejs#60214 fs: * (SEMVER-MINOR) add `ignore` option to `fs.watch` (Matteo Collina) nodejs#61433 http: * (SEMVER-MINOR) add `http.setGlobalProxyFromEnv()` (Joyee Cheung) nodejs#60953 module: * (SEMVER-MINOR) allow subpath imports that start with `#/` (Jan Martin) nodejs#60864 process: * (SEMVER-MINOR) preserve `AsyncLocalStorage` in `queueMicrotask` only when needed (Gürgün Dayıoğlu) nodejs#60913 sea: * (SEMVER-MINOR) split sea binary manipulation code (Joyee Cheung) nodejs#61167 sqlite: * (SEMVER-MINOR) enable defensive mode by default (Bart Louwers) nodejs#61266 * (SEMVER-MINOR) add sqlite prepare options args (Guilherme Araújo) nodejs#61311 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) nodejs#61548 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) nodejs#60426 * (SEMVER-MINOR) do not pass `readable.compose()` output via `Readable.from()` (René) nodejs#60907 test: * (SEMVER-MINOR) use fixture directories for sea tests (Joyee Cheung) nodejs#61167 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) nodejs#61367 * (SEMVER-MINOR) support expecting a test-case to fail (Jacob Smith) nodejs#60669 util: * (SEMVER-MINOR) add `convertProcessSignalToExitCode` utility (Erick Wendel) nodejs#60963 PR-URL: nodejs#61924
ruyadorno pushed a commit that referenced this pull request
Notable changes: async_hooks: * (SEMVER-MINOR) add `trackPromises` option to `createHook()` (Joyee Cheung) #61415 build,deps: * replace cjs-module-lexer with merve (Yagiz Nizipli) #61456 deps: * (SEMVER-MINOR) add LIEF as a dependency (Joyee Cheung) #61167 events: * (SEMVER-MINOR) repurpose `events.listenerCount()` to accept `EventTarget`s (René) #60214 fs: * (SEMVER-MINOR) add `ignore` option to `fs.watch` (Matteo Collina) #61433 http: * (SEMVER-MINOR) add `http.setGlobalProxyFromEnv()` (Joyee Cheung) #60953 module: * (SEMVER-MINOR) allow subpath imports that start with `#/` (Jan Martin) #60864 process: * (SEMVER-MINOR) preserve `AsyncLocalStorage` in `queueMicrotask` only when needed (Gürgün Dayıoğlu) #60913 sea: * (SEMVER-MINOR) split sea binary manipulation code (Joyee Cheung) #61167 sqlite: * (SEMVER-MINOR) enable defensive mode by default (Bart Louwers) #61266 * (SEMVER-MINOR) add sqlite prepare options args (Guilherme Araújo) #61311 src: * (SEMVER-MINOR) add initial support for ESM in embedder API (Joyee Cheung) #61548 stream: * (SEMVER-MINOR) add `bytes()` method to `node:stream/consumers` (wantaek) #60426 * (SEMVER-MINOR) do not pass `readable.compose()` output via `Readable.from()` (René) #60907 test: * (SEMVER-MINOR) use fixture directories for sea tests (Joyee Cheung) #61167 test_runner: * (SEMVER-MINOR) add `env` option to `run` function (Ethan Arrowood) #61367 * (SEMVER-MINOR) support expecting a test-case to fail (Jacob Smith) #60669 util: * (SEMVER-MINOR) add `convertProcessSignalToExitCode` utility (Erick Wendel) #60963 PR-URL: #61924