File tree Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -131,15 +131,18 @@ jnode.setRNode(rnode);
131
131
- [ eval] ( #eval )
132
132
- [ Parameters] ( #parameters-3 )
133
133
- [ Examples] ( #examples-1 )
134
- - [ wrap ] ( #wrap )
134
+ - [ evalAsync ] ( #evalasync )
135
135
- [ Parameters] ( #parameters-4 )
136
136
- [ Examples] ( #examples-2 )
137
- - [ RbValue] ( #rbvalue )
138
- - [ call] ( #call )
137
+ - [ wrap] ( #wrap )
139
138
- [ Parameters] ( #parameters-5 )
140
139
- [ Examples] ( #examples-3 )
141
- - [ toPrimitive] ( #toprimitive )
140
+ - [ RbValue] ( #rbvalue )
141
+ - [ call] ( #call )
142
142
- [ Parameters] ( #parameters-6 )
143
+ - [ Examples] ( #examples-4 )
144
+ - [ toPrimitive] ( #toprimitive )
145
+ - [ Parameters] ( #parameters-7 )
143
146
- [ toString] ( #tostring )
144
147
- [ toJS] ( #tojs )
145
148
- [ RbError] ( #rberror )
@@ -217,6 +220,28 @@ console.log(result.toString()); // 3
217
220
218
221
Returns ** any** the result of the last expression
219
222
223
+ #### evalAsync
224
+
225
+ Runs a string of Ruby code with top-level ` JS::Object#await `
226
+ Returns a promise that resolves when execution completes.
227
+
228
+ ##### Parameters
229
+
230
+ - ` code ` The Ruby code to run
231
+
232
+ ##### Examples
233
+
234
+ ``` javascript
235
+ const text = await vm .evalAsync (`
236
+ require 'js'
237
+ response = JS.global.fetch('https://example.com').await
238
+ response.text.await
239
+ ` );
240
+ console .log (text .toString ()); // <html>...</html>
241
+ ```
242
+
243
+ Returns ** any** a promise that resolves to the result of the last expression
244
+
220
245
#### wrap
221
246
222
247
Wrap a JavaScript value into a Ruby JS::Object
Original file line number Diff line number Diff line change @@ -225,6 +225,20 @@ export class RubyVM {
225
225
return evalRbCode ( this , this . privateObject ( ) , code ) ;
226
226
}
227
227
228
+ /**
229
+ * Runs a string of Ruby code with top-level `JS::Object#await`
230
+ * Returns a promise that resolves when execution completes.
231
+ * @param code The Ruby code to run
232
+ * @returns a promise that resolves to the result of the last expression
233
+ *
234
+ * @example
235
+ * const text = await vm.evalAsync(`
236
+ * require 'js'
237
+ * response = JS.global.fetch('https://example.com').await
238
+ * response.text.await
239
+ * `);
240
+ * console.log(text.toString()); // <html>...</html>
241
+ */
228
242
evalAsync ( code : string ) : Promise < RbValue > {
229
243
const JS = this . eval ( "require 'js'; JS" ) ;
230
244
return new Promise ( ( resolve , reject ) => {
You can’t perform that action at this time.
0 commit comments