Skip to content

Commit

Permalink
set eval mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway committed Aug 1, 2024
1 parent f84c86d commit 1c1de31
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static bool has_loaded_jsc = false;
Structure* createMemoryFootprintStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject);

extern "C" WebCore::Worker* WebWorker__getParentWorker(void*);
extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(const char* ptr, size_t length))
extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(const char* ptr, size_t length), bool evalMode)
{
// NOLINTBEGIN
if (has_loaded_jsc)
Expand Down Expand Up @@ -218,6 +218,7 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c
JSC::Options::useResizableArrayBuffer() = true;
JSC::Options::usePromiseWithResolversMethod() = true;
JSC::Options::useV8DateParser() = true;
JSC::Options::evalMode() = evalMode;

#ifdef BUN_DEBUG
JSC::Options::showPrivateScriptsInStackTraces() = true;
Expand Down Expand Up @@ -987,7 +988,9 @@ const JSC::GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = {
nullptr, // defaultLanguage
nullptr, // compileStreaming
nullptr, // instantiateStreaming
&Zig::deriveShadowRealmGlobalObject
&Zig::deriveShadowRealmGlobalObject,
nullptr, // codeForEval
nullptr, // canCompileStrings
};

const JSC::GlobalObjectMethodTable EvalGlobalObject::s_globalObjectMethodTable = {
Expand All @@ -1010,7 +1013,9 @@ const JSC::GlobalObjectMethodTable EvalGlobalObject::s_globalObjectMethodTable =
nullptr, // defaultLanguage
nullptr, // compileStreaming
nullptr, // instantiateStreaming
&Zig::deriveShadowRealmGlobalObject
&Zig::deriveShadowRealmGlobalObject,
nullptr, // codeForEval
nullptr, // canCompileStrings
};

GlobalObject::GlobalObject(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable)
Expand Down
5 changes: 3 additions & 2 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6456,8 +6456,8 @@ pub const DOMCalls = &.{
Bun.FFIObject.Reader.DOMCalls,
};

extern "c" fn JSCInitialize(env: [*]const [*:0]u8, count: usize, cb: *const fn ([*]const u8, len: usize) callconv(.C) void) void;
pub fn initialize() void {
extern "c" fn JSCInitialize(env: [*]const [*:0]u8, count: usize, cb: *const fn ([*]const u8, len: usize) callconv(.C) void, eval_mode: bool) void;
pub fn initialize(eval_mode: bool) void {
JSC.markBinding(@src());
bun.analytics.Features.jsc += 1;
JSCInitialize(
Expand All @@ -6483,6 +6483,7 @@ pub fn initialize() void {
bun.Global.exit(1);
}
}.callback,
eval_mode,
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/bun_js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub const Run = struct {

pub fn bootStandalone(ctx: Command.Context, entry_path: string, graph: bun.StandaloneModuleGraph) !void {
JSC.markBinding(@src());
bun.JSC.initialize();
bun.JSC.initialize(false);

const graph_ptr = try bun.default_allocator.create(bun.StandaloneModuleGraph);
graph_ptr.* = graph;
Expand Down Expand Up @@ -182,7 +182,8 @@ pub const Run = struct {
return;
}

bun.JSC.initialize();
bun.JSC.initialize(ctx.runtime_options.eval.eval_and_print);

js_ast.Expr.Data.Store.create();
js_ast.Stmt.Data.Store.create();
var arena = try Arena.init();
Expand Down
2 changes: 1 addition & 1 deletion src/cli/test_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ pub const TestCommand = struct {
loader.* = DotEnv.Loader.init(map, ctx.allocator);
break :brk loader;
};
bun.JSC.initialize();
bun.JSC.initialize(false);
HTTPThread.init();

var snapshot_file_buf = std.ArrayList(u8).init(ctx.allocator);
Expand Down
2 changes: 1 addition & 1 deletion src/js_ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7741,7 +7741,7 @@ pub const Macro = struct {
defer resolver.opts.transform_options = old_transform_options;

// JSC needs to be initialized if building from CLI
JSC.initialize();
JSC.initialize(false);

var _vm = try JavaScript.VirtualMachine.init(.{
.allocator = default_allocator,
Expand Down

0 comments on commit 1c1de31

Please sign in to comment.