Skip to content

Commit

Permalink
Ensure all core embind tests can run with closure. NFC (#20240)
Browse files Browse the repository at this point in the history
This change doesn't actually run them all with closure (don't want to
add too much time to CI), but I verified that they all at least do
run now.
  • Loading branch information
sbc100 authored Sep 13, 2023
1 parent c6a1b76 commit c65a321
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ var LibraryEmbind = {
},

#if WASM_BIGINT
_embind_register_bigint__docs: '/** @suppress {globalThis} */',
_embind_register_bigint__deps: [
'$embindRepr', '$readLatin1String', '$registerType', '$integerReadValueFromPointer'],
_embind_register_bigint: (primitiveType, name, size, minRange, maxRange) => {
Expand Down
12 changes: 6 additions & 6 deletions test/core/embind_lib_with_asyncify.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Module.onRuntimeInitialized = async () => {
Module['onRuntimeInitialized'] = async () => {
try {
let delayedThrowResult = Module.delayed_throw();
let delayedThrowResult = Module["delayed_throw"]();
assert(delayedThrowResult instanceof Promise);
let err = await delayedThrowResult.then(() => '', err => err.message);
assert(err === 'my message', `"${err}" doesn't contain the expected error`);

let fooResult = Module.foo();
let fooResult = Module["foo"]();
assert(fooResult instanceof Promise);
fooResult = await fooResult;
assert(fooResult === 10);

let barInstancePromise = new Module.Bar();
let barInstancePromise = new Module["Bar"]();
assert(barInstancePromise instanceof Promise);
let barInstance = await barInstancePromise;
assert(barInstance instanceof Module.Bar);
assert(barInstance instanceof Module["Bar"]);
assert(barInstance.x === 20);

let barMethodResult = barInstance.method();
Expand All @@ -27,7 +27,7 @@ Module.onRuntimeInitialized = async () => {
assert(barMethodResult instanceof Promise);
assert(await barMethodResult === undefined);

let barStaticMethodResult = Module.Bar.static_method();
let barStaticMethodResult = Module["Bar"].static_method();
assert(barStaticMethodResult instanceof Promise);
assert(await barStaticMethodResult === 50);

Expand Down
8 changes: 4 additions & 4 deletions test/core/test_embind_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ EMSCRIPTEN_BINDINGS(my_module) {
int main(int argc, char **argv) {
EM_ASM(
try {
var foo = new Module.MyFoo();
foo.doit();
var bar = new Module.MyBar();
bar.doit();
var foo = new Module['MyFoo']();
foo['doit']();
var bar = new Module['MyBar']();
bar['doit']();
} catch(e) {
out(e);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion test/core/test_embind_polymorphic_class_no_rtti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stdio.h>

EM_JS(void, calltest, (), {
var foo = new Module.Foo();
var foo = new Module["Foo"]();
console.log("foo.test() returned: " + foo.test());
foo.delete();
});
Expand Down
2 changes: 1 addition & 1 deletion test/embind/test_custom_marshal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Module.js_func = function(x) {
Module['js_func'] = function(x) {
console.log('JS got', x, typeof(x));
return 20;
}
6 changes: 3 additions & 3 deletions test/embind/test_finalization.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Module.onRuntimeInitialized = () => {
const foo1 = new Module.Foo("Constructed from JS");
const foo2 = Module.foo();
const foo3 = Module.pFoo();
const foo1 = new Module["Foo"]("Constructed from JS");
const foo2 = Module["foo"]();
const foo3 = Module["pFoo"]();
setTimeout(gc, 100);
}
1 change: 1 addition & 0 deletions test/embind/test_i64_val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int main() {
std::array<std::int64_t, 5> int64Array = {-2, -1, 0, 1, 2};

printf("start\n");
EM_ASM({globalThis.a = null});

test("val(int64_t v)");
val::global().set("a", val(int64_t(1234)));
Expand Down
11 changes: 6 additions & 5 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7637,10 +7637,11 @@ def test_embind(self, args):
})
@node_pthreads
def test_embind_2(self, args):
self.maybe_closure()
self.emcc_args += ['-lembind', '--post-js', 'post.js'] + args
create_file('post.js', '''
function printLerp() {
out('lerp ' + Module.lerp(100, 200, 66) + '.');
out('lerp ' + Module['lerp'](100, 200, 66) + '.');
}
''')
create_file('test_embind_2.cpp', r'''
Expand Down Expand Up @@ -7668,7 +7669,7 @@ def test_embind_3(self):
create_file('post.js', '''
function ready() {
try {
Module.compute(new Uint8Array([1,2,3]));
Module['compute'](new Uint8Array([1,2,3]));
} catch(e) {
out(e);
}
Expand All @@ -7695,7 +7696,7 @@ def test_embind_4(self):
self.emcc_args += ['-lembind', '--post-js', 'post.js']
create_file('post.js', '''
function printFirstElement() {
out(Module.getBufferView()[0]);
out(Module['getBufferView']()[0]);
}
''')
create_file('test_embind_4.cpp', r'''
Expand Down Expand Up @@ -7779,7 +7780,7 @@ def test_embind_no_rtti(self):
#include <stdio.h>
EM_JS(void, calltest, (), {
out("dotest returned: " + Module.dotest());
out("dotest returned: " + Module["dotest"]());
});
int main(int argc, char** argv){
Expand Down Expand Up @@ -7811,7 +7812,7 @@ def test_embind_no_rtti_followed_by_rtti(self):
#include <stdio.h>
EM_JS(void, calltest, (), {
out("dotest returned: " + Module.dotest());
out("dotest returned: " + Module["dotest"]());
});
int main(int argc, char** argv){
Expand Down

0 comments on commit c65a321

Please sign in to comment.