Commit dce6570
src: add initial support for ESM in embedder API
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>1 parent 4cf94fa commit dce6570Copy full SHA for dce6570
10 files changed
+502-58Lines changed: 502 additions & 58 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- lib/internal/main
- src
- api
- test
- cctest
- fixtures/sea/use-code-cache
Expand file treeCollapse file tree
Open diff view settings
Collapse file
lib/internal/main/embedding.js
Copy file name to clipboardExpand all lines: lib/internal/main/embedding.js+80-17Lines changed: 80 additions & 17 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | | - |
| 18 | + |
| 19 | + |
19 | 20 | |
20 | 21 | |
21 | 22 | |
22 | | - |
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | | - |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
27 | 31 | |
28 | 32 | |
29 | 33 | |
| ||
44 | 48 | |
45 | 49 | |
46 | 50 | |
47 | | - |
| 51 | + |
48 | 52 | |
49 | 53 | |
50 | 54 | |
51 | 55 | |
52 | | - |
53 | 56 | |
54 | 57 | |
55 | 58 | |
| ||
86 | 89 | |
87 | 90 | |
88 | 91 | |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
89 | 97 | |
90 | 98 | |
91 | 99 | |
92 | 100 | |
93 | | - |
| 101 | + |
94 | 102 | |
95 | 103 | |
96 | 104 | |
97 | 105 | |
98 | 106 | |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
99 | 119 | |
100 | 120 | |
101 | 121 | |
| 122 | + |
102 | 123 | |
103 | | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | | - |
| 124 | + |
113 | 125 | |
114 | 126 | |
115 | 127 | |
116 | 128 | |
117 | 129 | |
118 | | - |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
Collapse file
+138-11Lines changed: 138 additions & 11 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
574 | 574 | |
575 | 575 | |
576 | 576 | |
577 | | - |
| 577 | + |
578 | 578 | |
579 | 579 | |
580 | 580 | |
| ||
586 | 586 | |
587 | 587 | |
588 | 588 | |
| 589 | + |
| 590 | + |
| 591 | + |
| 592 | + |
| 593 | + |
| 594 | + |
| 595 | + |
| 596 | + |
| 597 | + |
| 598 | + |
| 599 | + |
| 600 | + |
| 601 | + |
| 602 | + |
| 603 | + |
| 604 | + |
| 605 | + |
| 606 | + |
| 607 | + |
| 608 | + |
| 609 | + |
| 610 | + |
| 611 | + |
| 612 | + |
| 613 | + |
| 614 | + |
| 615 | + |
| 616 | + |
| 617 | + |
| 618 | + |
| 619 | + |
| 620 | + |
| 621 | + |
| 622 | + |
| 623 | + |
| 624 | + |
| 625 | + |
| 626 | + |
| 627 | + |
| 628 | + |
| 629 | + |
| 630 | + |
| 631 | + |
| 632 | + |
| 633 | + |
| 634 | + |
| 635 | + |
| 636 | + |
| 637 | + |
| 638 | + |
| 639 | + |
| 640 | + |
| 641 | + |
| 642 | + |
| 643 | + |
| 644 | + |
| 645 | + |
| 646 | + |
| 647 | + |
| 648 | + |
| 649 | + |
| 650 | + |
| 651 | + |
| 652 | + |
| 653 | + |
| 654 | + |
| 655 | + |
| 656 | + |
| 657 | + |
| 658 | + |
| 659 | + |
| 660 | + |
| 661 | + |
| 662 | + |
| 663 | + |
| 664 | + |
| 665 | + |
| 666 | + |
| 667 | + |
| 668 | + |
| 669 | + |
| 670 | + |
| 671 | + |
| 672 | + |
| 673 | + |
| 674 | + |
| 675 | + |
| 676 | + |
| 677 | + |
| 678 | + |
| 679 | + |
| 680 | + |
| 681 | + |
| 682 | + |
| 683 | + |
| 684 | + |
| 685 | + |
| 686 | + |
| 687 | + |
| 688 | + |
| 689 | + |
| 690 | + |
| 691 | + |
| 692 | + |
| 693 | + |
| 694 | + |
| 695 | + |
| 696 | + |
| 697 | + |
| 698 | + |
| 699 | + |
| 700 | + |
589 | 701 | |
590 | 702 | |
591 | 703 | |
| 704 | + |
| 705 | + |
| 706 | + |
| 707 | + |
| 708 | + |
| 709 | + |
| 710 | + |
| 711 | + |
| 712 | + |
| 713 | + |
592 | 714 | |
593 | | - |
594 | | - |
| 715 | + |
595 | 716 | |
596 | 717 | |
597 | | - |
598 | | - |
599 | | - |
600 | | - |
601 | | - |
602 | | - |
603 | | - |
604 | | - |
| 718 | + |
| 719 | + |
| 720 | + |
| 721 | + |
| 722 | + |
| 723 | + |
| 724 | + |
| 725 | + |
| 726 | + |
| 727 | + |
| 728 | + |
| 729 | + |
| 730 | + |
| 731 | + |
605 | 732 | |
606 | 733 | |
607 | 734 | |
|
Collapse file
+18-22Lines changed: 18 additions & 22 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
255 | 255 | |
256 | 256 | |
257 | 257 | |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
262 | 262 | |
263 | 263 | |
264 | 264 | |
265 | | - |
| 265 | + |
| 266 | + |
266 | 267 | |
267 | 268 | |
268 | | - |
| 269 | + |
269 | 270 | |
270 | 271 | |
271 | 272 | |
272 | 273 | |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | | - |
282 | | - |
283 | | - |
284 | | - |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
285 | 280 | |
286 | 281 | |
287 | 282 | |
288 | | - |
| 283 | + |
| 284 | + |
289 | 285 | |
290 | 286 | |
291 | 287 | |
| ||
294 | 290 | |
295 | 291 | |
296 | 292 | |
297 | | - |
| 293 | + |
298 | 294 | |
299 | 295 | |
300 | 296 | |
| ||
308 | 304 | |
309 | 305 | |
310 | 306 | |
311 | | - |
| 307 | + |
312 | 308 | |
313 | | - |
| 309 | + |
314 | 310 | |
315 | 311 | |
316 | 312 | |
|
0 commit comments