Skip to content

Commit 74bce44

Browse files
committed
propagate doc rebuild
1 parent 112a6b6 commit 74bce44

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

doc/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ context.dispose()
173173
runtime.dispose()
174174
```
175175

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+
176199
### Memory Management
177200

178201
Many methods in this library return handles to memory allocated inside the

doc/quickjs-emscripten/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,29 @@ context.dispose()
193193
runtime.dispose()
194194
```
195195

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+
196219
### Memory Management
197220

198221
Many methods in this library return handles to memory allocated inside the

0 commit comments

Comments
 (0)