Closed Webifi closed 3 years ago
Immediate anonymous function Invocation seems to fail after async function.
Instantiate new interpreter with:
const interpreter = new Interpreter('', (interpreter, globalObject) => { // Add async function as test interpreter.setProperty( globalObject, 'testAsync', interpreter.createAsyncFunction((value, time, callback) => { // Return value after delay setTimeout(() => { callback(value) interpreter.run() }, time) }), Interpreter.NONENUMERABLE_DESCRIPTOR ) })
This will fail with "Uncaught TypeError: Test delay 1 is not a function"
interpreter.appendCode(` testAsync('Test delay 1', 1000) (function () { testAsync('Test delay 2', 1000) }()) `) interpreter.run()
This will work:
interpreter.appendCode(` testAsync('Test delay 1', 1000) var testFunc = function () { testAsync('Test delay 2', 1000) } testFunc() `) interpreter.run()
interpreter.appendCode(` (function () { testAsync('Test delay 2', 1000) }()) `) interpreter.run()
Never mind. Simply missing an ";"
Immediate anonymous function Invocation seems to fail after async function.
Instantiate new interpreter with:
This will fail with "Uncaught TypeError: Test delay 1 is not a function"
This will work:
This will work: