Skip to content

Commit

Permalink
Merge branch 'main' of github.com:oven-sh/bun into don/test/test-assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Isaac committed Dec 13, 2024
2 parents aa5245f + bd1c5e9 commit 0144be6
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 94 deletions.
10 changes: 9 additions & 1 deletion cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,21 @@ if(LINUX)
target_link_options(${bun} PUBLIC
-Wl,--wrap=exp
-Wl,--wrap=expf
-Wl,--wrap=fcntl64
-Wl,--wrap=log
-Wl,--wrap=log2
-Wl,--wrap=log2f
-Wl,--wrap=logf
-Wl,--wrap=pow
-Wl,--wrap=powf
-Wl,--wrap=fcntl64
)
else()
target_link_options(${bun} PUBLIC
-Wl,--wrap=exp
-Wl,--wrap=expf
-Wl,--wrap=log2f
-Wl,--wrap=logf
-Wl,--wrap=powf
)
endif()
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")

if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION e17d16e0060b3d80ae40e78353d19575c9a8f3af)
set(WEBKIT_VERSION 58549ddc4d9e7164823fe9d4e86c46c003e46a19)
endif()

if(WEBKIT_LOCAL)
Expand Down
1 change: 1 addition & 0 deletions src/analytics/analytics_thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub const Features = struct {
pub var lifecycle_scripts: usize = 0;
pub var loaders: usize = 0;
pub var lockfile_migration_from_package_lock: usize = 0;
pub var text_lockfile: usize = 0;
pub var macros: usize = 0;
pub var no_avx2: usize = 0;
pub var no_avx: usize = 0;
Expand Down
16 changes: 8 additions & 8 deletions src/bake/FrameworkRouter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,10 @@ pub const JSFrameworkRouter = struct {
const validators = bun.JSC.Node.validators;

pub fn getBindings(global: *JSC.JSGlobalObject) JSC.JSValue {
return global.createObjectFromStruct(.{
return JSC.JSObject.create(.{
.parseRoutePattern = global.createHostFunction("parseRoutePattern", parseRoutePattern, 1),
.FrameworkRouter = codegen.getConstructor(global),
}).toJS();
}, global).toJS();
}

pub fn constructor(global: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) !*JSFrameworkRouter {
Expand Down Expand Up @@ -1165,7 +1165,7 @@ pub const JSFrameworkRouter = struct {
var sfb = std.heap.stackFallback(4096, bun.default_allocator);
const alloc = sfb.get();

return global.createObjectFromStruct(.{
return JSC.JSObject.create(.{
.params = if (params_out.params.len > 0) params: {
const obj = JSValue.createEmptyObject(global, params_out.params.len);
for (params_out.params.slice()) |param| {
Expand All @@ -1176,7 +1176,7 @@ pub const JSFrameworkRouter = struct {
break :params obj;
} else .null,
.route = try jsfr.routeToJsonInverse(global, index, alloc),
}).toJS();
}, global).toJS();
}

return .null;
Expand All @@ -1193,7 +1193,7 @@ pub const JSFrameworkRouter = struct {

fn routeToJson(jsfr: *JSFrameworkRouter, global: *JSGlobalObject, route_index: Route.Index, allocator: Allocator) !JSValue {
const route = jsfr.router.routePtr(route_index);
return global.createObjectFromStruct(.{
return JSC.JSObject.create(.{
.part = try partToJS(global, route.part, allocator),
.page = jsfr.fileIdToJS(global, route.file_page),
.layout = jsfr.fileIdToJS(global, route.file_layout),
Expand All @@ -1212,12 +1212,12 @@ pub const JSFrameworkRouter = struct {
}
break :brk arr;
},
}).toJS();
}, global).toJS();
}

fn routeToJsonInverse(jsfr: *JSFrameworkRouter, global: *JSGlobalObject, route_index: Route.Index, allocator: Allocator) !JSValue {
const route = jsfr.router.routePtr(route_index);
return global.createObjectFromStruct(.{
return JSC.JSObject.create(.{
.part = try partToJS(global, route.part, allocator),
.page = jsfr.fileIdToJS(global, route.file_page),
.layout = jsfr.fileIdToJS(global, route.file_layout),
Expand All @@ -1226,7 +1226,7 @@ pub const JSFrameworkRouter = struct {
try routeToJsonInverse(jsfr, global, parent, allocator)
else
.null,
}).toJS();
}, global).toJS();
}

pub fn finalize(this: *JSFrameworkRouter) void {
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindgen_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
const gen = bun.gen.bindgen_test;

pub fn getBindgenTestFunctions(global: *JSC.JSGlobalObject) JSC.JSValue {
return global.createObjectFromStruct(.{
return JSC.JSObject.create(.{
.add = gen.createAddCallback(global),
.requiredAndOptionalArg = gen.createRequiredAndOptionalArgCallback(global),
}).toJS();
}, global).toJS();
}

// This example should be kept in sync with bindgen's documentation
Expand Down
69 changes: 59 additions & 10 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,65 @@ pub const JSObject = extern struct {
return JSValue.fromCell(obj);
}

/// Marshall a struct instance into a JSObject, copying its properties.
///
/// Each field will be encoded with `JSC.toJS`. Fields whose types have a
/// `toJS` method will have it called to encode.
///
/// This method is equivalent to `Object.create(...)` + setting properties,
/// and is only intended for creating POJOs.
pub fn create(pojo: anytype, global: *JSGlobalObject) *JSObject {
return createFromStructWithPrototype(@TypeOf(pojo), pojo, global, false);
}
/// Marshall a struct into a JSObject, copying its properties. It's
/// `__proto__` will be `null`.
///
/// Each field will be encoded with `JSC.toJS`. Fields whose types have a
/// `toJS` method will have it called to encode.
///
/// This is roughly equivalent to creating an object with
/// `Object.create(null)` and adding properties to it.
pub fn createNullProto(pojo: anytype, global: *JSGlobalObject) *JSObject {
return createFromStructWithPrototype(@TypeOf(pojo), pojo, global, true);
}

/// Marshall a struct instance into a JSObject. `pojo` is borrowed.
///
/// Each field will be encoded with `JSC.toJS`. Fields whose types have a
/// `toJS` method will have it called to encode.
///
/// This method is equivalent to `Object.create(...)` + setting properties,
/// and is only intended for creating POJOs.
///
/// The object's prototype with either be `null` or `ObjectPrototype`
/// depending on whether `null_prototype` is set. Prefer using the object
/// prototype (`null_prototype = false`) unless you have a good reason not
/// to.
fn createFromStructWithPrototype(comptime T: type, pojo: T, global: *JSGlobalObject, comptime null_prototype: bool) *JSObject {
const info: std.builtin.Type.Struct = @typeInfo(T).Struct;

const obj = obj: {
const val = if (comptime null_prototype)
JSValue.createEmptyObjectWithNullPrototype(global)
else
JSValue.createEmptyObject(global, comptime info.fields.len);
bun.debugAssert(val.isObject());
break :obj val.uncheckedPtrCast(JSObject);
};

const cell = toJS(obj);
inline for (info.fields) |field| {
const property = @field(pojo, field.name);
cell.put(
global,
field.name,
JSC.toJS(global, @TypeOf(property), property, .temporary),
);
}

return obj;
}

pub inline fn put(obj: *JSObject, global: *JSGlobalObject, key: anytype, value: JSValue) !void {
obj.toJS().put(global, key, value);
}
Expand Down Expand Up @@ -3493,16 +3552,6 @@ pub const JSGlobalObject = opaque {
return default;
}

pub inline fn createObjectFromStruct(global: *JSGlobalObject, properties: anytype) *JSObject {
const obj = JSValue.createEmptyObject(global, comptime std.meta.fields(@TypeOf(properties)).len).uncheckedPtrCast(JSObject);
obj.putAllFromStruct(global, properties) catch {
// empty object has no setters. this must be a low-allocation OOM,
// wherethrowing will be nearly impossible to handle correctly.
bun.outOfMemory();
};
return obj;
}

pub inline fn createHostFunction(
global: *JSGlobalObject,
comptime display_name: [:0]const u8,
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindings/webcrypto/CryptoAlgorithmHMACOpenSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ExceptionOr<bool> CryptoAlgorithmHMAC::platformVerifyWithAlgorithm(const CryptoK
if (!expectedSignature)
return Exception { OperationError };
// Using a constant time comparison to prevent timing attacks.
return signature.size() == expectedSignature->size() && !constantTimeMemcmp(expectedSignature->data(), signature.data(), expectedSignature->size());
return signature.size() == expectedSignature->size() && !constantTimeMemcmp(expectedSignature->span(), signature.span());
}

ExceptionOr<bool> CryptoAlgorithmHMAC::platformVerify(const CryptoKeyHMAC& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
Expand All @@ -108,7 +108,7 @@ ExceptionOr<bool> CryptoAlgorithmHMAC::platformVerify(const CryptoKeyHMAC& key,
if (!expectedSignature)
return Exception { OperationError };
// Using a constant time comparison to prevent timing attacks.
return signature.size() == expectedSignature->size() && !constantTimeMemcmp(expectedSignature->data(), signature.data(), expectedSignature->size());
return signature.size() == expectedSignature->size() && !constantTimeMemcmp(expectedSignature->span(), signature.span());
}

} // namespace WebCore
Expand Down
30 changes: 17 additions & 13 deletions src/bun.js/bindings/workaround-missing-symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ extern "C" int kill(int pid, int sig)
#endif

#if defined(__x86_64__)
__asm__(".symver exp,exp@GLIBC_2.2.5");
__asm__(".symver expf,expf@GLIBC_2.2.5");
__asm__(".symver log2f,log2f@GLIBC_2.2.5");
__asm__(".symver logf,logf@GLIBC_2.2.5");
__asm__(".symver powf,powf@GLIBC_2.2.5");
#elif defined(__aarch64__)
__asm__(".symver expf,expf@GLIBC_2.17");
__asm__(".symver powf,powf@GLIBC_2.17");
__asm__(".symver pow,pow@GLIBC_2.17");
__asm__(".symver log,log@GLIBC_2.17");
__asm__(".symver exp,exp@GLIBC_2.17");
__asm__(".symver logf,logf@GLIBC_2.17");
__asm__(".symver log2f,log2f@GLIBC_2.17");
__asm__(".symver log,log@GLIBC_2.17");
__asm__(".symver log2,log2@GLIBC_2.17");
__asm__(".symver log2f,log2f@GLIBC_2.17");
__asm__(".symver logf,logf@GLIBC_2.17");
__asm__(".symver pow,pow@GLIBC_2.17");
__asm__(".symver powf,powf@GLIBC_2.17");
#endif

#if defined(__x86_64__) || defined(__aarch64__)
Expand All @@ -101,16 +105,16 @@ __asm__(".symver log2,log2@GLIBC_2.17");

extern "C" {

double BUN_WRAP_GLIBC_SYMBOL(exp)(double);
float BUN_WRAP_GLIBC_SYMBOL(expf)(float);
float BUN_WRAP_GLIBC_SYMBOL(log2f)(float);
float BUN_WRAP_GLIBC_SYMBOL(logf)(float);
float BUN_WRAP_GLIBC_SYMBOL(powf)(float, float);

#if defined(__aarch64__)

float BUN_WRAP_GLIBC_SYMBOL(powf)(float, float);
double BUN_WRAP_GLIBC_SYMBOL(pow)(double, double);
double BUN_WRAP_GLIBC_SYMBOL(log)(double);
double BUN_WRAP_GLIBC_SYMBOL(exp)(double);
float BUN_WRAP_GLIBC_SYMBOL(logf)(float);
float BUN_WRAP_GLIBC_SYMBOL(log2f)(float);
double BUN_WRAP_GLIBC_SYMBOL(log2)(double);
int BUN_WRAP_GLIBC_SYMBOL(fcntl64)(int, int, ...);

Expand All @@ -119,15 +123,15 @@ int BUN_WRAP_GLIBC_SYMBOL(fcntl64)(int, int, ...);
#if defined(__x86_64__) || defined(__aarch64__)

float __wrap_expf(float x) { return expf(x); }
float __wrap_powf(float x, float y) { return powf(x, y); }
float __wrap_logf(float x) { return logf(x); }
float __wrap_log2f(float x) { return log2f(x); }
double __wrap_exp(double x) { return exp(x); }

#if defined(__aarch64__)

float __wrap_powf(float x, float y) { return powf(x, y); }
double __wrap_pow(double x, double y) { return pow(x, y); }
double __wrap_log(double x) { return log(x); }
double __wrap_exp(double x) { return exp(x); }
float __wrap_logf(float x) { return logf(x); }
float __wrap_log2f(float x) { return log2f(x); }
double __wrap_log2(double x) { return log2(x); }

#endif
Expand Down
12 changes: 6 additions & 6 deletions src/ini.zig
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,12 @@ pub const IniTestingAPIs = struct {
default_registry_password.deref();
}

return globalThis.createObjectFromStruct(.{
.default_registry_url = default_registry_url.toJS(globalThis),
.default_registry_token = default_registry_token.toJS(globalThis),
.default_registry_username = default_registry_username.toJS(globalThis),
.default_registry_password = default_registry_password.toJS(globalThis),
}).toJS();
return JSC.JSObject.create(.{
.default_registry_url = default_registry_url,
.default_registry_token = default_registry_token,
.default_registry_username = default_registry_username,
.default_registry_password = default_registry_password,
}, globalThis).toJS();
}

pub fn parse(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
Expand Down
Loading

0 comments on commit 0144be6

Please sign in to comment.