Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion scripts/build-jsc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bun
import { spawnSync } from "child_process";
import { existsSync, mkdirSync } from "fs";
import { existsSync, mkdirSync, rmSync } from "fs";
import { arch, platform } from "os";
import { join, resolve } from "path";

Expand Down Expand Up @@ -205,6 +205,10 @@ function buildJSC() {
env,
});

rmSync("vendor/WebKit/WebKitBuild/Debug/JavaScriptCore/DerivedSources/inspector/InspectorProtocolObjects.h", {
force: true,
});

console.log(`\n✅ JSC build completed successfully!`);
console.log(`Build output: ${buildDir}`);
}
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/SavedSourceMap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const SavedSourceMap = @This();

/// This is a pointer to the map located on the VirtualMachine struct
map: *HashTable,
mutex: bun.Mutex = .{},
mutex: bun.Mutex,

pub const vlq_offset = 24;

Expand All @@ -15,12 +15,12 @@ pub fn init(this: *SavedSourceMap, map: *HashTable) void {
this.map.lockPointers();
}

pub inline fn lock(map: *SavedSourceMap) void {
pub fn lock(map: *SavedSourceMap) void {
map.mutex.lock();
map.map.unlockPointers();
}

pub inline fn unlock(map: *SavedSourceMap) void {
pub fn unlock(map: *SavedSourceMap) void {
map.map.lockPointers();
map.mutex.unlock();
}
Expand All @@ -35,7 +35,7 @@ pub const SavedMappings = struct {
return this.data[vlq_offset..this.len()];
}

pub inline fn len(this: SavedMappings) usize {
pub fn len(this: SavedMappings) usize {
return @as(u64, @bitCast(this.data[0..8].*));
}

Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/api/bun/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ pub fn NewSocket(comptime ssl: bool) type {

const ext_size = @sizeOf(WrappedSocket);

var handlers_ptr = bun.handleOom(bun.default_allocator.create(Handlers));
var handlers_ptr = bun.new(Handlers, undefined);
handlers.withAsyncContextIfNeeded(globalObject);
handlers_ptr.* = handlers;
handlers_ptr.protect();
Expand Down Expand Up @@ -1534,7 +1534,7 @@ pub fn NewSocket(comptime ssl: bool) type {
tls.ref();
const vm = handlers.vm;

var raw_handlers_ptr = bun.handleOom(bun.default_allocator.create(Handlers));
var raw_handlers_ptr = bun.new(Handlers, undefined);
raw_handlers_ptr.* = blk: {
const this_handlers = this.getHandlers();
break :blk .{
Expand Down Expand Up @@ -1951,7 +1951,7 @@ pub fn jsUpgradeDuplexToTLS(globalObject: *jsc.JSGlobalObject, callframe: *jsc.C
return globalObject.throw("Expected \"socket\" option", .{});
};

var handlers = try Handlers.fromJS(globalObject, socket_obj, false);
const handlers = try Handlers.fromJS(globalObject, socket_obj, false);

var ssl_opts: ?jsc.API.ServerConfig.SSLConfig = null;
if (try opts.getTruthy(globalObject, "tls")) |tls| {
Expand Down Expand Up @@ -1982,7 +1982,7 @@ pub fn jsUpgradeDuplexToTLS(globalObject: *jsc.JSGlobalObject, callframe: *jsc.C

const is_server = false; // A duplex socket is always handled as a client

var handlers_ptr = bun.handleOom(handlers.vm.allocator.create(Handlers));
var handlers_ptr = bun.new(Handlers, undefined);
handlers_ptr.* = handlers;
handlers_ptr.is_server = is_server;
handlers_ptr.withAsyncContextIfNeeded(globalObject);
Expand Down
4 changes: 1 addition & 3 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3172,9 +3172,7 @@ extern fn Bun__addInspector(bool, *anyopaque, *jsc.JSGlobalObject) void;
pub export fn Server__setIdleTimeout(server: jsc.JSValue, seconds: jsc.JSValue, globalThis: *jsc.JSGlobalObject) void {
Server__setIdleTimeout_(server, seconds, globalThis) catch |err| switch (err) {
error.JSError => {},
error.OutOfMemory => {
_ = globalThis.throwOutOfMemoryValue();
},
error.OutOfMemory => globalThis.throwOutOfMemory() catch {},
};
}
Comment thread
nektro marked this conversation as resolved.
Resolved

Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/bindings/BunPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ void JSModuleMock::visitChildrenImpl(JSCell* cell, Visitor& visitor)

DEFINE_VISIT_CHILDREN(JSModuleMock);

EncodedJSValue BunPlugin::OnLoad::run(JSC::JSGlobalObject* globalObject, BunString* namespaceString, BunString* path)
EncodedJSValue BunPlugin::OnLoad::run(JSC::JSGlobalObject* globalObject, const BunString* namespaceString, const BunString* path)
{
Group* groupPtr = this->group(namespaceString ? namespaceString->toWTFString(BunString::ZeroCopy) : String());
if (groupPtr == nullptr) {
Expand Down Expand Up @@ -778,7 +778,7 @@ std::optional<String> BunPlugin::OnLoad::resolveVirtualModule(const String& path
return virtualModules->contains(path) ? std::optional<String> { path } : std::nullopt;
}

EncodedJSValue BunPlugin::OnResolve::run(JSC::JSGlobalObject* globalObject, BunString* namespaceString, BunString* path, BunString* importer)
EncodedJSValue BunPlugin::OnResolve::run(JSC::JSGlobalObject* globalObject, const BunString* namespaceString, const BunString* path, const BunString* importer)
{
Group* groupPtr = this->group(namespaceString ? namespaceString->toWTFString(BunString::ZeroCopy) : String());
if (groupPtr == nullptr) {
Expand Down Expand Up @@ -860,12 +860,12 @@ EncodedJSValue BunPlugin::OnResolve::run(JSC::JSGlobalObject* globalObject, BunS

} // namespace Zig

extern "C" JSC::EncodedJSValue Bun__runOnResolvePlugins(Zig::GlobalObject* globalObject, BunString* namespaceString, BunString* path, BunString* from, BunPluginTarget target)
extern "C" [[ZIG_EXPORT(nothrow)]] JSC::EncodedJSValue Bun__runOnResolvePlugins(Zig::GlobalObject* globalObject, const BunString* namespaceString, const BunString* path, const BunString* from, BunPluginTarget target)
{
return globalObject->onResolvePlugins.run(globalObject, namespaceString, path, from);
}

extern "C" JSC::EncodedJSValue Bun__runOnLoadPlugins(Zig::GlobalObject* globalObject, BunString* namespaceString, BunString* path, BunPluginTarget target)
extern "C" [[ZIG_EXPORT(nothrow)]] JSC::EncodedJSValue Bun__runOnLoadPlugins(Zig::GlobalObject* globalObject, const BunString* namespaceString, const BunString* path, BunPluginTarget target)
{
return globalObject->onLoadPlugins.run(globalObject, namespaceString, path);
}
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindings/BunPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BunPlugin {

VirtualModuleMap* _Nullable virtualModules = nullptr;
bool mustDoExpensiveRelativeLookup = false;
JSC::EncodedJSValue run(JSC::JSGlobalObject* globalObject, BunString* namespaceString, BunString* path);
JSC::EncodedJSValue run(JSC::JSGlobalObject* globalObject, const BunString* namespaceString, const BunString* path);

bool hasVirtualModules() const { return virtualModules != nullptr; }

Expand All @@ -95,7 +95,7 @@ class BunPlugin {
{
}

JSC::EncodedJSValue run(JSC::JSGlobalObject* globalObject, BunString* namespaceString, BunString* path, BunString* importer);
JSC::EncodedJSValue run(JSC::JSGlobalObject* globalObject, const BunString* namespaceString, const BunString* path, const BunString* importer);
};
};

Expand Down
70 changes: 16 additions & 54 deletions src/bun.js/bindings/JSGlobalObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub const JSGlobalObject = opaque {
return this.throwValue(err);
}

pub const requestTermination = JSGlobalObject__requestTermination;
pub const clearTerminationException = JSGlobalObject__clearTerminationException;
pub const requestTermination = bun.cpp.JSGlobalObject__requestTermination;
pub const clearTerminationException = bun.cpp.JSGlobalObject__clearTerminationException;

pub fn setTimeZone(this: *JSGlobalObject, timeZone: *const ZigString) bool {
return JSGlobalObject__setTimeZone(this, timeZone);
return bun.cpp.JSGlobalObject__setTimeZone(this, timeZone);
}

pub inline fn toJSValue(globalThis: *JSGlobalObject) JSValue {
Expand Down Expand Up @@ -230,32 +230,28 @@ pub const JSGlobalObject = opaque {
return this.throwValue(this.createNotEnoughArguments(name_, expected, got));
}

extern fn JSC__JSGlobalObject__reload(JSC__JSGlobalObject__ptr: *JSGlobalObject) void;
pub fn reload(this: *jsc.JSGlobalObject) void {
this.vm().drainMicrotasks();
this.vm().collectAsync();

JSC__JSGlobalObject__reload(this);
bun.cpp.JSC__JSGlobalObject__reload(this);
}

pub const BunPluginTarget = enum(u8) {
bun = 0,
node = 1,
browser = 2,
};
extern fn Bun__runOnLoadPlugins(*jsc.JSGlobalObject, ?*const bun.String, *const bun.String, BunPluginTarget) JSValue;
extern fn Bun__runOnResolvePlugins(*jsc.JSGlobalObject, ?*const bun.String, *const bun.String, *const String, BunPluginTarget) JSValue;

pub fn runOnLoadPlugins(this: *JSGlobalObject, namespace_: bun.String, path: bun.String, target: BunPluginTarget) bun.JSError!?JSValue {
jsc.markBinding(@src());
const result = try bun.jsc.fromJSHostCall(this, @src(), Bun__runOnLoadPlugins, .{ this, if (namespace_.length() > 0) &namespace_ else null, &path, target });
const result = try bun.jsc.fromJSHostCall(this, @src(), bun.cpp.Bun__runOnLoadPlugins, .{ this, if (namespace_.length() > 0) &namespace_ else null, &path, target });
if (result.isUndefinedOrNull()) return null;
return result;
}

pub fn runOnResolvePlugins(this: *JSGlobalObject, namespace_: bun.String, path: bun.String, source: bun.String, target: BunPluginTarget) bun.JSError!?JSValue {
jsc.markBinding(@src());
const result = try bun.jsc.fromJSHostCall(this, @src(), Bun__runOnResolvePlugins, .{ this, if (namespace_.length() > 0) &namespace_ else null, &path, &source, target });
const result = try bun.jsc.fromJSHostCall(this, @src(), bun.cpp.Bun__runOnResolvePlugins, .{ this, if (namespace_.length() > 0) &namespace_ else null, &path, &source, target });
if (result.isUndefinedOrNull()) return null;
return result;
}
Expand Down Expand Up @@ -601,42 +597,19 @@ pub const JSGlobalObject = opaque {
return bun.jsc.fromJSHostCallGeneric(this, @src(), JSC__JSGlobalObject__handleRejectedPromises, .{this}) catch @panic("unreachable");
}

extern fn ZigGlobalObject__readableStreamToArrayBuffer(*JSGlobalObject, JSValue) JSValue;
extern fn ZigGlobalObject__readableStreamToBytes(*JSGlobalObject, JSValue) JSValue;
extern fn ZigGlobalObject__readableStreamToText(*JSGlobalObject, JSValue) JSValue;
extern fn ZigGlobalObject__readableStreamToJSON(*JSGlobalObject, JSValue) JSValue;
extern fn ZigGlobalObject__readableStreamToFormData(*JSGlobalObject, JSValue, JSValue) JSValue;
extern fn ZigGlobalObject__readableStreamToBlob(*JSGlobalObject, JSValue) JSValue;

pub fn readableStreamToArrayBuffer(this: *JSGlobalObject, value: JSValue) JSValue {
return ZigGlobalObject__readableStreamToArrayBuffer(this, value);
}

pub fn readableStreamToBytes(this: *JSGlobalObject, value: JSValue) JSValue {
return ZigGlobalObject__readableStreamToBytes(this, value);
}
pub const readableStreamToArrayBuffer = bun.cpp.ZigGlobalObject__readableStreamToArrayBuffer;

pub fn readableStreamToText(this: *JSGlobalObject, value: JSValue) JSValue {
return ZigGlobalObject__readableStreamToText(this, value);
}
pub const readableStreamToBytes = bun.cpp.ZigGlobalObject__readableStreamToBytes;

pub fn readableStreamToJSON(this: *JSGlobalObject, value: JSValue) JSValue {
return ZigGlobalObject__readableStreamToJSON(this, value);
}
pub const readableStreamToText = bun.cpp.ZigGlobalObject__readableStreamToText;

pub fn readableStreamToBlob(this: *JSGlobalObject, value: JSValue) JSValue {
return ZigGlobalObject__readableStreamToBlob(this, value);
}
pub const readableStreamToJSON = bun.cpp.ZigGlobalObject__readableStreamToJSON;

pub fn readableStreamToFormData(this: *JSGlobalObject, value: JSValue, content_type: JSValue) JSValue {
return ZigGlobalObject__readableStreamToFormData(this, value, content_type);
}
pub const readableStreamToBlob = bun.cpp.ZigGlobalObject__readableStreamToBlob;

extern fn ZigGlobalObject__makeNapiEnvForFFI(*JSGlobalObject) *napi.NapiEnv;
pub const readableStreamToFormData = bun.cpp.ZigGlobalObject__readableStreamToFormData;

pub fn makeNapiEnvForFFI(this: *JSGlobalObject) *napi.NapiEnv {
return ZigGlobalObject__makeNapiEnvForFFI(this);
}
pub const makeNapiEnvForFFI = bun.cpp.ZigGlobalObject__makeNapiEnvForFFI;

pub inline fn assertOnJSThread(this: *JSGlobalObject) void {
if (bun.Environment.allow_assert) this.bunVM().assertOnJSThread();
Expand Down Expand Up @@ -798,13 +771,9 @@ pub const JSGlobalObject = opaque {
extern fn JSC__JSGlobalObject__deleteModuleRegistryEntry(*JSGlobalObject, *const ZigString) void;
extern fn JSGlobalObject__clearException(*JSGlobalObject) void;
extern fn JSGlobalObject__clearExceptionExceptTermination(*JSGlobalObject) bool;
extern fn JSGlobalObject__clearTerminationException(this: *JSGlobalObject) void;
extern fn JSGlobalObject__hasException(*JSGlobalObject) bool;
extern fn JSGlobalObject__setTimeZone(this: *JSGlobalObject, timeZone: *const ZigString) bool;
extern fn JSGlobalObject__tryTakeException(*JSGlobalObject) JSValue;
extern fn JSGlobalObject__requestTermination(this: *JSGlobalObject) void;

extern fn Zig__GlobalObject__create(*anyopaque, i32, bool, bool, ?*anyopaque) *JSGlobalObject;
pub fn create(
v: *jsc.VirtualMachine,
console: *anyopaque,
Expand All @@ -817,23 +786,17 @@ pub const JSGlobalObject = opaque {
defer trace.end();

v.eventLoop().ensureWaker();
const global = Zig__GlobalObject__create(console, context_id, mini_mode, eval_mode, worker_ptr);
const global = bun.cpp.Zig__GlobalObject__create(console, context_id, mini_mode, eval_mode, worker_ptr).?;

// JSC might mess with the stack size.
bun.StackCheck.configureThread();

return global;
}

extern fn Zig__GlobalObject__getModuleRegistryMap(*JSGlobalObject) *anyopaque;
pub fn getModuleRegistryMap(global: *JSGlobalObject) *anyopaque {
return Zig__GlobalObject__getModuleRegistryMap(global);
}
pub const getModuleRegistryMap = bun.cpp.Zig__GlobalObject__getModuleRegistryMap;

extern fn Zig__GlobalObject__resetModuleRegistryMap(*JSGlobalObject, *anyopaque) bool;
pub fn resetModuleRegistryMap(global: *JSGlobalObject, map: *anyopaque) bool {
return Zig__GlobalObject__resetModuleRegistryMap(global, map);
}
pub const resetModuleRegistryMap = bun.cpp.Zig__GlobalObject__resetModuleRegistryMap;

pub fn resolve(res: *ErrorableString, global: *JSGlobalObject, specifier: *bun.String, source: *bun.String, query: *ZigString) callconv(.C) void {
jsc.markBinding(@src());
Expand Down Expand Up @@ -987,7 +950,6 @@ pub const JSGlobalObject = opaque {

const string = []const u8;

const napi = @import("../../napi/napi.zig");
const std = @import("std");

const bun = @import("bun");
Expand Down
4 changes: 1 addition & 3 deletions src/bun.js/bindings/ZigException.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ pub const ZigException = extern struct {

browser_url: String = .empty,

pub extern fn ZigException__collectSourceLines(jsValue: JSValue, global: *JSGlobalObject, exception: *ZigException) void;

pub fn collectSourceLines(this: *ZigException, value: JSValue, global: *JSGlobalObject) void {
ZigException__collectSourceLines(value, global, this);
bun.cpp.ZigException__collectSourceLines(value, global, this);
}

pub fn deinit(this: *ZigException) void {
Expand Down
Loading