I am struggling to get this to work. Once i add an async API callback the
browser locks up to a point where i need to kill it.
I have reduced my setup to the minimal example below. The "run" button is
supposed to run the code "test();" in the JS Interpreter. This should then
wait for the event. And the "event" button is supposed to send that event. The
handler should then call callback with the value 42 from the event and the
Interpreter is supposed to finish processing. At least that's what i was hoping
for.
But once the API callback is invoked the browser becomes unresponsible. I
cannot even reload the page nor can i click the "event" button.
Regards,
Till
<!DOCTYPE html>
<html>
<head>
<script src="./acorn_interpreter.js"></script>
</head>
<body>
<button onclick="run()">JavaScript</button>
<button onclick="window.dispatchEvent(new CustomEvent('my_event', { detail:
42 }));">Event</button>
<script>
var initInterpreter = function(interpreter, scope) {
var wrapper = function(callback) {
console.log("test api called");
window.addEventListener('my_event', function (e) {
console.log("EVENT!!!"); callback(e.detail); }, false);
};
interpreter.setProperty(scope, 'test',
interpreter.createAsyncFunction(wrapper));
}
function run() {
var interpreter = new Interpreter('test();', initInterpreter);
do { go = interpreter.step(); } while(go);
console.log("DONE");
}
</script>
</body>
</html>