Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
[Web] add missing function test
Browse files Browse the repository at this point in the history
  • Loading branch information
nokotan committed Apr 25, 2024
1 parent d9c4e4b commit 8db91c7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 69 deletions.
5 changes: 0 additions & 5 deletions Siv3D/lib/Web/jslib/Siv3D.pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ Please use another browser that supports WebAssembly.")
{
onAbort(e);
}
// Test stub: throw JSException instead of abort.
// else if (typeof e === "string" && e !== "" && e !== "native code called abort()")
// {
// Module["siv3dSetThrowJSException"](e);
// }
};
})();
77 changes: 13 additions & 64 deletions Test/Siv3DTest.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
//
// Mock implementation for Node.js
//

Module.preRun = [
function ()
// Test stub: throw JSException instead of abort.
Module["onAbort"] = function(e) {
if ((e !== "" && e !== "native code called abort()"))
{
FS.mkdir('/test');
FS.mount(NODEFS, { root: '../../../Test/test' }, '/test');

FS.mkdir('/resources');
FS.mount(NODEFS, { root: '../../App/resources' }, '/resources');

//
// Mock Implementations
//
global.navigator = {
getGamepads() { return []; }
};

global.window = {
alert(text) { console.error(text); },
addEventListener() {},
removeEventListener() {},
speechSynthesis: {
getVoices() { return []; }
},
screen: {}
};

global.document = {
createElement() {
return {
style: {},
addEventListener() {},
removeEventListener() {},
};
},
};

Module.canvas = {
style: {
removeProperty() {}
},
parentNode: {
prepend() {}
},
addEventListener() {},
removeEventListener() {},
};

global.FileReader = class {
constructor() {}
};

global.Notification = {
permission: "granted",
requestPermission() {}
};

global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
Module["siv3dSetThrowJSException"](e);
}

global.requestAnimationFrame = function(callback) {
setTimeout(callback, 16);
};
if (e === -1) {
// FIXME: -1 is thrown when unresolved function is called in emscripten 3.1.20.
// We should migrate to emscripten 3.1.53, in which unresolved symbol report will be thrown.
//
// abort(-1); // emscripten 3.1.20, not user friendly abort
// abort("missing function: <some function name>"); // emscripten 3.1.53
Module["siv3dSetThrowJSException"](e.toString());
}
];
};
12 changes: 12 additions & 0 deletions Test/Siv3DTest_DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ TEST_CASE("DLL")
REQUIRE_THROWS_MATCHES(DLL::Load(U"libsub.so"), s3d::EngineError, EngineErrorMatcher(U"To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking"));
}

SECTION("Undefined Symbol")
{
extern void NonExistentFunction();

// FIXME: -1 is thrown when unresolved function is called in emscripten 3.1.20.
// We should migrate to emscripten 3.1.53, in which unresolved symbol report will be thrown.
//
// abort(-1); // emscripten 3.1.20, not user friendly abort
// abort("missing function: _Z19NonExistentFunctionv"); // emscripten 3.1.53
REQUIRE_THROWS_MATCHES(NonExistentFunction(), s3d::EngineError, EngineErrorMatcher(U"-1"));
}

# else

SECTION("Existent Module")
Expand Down
2 changes: 2 additions & 0 deletions Web/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ target_link_options(Siv3DTest PRIVATE
-g2
-fexceptions
-sASYNCIFY=1
--pre-js=${PROJECT_SOURCE_DIR}/../Test/Siv3DTest.js
--preload-file=${PROJECT_SOURCE_DIR}/../Test/test@/test
--preload-file=${PROJECT_SOURCE_DIR}/App/resources@/resources
--preload-file=${PROJECT_SOURCE_DIR}/App/example@/example
Expand Down Expand Up @@ -1645,6 +1646,7 @@ target_link_options(Siv3DUnitTest PRIVATE
--emrun
-fexceptions
-sASYNCIFY=1
--pre-js=${PROJECT_SOURCE_DIR}/../Test/Siv3DTest.js
--preload-file=${PROJECT_SOURCE_DIR}/../Test/test@/test
--preload-file=${PROJECT_SOURCE_DIR}/App/resources@/resources
--preload-file=${PROJECT_SOURCE_DIR}/App/example@/example
Expand Down

0 comments on commit 8db91c7

Please sign in to comment.