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);
131131 - [ eval] ( #eval )
132132 - [ Parameters] ( #parameters-3 )
133133 - [ Examples] ( #examples-1 )
134- - [ wrap ] ( #wrap )
134+ - [ evalAsync ] ( #evalasync )
135135 - [ Parameters] ( #parameters-4 )
136136 - [ Examples] ( #examples-2 )
137- - [ RbValue] ( #rbvalue )
138- - [ call] ( #call )
137+ - [ wrap] ( #wrap )
139138 - [ Parameters] ( #parameters-5 )
140139 - [ Examples] ( #examples-3 )
141- - [ toPrimitive] ( #toprimitive )
140+ - [ RbValue] ( #rbvalue )
141+ - [ call] ( #call )
142142 - [ Parameters] ( #parameters-6 )
143+ - [ Examples] ( #examples-4 )
144+ - [ toPrimitive] ( #toprimitive )
145+ - [ Parameters] ( #parameters-7 )
143146 - [ toString] ( #tostring )
144147 - [ toJS] ( #tojs )
145148- [ RbError] ( #rberror )
@@ -217,6 +220,28 @@ console.log(result.toString()); // 3
217220
218221Returns ** any** the result of the last expression
219222
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+
220245#### wrap
221246
222247Wrap 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 {
225225 return evalRbCode ( this , this . privateObject ( ) , code ) ;
226226 }
227227
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+ */
228242 evalAsync ( code : string ) : Promise < RbValue > {
229243 const JS = this . eval ( "require 'js'; JS" ) ;
230244 return new Promise ( ( resolve , reject ) => {
You can’t perform that action at this time.
0 commit comments