Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to Rhino's NativePromise #443

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/org/ringojs/engine/RingoGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ public static Object spawn(Context cx, Scriptable thisObj,
public Object call() {
return cxfactory.call(new ContextAction<Object>() {
public Object run(Context cx) {
return function.call(cx, scope, scope, fnArgs);
Object result = function.call(cx, scope, scope, fnArgs);
cx.processMicrotasks();
return result;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/org/ringojs/engine/RingoWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public Object invoke(Object module, Object function, Object... args)
}
} finally {
releaseWorker(previous);
cx.processMicrotasks();
Context.exit();
}
}
Expand Down
1 change: 1 addition & 0 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.testBinary = require('./binary/all');
exports.testRepository = require('./repository/all');
exports.testIo = require('./io_test');
exports.testModules = require('./modules/all');
exports.testRhino = require("./rhino/all");

// Also include integration tests
exports.testIntegration = require('./integration-tests/all');
Expand Down
4 changes: 4 additions & 0 deletions test/rhino/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports.testArrowFunctions = require("./arrow_functions");
exports.testConstStatement = require("./const_statement");
exports.testLetStatement = require("./let_statement");
exports.testPromise = require("./promise_test");
22 changes: 22 additions & 0 deletions test/rhino/promise_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const assert = require("assert");
const {Semaphore} = require("ringo/concurrent");

exports.testResolve = () => {
const semaphore = new Semaphore();
let expected = false;
spawn(() => {
return new Promise(resolve => {
java.lang.Thread.sleep(100);
resolve(true);
}).then(value => {
expected = value;
semaphore.signal();
});
});
semaphore.tryWait(150);
assert.isTrue(expected);
};

if (require.main === module) {
require("system").exit(require("test").run(module.id));
}