-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
src: initial support for ESM in embedder API #61548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
|
cc @nodejs/embedders |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61548 +/- ##
========================================
Coverage 89.78% 89.78%
========================================
Files 672 672
Lines 203809 203916 +107
Branches 39183 39182 -1
========================================
+ Hits 182980 183077 +97
- Misses 13166 13183 +17
+ Partials 7663 7656 -7
🚀 New features to boost your workflow:
|
|
I don't think this is semver-major - notice none of the existing tests need updating, as the new overloads are backward compatible. (I would be worth at some point deprecating the older overloads, maybe before March for 26, because the older types are prone to ABI breakage whenever we try to add more features, but that can be a separate PR). |
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);
```
|
hmm, noticed that I accidentally changed the original overloads - updated to remove the changes. This should be now fully backward compatible. |
This patch extends
LoadEnvironmentto support loading ES modules, and adds the following new types:And two new
LoadEnvironment()overloads:Notes about the
run_modulefunction:run_cjsfunction is renamed torun_moduleand now acceptsthree arguments:
(source, format, resourceName)where formatcorresponds to
ModuleFormatvalues. This keeps the oldStartExecutionCallbackbackward-compatible, and reuses this newfunction for
StartExecutionCallbackWithModule.points continue to return the wrapper's return value.
The following are left as TODO for follow-up PRs.
import()andimport.metaRefs: #53565