Skip to content
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
25 changes: 15 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ if (ENABLE_WPT)
include("tests/wpt-harness/wpt.cmake")
endif()

add_executable(starling-raw.wasm
runtime/js.cpp
runtime/allocator.cpp
runtime/encode.cpp
runtime/decode.cpp
runtime/engine.cpp
runtime/event_loop.cpp
runtime/builtin.cpp
runtime/script_loader.cpp
runtime/debugger.cpp
set(SOURCES
runtime/js.cpp
runtime/allocator.cpp
runtime/encode.cpp
runtime/decode.cpp
runtime/engine.cpp
runtime/event_loop.cpp
runtime/builtin.cpp
runtime/script_loader.cpp
)

if (ENABLE_JS_DEBUGGER)
list(APPEND SOURCES runtime/debugger.cpp)
endif()

add_executable(starling-raw.wasm ${SOURCES})

target_link_libraries(starling-raw.wasm PRIVATE host_api extension_api builtins spidermonkey rust-crates)

option(USE_WASM_OPT "use wasm-opt to optimize the StarlingMonkey binary" ON)
Expand Down
16 changes: 12 additions & 4 deletions runtime/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "jsfriendapi.h"
#pragma clang diagnostic pop

#include "debugger.h"
#ifdef JS_DEBUGGER
#include "debugger.h"
#endif
#include "script_loader.h"

#include <decode.h>
Expand Down Expand Up @@ -443,11 +445,13 @@ Engine::Engine(std::unique_ptr<EngineConfig> config) {
// Debugging isn't supported during wizening, so only try it when doing runtime evaluation.
// The debugger can be initialized at runtime by whatever export is invoked on the
// resumed wizer snapshot.
content_debugger::maybe_init_debugger(this, false);
#ifdef JS_DEBUGGER
content_debugger::maybe_init_debugger(this, false);
if (auto replacement_script_path = content_debugger::replacement_script_path()) {
TRACE("Using replacement script path received from debugger: " << *replacement_script_path);
content_script_path = replacement_script_path;
}
#endif
}

if (content_script_path) {
Expand Down Expand Up @@ -538,10 +542,14 @@ bool Engine::run_initialization_script() {

JSAutoRealm ar(cx, global);

if (!JS_DefineFunction(cx, global, "defineBuiltinModule", ::define_builtin_module, 2, 0) ||
!JS_DefineFunction(cx, global, "print", content_debugger::dbg_print, 1, 0)) {
if (!JS_DefineFunction(cx, global, "defineBuiltinModule", ::define_builtin_module, 2, 0)) {
return false;
}
#ifdef JS_DEBUGGER
if (!JS_DefineFunction(cx, global, "print", content_debugger::dbg_print, 1, 0)) {
return false;
}
#endif

auto path = config_->initializer_script_path.value();
TRACE("Running initialization script from file " << path);
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/init-script/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ const builtinMod = {
}

defineBuiltinModule('builtinMod', builtinMod);
print("initialization done");
if (typeof print !== 'undefined')
print("initialization done");
Loading