File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,29 @@ context.dispose()
173
173
runtime .dispose ()
174
174
```
175
175
176
+ #### EcmaScript Module Exports
177
+
178
+ When you evaluate code as an ES Module, the result will be a handle to the
179
+ module's exports, or a handle to a promise that resolves to the module's
180
+ exports if the module depends on a top-level await.
181
+
182
+ ``` typescript
183
+ const context = QuickJS .newContext ()
184
+ const result = context .evalCode (
185
+ `
186
+ export const name = 'Jake'
187
+ export const favoriteBean = 'wax bean'
188
+ export default 'potato'
189
+ ` ,
190
+ " jake.js" ,
191
+ { type: " module" },
192
+ )
193
+ const moduleExports = context .unwrapResult (result )
194
+ console .log (context .dump (moduleExports ))
195
+ // -> { name: 'Jake', favoriteBean: 'wax bean', default: 'potato' }
196
+ moduleExports .dispose ()
197
+ ```
198
+
176
199
### Memory Management
177
200
178
201
Many methods in this library return handles to memory allocated inside the
Original file line number Diff line number Diff line change @@ -193,6 +193,29 @@ context.dispose()
193
193
runtime .dispose ()
194
194
```
195
195
196
+ #### EcmaScript Module Exports
197
+
198
+ When you evaluate code as an ES Module, the result will be a handle to the
199
+ module's exports, or a handle to a promise that resolves to the module's
200
+ exports if the module depends on a top-level await.
201
+
202
+ ``` typescript
203
+ const context = QuickJS .newContext ()
204
+ const result = context .evalCode (
205
+ `
206
+ export const name = 'Jake'
207
+ export const favoriteBean = 'wax bean'
208
+ export default 'potato'
209
+ ` ,
210
+ " jake.js" ,
211
+ { type: " module" },
212
+ )
213
+ const moduleExports = context .unwrapResult (result )
214
+ console .log (context .dump (moduleExports ))
215
+ // -> { name: 'Jake', favoriteBean: 'wax bean', default: 'potato' }
216
+ moduleExports .dispose ()
217
+ ```
218
+
196
219
### Memory Management
197
220
198
221
Many methods in this library return handles to memory allocated inside the
You can’t perform that action at this time.
0 commit comments