@@ -8,22 +8,22 @@ C by Fabrice Bellard](https://bellard.org/quickjs/) compiled to WebAssembly.
8
8
- Expose host functions to the QuickJS runtime.
9
9
10
10
``` typescript
11
- import { getQuickJS } from ' quickjs-emscripten'
11
+ import { getQuickJS } from " quickjs-emscripten"
12
12
13
13
async function main() {
14
14
const QuickJS = await getQuickJS ()
15
15
const vm = QuickJS .createVm ()
16
16
17
- const world = vm .newString (' world' )
18
- vm .setProp (vm .global , ' NAME' , world )
17
+ const world = vm .newString (" world" )
18
+ vm .setProp (vm .global , " NAME" , world )
19
19
world .dispose ()
20
20
21
21
const result = vm .evalCode (` "Hello " + NAME + "!" ` )
22
22
if (result .error ) {
23
- console .log (' Execution failed:' , vm .dump (result .error ))
23
+ console .log (" Execution failed:" , vm .dump (result .error ))
24
24
result .error .dispose ()
25
25
} else {
26
- console .log (' Success:' , vm .dump (result .value ))
26
+ console .log (" Success:" , vm .dump (result .value ))
27
27
result .value .dispose ()
28
28
}
29
29
@@ -49,10 +49,10 @@ function to directly access the singleton engine in your synchronous code.
49
49
See [ QuickJS.evalCode] ( https://github.com/justjake/quickjs-emscripten/blob/master/doc/classes/quickjs.md#evalcode )
50
50
51
51
``` typescript
52
- import { getQuickJS , shouldInterruptAfterDeadline } from ' quickjs-emscripten'
52
+ import { getQuickJS , shouldInterruptAfterDeadline } from " quickjs-emscripten"
53
53
54
- getQuickJS ().then (QuickJS => {
55
- const result = QuickJS .evalCode (' 1 + 1' , {
54
+ getQuickJS ().then (( QuickJS ) => {
55
+ const result = QuickJS .evalCode (" 1 + 1" , {
56
56
shouldInterrupt: shouldInterruptAfterDeadline (Date .now () + 1000 ),
57
57
memoryLimitBytes: 1024 * 1024 ,
58
58
})
@@ -73,15 +73,15 @@ limit. See the documentation for details.
73
73
const vm = QuickJS .createVm ()
74
74
let state = 0
75
75
76
- const fnHandle = vm .newFunction (' nextId' , () => {
76
+ const fnHandle = vm .newFunction (" nextId" , () => {
77
77
return vm .newNumber (++ state )
78
78
})
79
79
80
- vm .setProp (vm .global , ' nextId' , fnHandle )
80
+ vm .setProp (vm .global , " nextId" , fnHandle )
81
81
fnHandle .dispose ()
82
82
83
83
const nextId = vm .unwrapResult (vm .evalCode (` nextId(); nextId(); nextId() ` ))
84
- console .log (' vm result:' , vm .getNumber (nextId ), ' native state:' , state )
84
+ console .log (" vm result:" , vm .getNumber (nextId ), " native state:" , state )
85
85
86
86
nextId .dispose ()
87
87
vm .dispose ()
@@ -121,20 +121,20 @@ method in the reverse order in which they're added to the scope. Here's the
121
121
"Interfacing with the interpreter" example re-written using ` Scope ` :
122
122
123
123
``` typescript
124
- Scope .withScope (scope => {
124
+ Scope .withScope (( scope ) => {
125
125
const vm = scope .manage (QuickJS .createVm ())
126
126
let state = 0
127
127
128
128
const fnHandle = scope .manage (
129
- vm .newFunction (' nextId' , () => {
129
+ vm .newFunction (" nextId" , () => {
130
130
return vm .newNumber (++ state )
131
131
})
132
132
)
133
133
134
- vm .setProp (vm .global , ' nextId' , fnHandle )
134
+ vm .setProp (vm .global , " nextId" , fnHandle )
135
135
136
136
const nextId = scope .manage (vm .unwrapResult (vm .evalCode (` nextId(); nextId(); nextId() ` )))
137
- console .log (' vm result:' , vm .getNumber (nextId ), ' native state:' , state )
137
+ console .log (" vm result:" , vm .getNumber (nextId ), " native state:" , state )
138
138
139
139
// When the withScope block exits, it calls scope.dispose(), which in turn calls
140
140
// the .dispose() methods of all the disposables managed by the scope.
@@ -158,12 +158,12 @@ Here's the "Interfacing with interpreter" example re-written using `.consume()`:
158
158
const vm = QuickJS .createVm ()
159
159
let state = 0
160
160
161
- vm .newFunction (' nextId' , () => {
161
+ vm .newFunction (" nextId" , () => {
162
162
return vm .newNumber (++ state )
163
- }).consume (fnHandle => vm .setProp (vm .global , ' nextId' , fnHandle ))
163
+ }).consume (( fnHandle ) => vm .setProp (vm .global , " nextId" , fnHandle ))
164
164
165
- vm .unwrapResult (vm .evalCode (` nextId(); nextId(); nextId() ` )).consume (nextId =>
166
- console .log (' vm result:' , vm .getNumber (nextId ), ' native state:' , state )
165
+ vm .unwrapResult (vm .evalCode (` nextId(); nextId(); nextId() ` )).consume (( nextId ) =>
166
+ console .log (" vm result:" , vm .getNumber (nextId ), " native state:" , state )
167
167
)
168
168
169
169
vm .dispose ()
0 commit comments