Skip to content

Disable xsystem for WASM #288

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

Merged
merged 2 commits into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions src/xsystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ namespace xcpp

void apply(const std::string& code, nl::json& kernel_res) override
{
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
// WASM environment: Disable shell commands
kernel_res["status"] = "error";
kernel_res["ename"] = "UnsupportedEnvironment";
kernel_res["evalue"] = "Shell commands are not supported in the WASM environment.";
kernel_res["traceback"] = nl::json::array();
#else
// Native environment: Execute shell commands
std::regex re(spattern + R"((.*))");
std::smatch to_execute;
std::regex_search(code, to_execute, re);
Expand Down Expand Up @@ -65,6 +73,7 @@ namespace xcpp
kernel_res["evalue"] = "evalue";
kernel_res["traceback"] = nl::json::array();
}
#endif
}

[[nodiscard]] std::unique_ptr<xpreamble> clone() const override
Expand Down
8 changes: 2 additions & 6 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,15 +654,10 @@ TEST_SUITE("xsystem_clone")
}
}

#if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
TEST_SUITE("xsystem_apply")
{
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
TEST_CASE("apply_xsystem"
* doctest::should_fail(true)
* doctest::description("TODO: Currently fails for the Emscripten build"))
#else
TEST_CASE("apply_xsystem")
#endif
{
xcpp::xsystem system;
std::string code = "!echo Hello, World!";
Expand All @@ -673,6 +668,7 @@ TEST_SUITE("xsystem_apply")
REQUIRE(kernel_res["status"] == "ok");
}
}
#endif

TEST_SUITE("xmagics_contains"){
TEST_CASE("bad_status_cell") {
Expand Down
Loading