Skip to content

Commit 49c8f48

Browse files
committed
Disable xsystem for WASM
1 parent d7699c0 commit 49c8f48

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/xsystem.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ namespace xcpp
2828

2929
void apply(const std::string& code, nl::json& kernel_res) override
3030
{
31+
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
32+
// WASM environment: Disable shell commands
33+
kernel_res["status"] = "error";
34+
kernel_res["ename"] = "UnsupportedEnvironment";
35+
kernel_res["evalue"] = "Shell commands are not supported in the WASM environment.";
36+
kernel_res["traceback"] = nl::json::array();
37+
#else
38+
// Native environment: Execute shell commands
3139
std::regex re(spattern + R"((.*))");
3240
std::smatch to_execute;
3341
std::regex_search(code, to_execute, re);
@@ -65,6 +73,7 @@ namespace xcpp
6573
kernel_res["evalue"] = "evalue";
6674
kernel_res["traceback"] = nl::json::array();
6775
}
76+
#endif
6877
}
6978

7079
[[nodiscard]] std::unique_ptr<xpreamble> clone() const override

test/test_interpreter.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,20 @@ TEST_SUITE("xsystem_clone")
620620
TEST_SUITE("xsystem_apply")
621621
{
622622
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
623-
TEST_CASE("apply_xsystem"
624-
* doctest::should_fail(true)
625-
* doctest::description("TODO: Currently fails for the Emscripten build"))
623+
TEST_CASE("apply_xsystem")
624+
{
625+
xcpp::xsystem system;
626+
std::string code = "!echo Hello, World!";
627+
nl::json kernel_res;
628+
629+
system.apply(code, kernel_res);
630+
631+
REQUIRE(kernel_res["status"] == "error");
632+
REQUIRE(kernel_res["ename"] == "UnsupportedEnvironment");
633+
REQUIRE(kernel_res["evalue"] == "Shell commands are not supported in the WASM environment.");
634+
}
626635
#else
627636
TEST_CASE("apply_xsystem")
628-
#endif
629637
{
630638
xcpp::xsystem system;
631639
std::string code = "!echo Hello, World!";
@@ -635,6 +643,7 @@ TEST_SUITE("xsystem_apply")
635643

636644
REQUIRE(kernel_res["status"] == "ok");
637645
}
646+
#endif
638647
}
639648

640649
TEST_SUITE("xmagics_contains"){

0 commit comments

Comments
 (0)