aboutsummaryrefslogtreecommitdiff
path: root/src/javascript
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-02 03:40:14 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-02 03:40:14 -0700
commit125a4c747b24fde0cc7f19d23c5f6b7c78244329 (patch)
tree53693dcbe5ba1e49779482de3c6ef46b44a409b2 /src/javascript
parent69668d49e5ddb5169eae7966d8a30e9ae9e32cea (diff)
downloadbun-125a4c747b24fde0cc7f19d23c5f6b7c78244329.tar.gz
bun-125a4c747b24fde0cc7f19d23c5f6b7c78244329.tar.zst
bun-125a4c747b24fde0cc7f19d23c5f6b7c78244329.zip
[bun:ffi] cleanup
Diffstat (limited to 'src/javascript')
-rw-r--r--src/javascript/jsc/api/FFI.h8
-rw-r--r--src/javascript/jsc/api/ffi.zig90
-rw-r--r--src/javascript/jsc/bindings/Buffer.h1
-rw-r--r--src/javascript/jsc/bindings/JSBuffer.cpp35
-rw-r--r--src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h1
-rw-r--r--src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp13
-rw-r--r--src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h9
-rw-r--r--src/javascript/jsc/bindings/header-gen.zig2
-rw-r--r--src/javascript/jsc/bindings/headers-cpp.h64
-rw-r--r--src/javascript/jsc/bindings/headers.h2
-rw-r--r--src/javascript/jsc/javascript.zig2
11 files changed, 146 insertions, 81 deletions
diff --git a/src/javascript/jsc/api/FFI.h b/src/javascript/jsc/api/FFI.h
index 48e4db48d..096abcfd9 100644
--- a/src/javascript/jsc/api/FFI.h
+++ b/src/javascript/jsc/api/FFI.h
@@ -106,6 +106,8 @@ EncodedJSValue ValueTrue = { TagValueTrue };
typedef void* JSContext;
+#define LOAD_ARGUMENTS_FROM_CALL_FRAME EncodedJSValue* args = (EncodedJSValue*)((size_t*)callFrame + Bun_FFI_PointerOffsetToArgumentsList);
+
#ifdef IS_CALLBACK
extern int64_t bun_call(JSContext, void* func, void* thisValue, size_t len, const EncodedJSValue args[], void* exception);
@@ -180,6 +182,12 @@ static bool JSVALUE_TO_BOOL(EncodedJSValue val) {
return val.asInt64 == TagValueTrue;
}
+#define arg(i) ((EncodedJSValue*)args)[i]
+void* JSFunctionCall(void* globalObject, void* callFrame);
+// int64_t JSFunctionCall(void* globalObject, void* callFrame) {
+// EncodedJSValue* args = (EncodedJSValue*)((unsigned char*)callFrame + Bun_FFI_PointerOffsetToArgumentsList);
+// }
+
// --- Generated Code ---
diff --git a/src/javascript/jsc/api/ffi.zig b/src/javascript/jsc/api/ffi.zig
index ceffd6278..7ae3b60dc 100644
--- a/src/javascript/jsc/api/ffi.zig
+++ b/src/javascript/jsc/api/ffi.zig
@@ -371,7 +371,12 @@ pub const FFI = struct {
return ZigString.init("Failed to compile (nothing happend!)").toErrorInstance(global);
},
.compiled => |compiled| {
- var cb = JSC.C.JSObjectMakeFunctionWithCallback(global.ref(), null, @ptrCast(JSC.C.JSObjectCallAsFunctionCallback, compiled.ptr));
+ var cb = Bun__CreateFFIFunction(
+ global,
+ &ZigString.init(std.mem.span(function.base_name)),
+ @intCast(u32, function.arg_types.items.len),
+ compiled.ptr,
+ );
obj.put(global, &ZigString.init(std.mem.span(function.base_name)), JSC.JSValue.cast(cb));
},
@@ -408,7 +413,7 @@ pub const FFI = struct {
if (val.isAnyInt()) {
const int = val.toInt32();
switch (int) {
- 0...13 => {
+ 0...14 => {
abi_types.appendAssumeCapacity(@intToEnum(ABIType, int));
continue;
},
@@ -439,7 +444,7 @@ pub const FFI = struct {
if (ret_value.isAnyInt()) {
const int = ret_value.toInt32();
switch (int) {
- 0...13 => {
+ 0...14 => {
return_type = @intToEnum(ABIType, int);
break :brk;
},
@@ -612,6 +617,19 @@ pub const FFI = struct {
}
_ = TCC.tcc_set_output_type(state, TCC.TCC_OUTPUT_MEMORY);
+ const Sizes = @import("../bindings/sizes.zig");
+
+ var symbol_buf: [256]u8 = undefined;
+ TCC.tcc_define_symbol(
+ state,
+ "Bun_FFI_PointerOffsetToArgumentsList",
+ std.fmt.bufPrintZ(&symbol_buf, "{d}", .{Sizes.Bun_FFI_PointerOffsetToArgumentsList}) catch unreachable,
+ );
+ // TCC.tcc_define_symbol(
+ // state,
+ // "Bun_FFI_PointerOffsetToArgumentsCount",
+ // std.fmt.bufPrintZ(symbol_buf[8..], "{d}", .{Bun_FFI_PointerOffsetToArgumentsCount}) catch unreachable,
+ // );
const compilation_result = TCC.tcc_compile_string(
state,
@@ -629,6 +647,7 @@ pub const FFI = struct {
}
CompilerRT.inject(state);
_ = TCC.tcc_add_symbol(state, this.base_name, this.symbol_from_dynamic_library.?);
+
if (this.step == .failed) {
return;
}
@@ -658,9 +677,7 @@ pub const FFI = struct {
pthread_jit_write_protect_np(true);
}
- var formatted_symbol_name = try std.fmt.allocPrintZ(allocator, "bun_gen_{s}", .{std.mem.span(this.base_name)});
- defer allocator.free(formatted_symbol_name);
- var symbol = TCC.tcc_get_symbol(state, formatted_symbol_name) orelse {
+ var symbol = TCC.tcc_get_symbol(state, "JSFunctionCall") orelse {
this.step = .{ .failed = .{ .msg = "missing generated symbol in source code" } };
return;
@@ -787,6 +804,10 @@ pub const FFI = struct {
this: *Function,
writer: anytype,
) !void {
+ if (this.arg_types.items.len > 0) {
+ try writer.writeAll("#define HAS_ARGUMENTS\n");
+ }
+
brk: {
if (this.return_type.isFloatingPoint()) {
try writer.writeAll("#define USES_FLOAT 1\n");
@@ -826,27 +847,20 @@ pub const FFI = struct {
try writer.writeAll(");\n\n");
// -- Generate JavaScriptCore's C wrapper function
- try writer.writeAll("/* ---- Your Wrapper Function ---- */\nvoid* bun_gen_");
- try writer.writeAll(std.mem.span(this.base_name));
- try writer.writeAll("(JSContext ctx, void* function, void* thisObject, size_t argumentCount, const EncodedJSValue arguments[], void* exception);\n\n");
+ try writer.writeAll(
+ \\/* ---- Your Wrapper Function ---- */
+ \\void* JSFunctionCall(void* globalObject, void* callFrame) {
+ \\#ifdef HAS_ARGUMENTS
+ \\ LOAD_ARGUMENTS_FROM_CALL_FRAME;
+ \\#endif
+ \\
+ );
+
+ // try writer.writeAll(
+ // "(JSContext ctx, void* function, void* thisObject, size_t argumentCount, const EncodedJSValue arguments[], void* exception);\n\n",
+ // );
- try writer.writeAll("void* bun_gen_");
- try writer.writeAll(std.mem.span(this.base_name));
- try writer.writeAll("(JSContext ctx, void* function, void* thisObject, size_t argumentCount, const EncodedJSValue arguments[], void* exception) {\n\n");
- if (comptime Environment.isDebug) {
- try writer.writeAll("#ifdef INJECT_BEFORE\n");
- try writer.writeAll("INJECT_BEFORE;\n");
- try writer.writeAll("#endif\n");
- }
var arg_buf: [512]u8 = undefined;
- arg_buf[0.."arguments[".len].* = "arguments[".*;
- for (this.arg_types.items) |arg, i| {
- try writer.writeAll(" ");
- try arg.typename(writer);
- var printed = std.fmt.bufPrintIntToSlice(arg_buf["arguments[".len..], i, 10, .lower, .{});
- arg_buf["arguments[".len + printed.len] = ']';
- try writer.print(" arg{d} = {};\n", .{ i, arg.toC(arg_buf[0 .. printed.len + "arguments[]".len]) });
- }
try writer.writeAll(" ");
if (!(this.return_type == .void)) {
@@ -855,14 +869,20 @@ pub const FFI = struct {
}
try writer.print("{s}(", .{std.mem.span(this.base_name)});
first = true;
- for (this.arg_types.items) |_, i| {
+ arg_buf[0..4].* = "arg(".*;
+ for (this.arg_types.items) |arg, i| {
if (!first) {
try writer.writeAll(", ");
}
first = false;
- try writer.print("arg{d}", .{i});
+
+ try writer.writeAll(" ");
+ _ = std.fmt.bufPrintIntToSlice(arg_buf["arg(".len..], i, 10, .lower, .{});
+ arg_buf["arg(N".len] = ')';
+ try writer.print("{}", .{arg.toC(arg_buf[0..6])});
}
try writer.writeAll(");\n");
+
if (!first) try writer.writeAll("\n");
try writer.writeAll(" ");
@@ -1014,6 +1034,8 @@ pub const FFI = struct {
@"void" = 13,
+ cstring = 14,
+
const map = .{
.{ "bool", ABIType.bool },
.{ "c_int", ABIType.int32_t },
@@ -1047,6 +1069,7 @@ pub const FFI = struct {
.{ "ptr", ABIType.ptr },
.{ "pointer", ABIType.ptr },
.{ "void", ABIType.@"void" },
+ .{ "cstring", ABIType.@"cstring" },
};
pub const label = ComptimeStringMap(ABIType, map);
const EnumMapFormatter = struct {
@@ -1110,7 +1133,7 @@ pub const FFI = struct {
},
.int64_t => {},
.uint64_t => {},
- .ptr => {
+ .cstring, .ptr => {
try writer.print("JSVALUE_TO_PTR({s})", .{self.symbol});
},
.double => {
@@ -1138,7 +1161,7 @@ pub const FFI = struct {
},
.int64_t => {},
.uint64_t => {},
- .ptr => {
+ .cstring, .ptr => {
try writer.print("PTR_TO_JSVALUE({s})", .{self.symbol});
},
.double => {
@@ -1171,7 +1194,7 @@ pub const FFI = struct {
pub fn typenameLabel(this: ABIType) []const u8 {
return switch (this) {
- .ptr => "void*",
+ .cstring, .ptr => "void*",
.bool => "bool",
.int8_t => "int8_t",
.uint8_t => "uint8_t",
@@ -1189,3 +1212,10 @@ pub const FFI = struct {
}
};
};
+
+extern fn Bun__CreateFFIFunction(
+ globalObject: *JSGlobalObject,
+ symbolName: *const ZigString,
+ argCount: u32,
+ functionPointer: *anyopaque,
+) *anyopaque;
diff --git a/src/javascript/jsc/bindings/Buffer.h b/src/javascript/jsc/bindings/Buffer.h
index bc3367ad6..3dc828c87 100644
--- a/src/javascript/jsc/bindings/Buffer.h
+++ b/src/javascript/jsc/bindings/Buffer.h
@@ -10,6 +10,7 @@
#include "BufferEncodingType.h"
#include "JavaScriptCore/GenericTypedArrayView.h"
#include "JavaScriptCore/JSBase.h"
+#include "headers-handwritten.h"
extern "C" JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalObject* lexicalGlobalObject, char* ptr, unsigned int length, void* ctx, JSTypedArrayBytesDeallocator bytesDeallocator);
extern "C" JSC::EncodedJSValue Bun__encoding__toStringUTF16(const uint8_t* input, size_t len, JSC::JSGlobalObject* globalObject);
diff --git a/src/javascript/jsc/bindings/JSBuffer.cpp b/src/javascript/jsc/bindings/JSBuffer.cpp
index 8f56703ce..347dec29a 100644
--- a/src/javascript/jsc/bindings/JSBuffer.cpp
+++ b/src/javascript/jsc/bindings/JSBuffer.cpp
@@ -797,6 +797,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGl
static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 1) {
return JSValue::encode(castedThis);
@@ -805,7 +806,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
auto value = callFrame->uncheckedArgument(0);
if (!value.isString()) {
- auto value_ = value.toInt32() & 0xFF;
+ auto value_ = value.toInt32(lexicalGlobalObject) & 0xFF;
auto value_uint8 = static_cast<uint8_t>(value_);
auto length = castedThis->byteLength();
@@ -815,21 +816,21 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
if (auto start_ = callFrame->uncheckedArgument(1).tryGetAsUint32Index()) {
start = start_.value();
} else {
- return throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
+ return throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
}
if (callFrame->argumentCount() > 2) {
if (auto end_ = callFrame->uncheckedArgument(2).tryGetAsUint32Index()) {
end = end_.value();
} else {
- return throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
+ return throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
}
}
}
if (start > end) {
- return throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
+ return throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
}
if (end > length) {
- return throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
+ return throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
}
auto startPtr = castedThis->typedVector() + start;
auto endPtr = castedThis->typedVector() + end;
@@ -848,14 +849,14 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
if (auto start_ = callFrame->uncheckedArgument(1).tryGetAsUint32Index()) {
start = start_.value();
} else {
- throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
+ throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
return JSC::JSValue::encode(jsUndefined());
}
if (callFrame->argumentCount() > 2) {
if (auto end_ = callFrame->uncheckedArgument(2).tryGetAsUint32Index()) {
end = end_.value();
} else {
- throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
+ throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
return JSC::JSValue::encode(jsUndefined());
}
}
@@ -863,9 +864,9 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
if (callFrame->argumentCount() > 3) {
auto encoding_ = callFrame->uncheckedArgument(3).toString(lexicalGlobalObject);
- std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, arg1.value());
+ std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, encoding_);
if (!encoded) {
- throwTypeError(lexicalGlobalObject, scope, "Invalid encoding");
+ throwTypeError(lexicalGlobalObject, throwScope, "Invalid encoding");
return JSC::JSValue::encode(jsUndefined());
}
@@ -873,24 +874,24 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
}
}
if (start > end) {
- throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
+ throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "start out of range"_s));
return JSC::JSValue::encode(jsUndefined());
}
if (end > length) {
- throwVMError(lexicalGlobalObject, JSC::throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
+ throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "end out of range"_s));
return JSC::JSValue::encode(jsUndefined());
}
auto startPtr = castedThis->typedVector() + start;
- ZigString str = Zig::toString(value.toString(lexicalGlobalObject));
+ // ZigString str = Zig::toString(value.toString(lexicalGlobalObject));
- Bun__ArrayBuffer buf;
- JSC__JSValue__asArrayBuffer_(JSC::JSValue::encode(castedThis), lexicalGlobalObject,
- &buf);
- Bun__Buffer_fill(lexicalGlobalObject, &buf, &str, start, end, encoding);
+ // Bun__ArrayBuffer buf;
+ // JSC__JSValue__asArrayBuffer_(JSC::JSValue::encode(castedThis), lexicalGlobalObject,
+ // &buf);
+ // Bun__Buffer_fill(lexicalGlobalObject, &buf, &str, start, end, encoding);
- return JSValue::encode(castedThis);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(castedThis));
}
}
static inline JSC::EncodedJSValue jsBufferPrototypeFunction_includesBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis)
diff --git a/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h
index 328e597eb..f071164d5 100644
--- a/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h
+++ b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h
@@ -1,3 +1,4 @@
+//clang-format off
/*
* Copyright (c) 2016 Apple Inc. All rights reserved.
* Copyright (c) 2022 Codeblog Corp. All rights reserved.
diff --git a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp
index 2c3969f98..a7548b22a 100644
--- a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp
+++ b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp
@@ -673,6 +673,19 @@ const char* const s_jsBufferPrototypeToJSONCode =
"})\n" \
;
+const JSC::ConstructAbility s_jsBufferPrototypeSubarrayCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeSubarrayCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeSubarrayCodeLength = 196;
+static const JSC::Intrinsic s_jsBufferPrototypeSubarrayCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeSubarrayCode =
+ "(function (start, end) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " Buffer[Symbol.species] ??= Buffer;\n" \
+ " return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));\n" \
+ "})\n" \
+;
+
const JSC::ConstructAbility s_jsBufferPrototypeInitializeBunBufferCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeConstructorKind = JSC::ConstructorKind::None;
const int s_jsBufferPrototypeInitializeBunBufferCodeLength = 45;
diff --git a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h
index 3bd387ff3..beff50d66 100644
--- a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h
+++ b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h
@@ -1,3 +1,4 @@
+//clang-format off
/*
* Copyright (c) 2016 Apple Inc. All rights reserved.
* Copyright (c) 2022 Codeblog Corp. All rights reserved.
@@ -262,6 +263,10 @@ extern const char* const s_jsBufferPrototypeToJSONCode;
extern const int s_jsBufferPrototypeToJSONCodeLength;
extern const JSC::ConstructAbility s_jsBufferPrototypeToJSONCodeConstructAbility;
extern const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeSubarrayCode;
+extern const int s_jsBufferPrototypeSubarrayCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeSubarrayCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeSubarrayCodeConstructorKind;
extern const char* const s_jsBufferPrototypeInitializeBunBufferCode;
extern const int s_jsBufferPrototypeInitializeBunBufferCodeLength;
extern const JSC::ConstructAbility s_jsBufferPrototypeInitializeBunBufferCodeConstructAbility;
@@ -323,6 +328,7 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeCons
macro(base64urlSlice, jsBufferPrototypeBase64urlSlice, 2) \
macro(hexSlice, jsBufferPrototypeHexSlice, 2) \
macro(toJSON, jsBufferPrototypeToJSON, 0) \
+ macro(subarray, jsBufferPrototypeSubarray, 2) \
macro(initializeBunBuffer, jsBufferPrototypeInitializeBunBuffer, 1) \
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_SETBIGUINT64 1
@@ -380,6 +386,7 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeCons
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BASE64URLSLICE 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_HEXSLICE 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_TOJSON 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_SUBARRAY 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_INITIALIZEBUNBUFFER 1
#define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(macro) \
@@ -438,6 +445,7 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeCons
macro(jsBufferPrototypeBase64urlSliceCode, base64urlSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeBase64urlSliceCodeLength) \
macro(jsBufferPrototypeHexSliceCode, hexSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeHexSliceCodeLength) \
macro(jsBufferPrototypeToJSONCode, toJSON, static_cast<const char*>(nullptr), s_jsBufferPrototypeToJSONCodeLength) \
+ macro(jsBufferPrototypeSubarrayCode, subarray, static_cast<const char*>(nullptr), s_jsBufferPrototypeSubarrayCodeLength) \
macro(jsBufferPrototypeInitializeBunBufferCode, initializeBunBuffer, static_cast<const char*>(nullptr), s_jsBufferPrototypeInitializeBunBufferCodeLength) \
#define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(macro) \
@@ -472,6 +480,7 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeCons
macro(readUInt8) \
macro(setBigUint64) \
macro(slice) \
+ macro(subarray) \
macro(toJSON) \
macro(ucs2Slice) \
macro(ucs2Write) \
diff --git a/src/javascript/jsc/bindings/header-gen.zig b/src/javascript/jsc/bindings/header-gen.zig
index 30467f698..3ec73ea94 100644
--- a/src/javascript/jsc/bindings/header-gen.zig
+++ b/src/javascript/jsc/bindings/header-gen.zig
@@ -517,7 +517,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
\\
\\#ifndef INCLUDED_{s}
\\#define INCLUDED_{s}
- \\#include {s}
+ \\#include "{s}"
\\#endif
\\
\\extern "C" const size_t {s} = sizeof({s});
diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h
index 67ae00e83..fdac529b7 100644
--- a/src/javascript/jsc/bindings/headers-cpp.h
+++ b/src/javascript/jsc/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1651379222
+//-- AUTOGENERATED FILE -- 1651480881
// clang-format off
#pragma once
@@ -10,7 +10,7 @@
#ifndef INCLUDED_JavaScriptCore_JSObject_h
#define INCLUDED_JavaScriptCore_JSObject_h
-#include JavaScriptCore/JSObject.h
+#include "JavaScriptCore/JSObject.h"
#endif
extern "C" const size_t JSC__JSObject_object_size_ = sizeof(JSC::JSObject);
@@ -18,7 +18,7 @@ extern "C" const size_t JSC__JSObject_object_align_ = alignof(JSC::JSObject);
#ifndef INCLUDED_FetchHeaders_h
#define INCLUDED_FetchHeaders_h
-#include FetchHeaders.h
+#include "FetchHeaders.h"
#endif
extern "C" const size_t WebCore__FetchHeaders_object_size_ = sizeof(WebCore::FetchHeaders);
@@ -26,7 +26,7 @@ extern "C" const size_t WebCore__FetchHeaders_object_align_ = alignof(WebCore::F
#ifndef INCLUDED_JavaScriptCore_JSCell_h
#define INCLUDED_JavaScriptCore_JSCell_h
-#include JavaScriptCore/JSCell.h
+#include "JavaScriptCore/JSCell.h"
#endif
extern "C" const size_t JSC__JSCell_object_size_ = sizeof(JSC::JSCell);
@@ -34,7 +34,7 @@ extern "C" const size_t JSC__JSCell_object_align_ = alignof(JSC::JSCell);
#ifndef INCLUDED_JavaScriptCore_JSString_h
#define INCLUDED_JavaScriptCore_JSString_h
-#include JavaScriptCore/JSString.h
+#include "JavaScriptCore/JSString.h"
#endif
extern "C" const size_t JSC__JSString_object_size_ = sizeof(JSC::JSString);
@@ -42,7 +42,7 @@ extern "C" const size_t JSC__JSString_object_align_ = alignof(JSC::JSString);
#ifndef INCLUDED_JavaScriptCore_ScriptArguments_h
#define INCLUDED_JavaScriptCore_ScriptArguments_h
-#include JavaScriptCore/ScriptArguments.h
+#include "JavaScriptCore/ScriptArguments.h"
#endif
extern "C" const size_t Inspector__ScriptArguments_object_size_ = sizeof(Inspector::ScriptArguments);
@@ -50,7 +50,7 @@ extern "C" const size_t Inspector__ScriptArguments_object_align_ = alignof(Inspe
#ifndef INCLUDED_JavaScriptCore_JSModuleLoader_h
#define INCLUDED_JavaScriptCore_JSModuleLoader_h
-#include JavaScriptCore/JSModuleLoader.h
+#include "JavaScriptCore/JSModuleLoader.h"
#endif
extern "C" const size_t JSC__JSModuleLoader_object_size_ = sizeof(JSC::JSModuleLoader);
@@ -58,7 +58,7 @@ extern "C" const size_t JSC__JSModuleLoader_object_align_ = alignof(JSC::JSModul
#ifndef INCLUDED_JavaScriptCore_JSModuleRecord_h
#define INCLUDED_JavaScriptCore_JSModuleRecord_h
-#include JavaScriptCore/JSModuleRecord.h
+#include "JavaScriptCore/JSModuleRecord.h"
#endif
extern "C" const size_t JSC__JSModuleRecord_object_size_ = sizeof(JSC::JSModuleRecord);
@@ -66,7 +66,7 @@ extern "C" const size_t JSC__JSModuleRecord_object_align_ = alignof(JSC::JSModul
#ifndef INCLUDED_JavaScriptCore_JSPromise_h
#define INCLUDED_JavaScriptCore_JSPromise_h
-#include JavaScriptCore/JSPromise.h
+#include "JavaScriptCore/JSPromise.h"
#endif
extern "C" const size_t JSC__JSPromise_object_size_ = sizeof(JSC::JSPromise);
@@ -74,7 +74,7 @@ extern "C" const size_t JSC__JSPromise_object_align_ = alignof(JSC::JSPromise);
#ifndef INCLUDED_JavaScriptCore_JSInternalPromise_h
#define INCLUDED_JavaScriptCore_JSInternalPromise_h
-#include JavaScriptCore/JSInternalPromise.h
+#include "JavaScriptCore/JSInternalPromise.h"
#endif
extern "C" const size_t JSC__JSInternalPromise_object_size_ = sizeof(JSC::JSInternalPromise);
@@ -82,7 +82,7 @@ extern "C" const size_t JSC__JSInternalPromise_object_align_ = alignof(JSC::JSIn
#ifndef INCLUDED_JavaScriptCore_SourceOrigin_h
#define INCLUDED_JavaScriptCore_SourceOrigin_h
-#include JavaScriptCore/SourceOrigin.h
+#include "JavaScriptCore/SourceOrigin.h"
#endif
extern "C" const size_t JSC__SourceOrigin_object_size_ = sizeof(JSC::SourceOrigin);
@@ -90,7 +90,7 @@ extern "C" const size_t JSC__SourceOrigin_object_align_ = alignof(JSC::SourceOri
#ifndef INCLUDED_JavaScriptCore_SourceProvider_h
#define INCLUDED_JavaScriptCore_SourceProvider_h
-#include JavaScriptCore/SourceProvider.h
+#include "JavaScriptCore/SourceProvider.h"
#endif
extern "C" const size_t JSC__SourceCode_object_size_ = sizeof(JSC::SourceCode);
@@ -98,7 +98,7 @@ extern "C" const size_t JSC__SourceCode_object_align_ = alignof(JSC::SourceCode)
#ifndef INCLUDED_JavaScriptCore_JSFunction_h
#define INCLUDED_JavaScriptCore_JSFunction_h
-#include JavaScriptCore/JSFunction.h
+#include "JavaScriptCore/JSFunction.h"
#endif
extern "C" const size_t JSC__JSFunction_object_size_ = sizeof(JSC::JSFunction);
@@ -106,7 +106,7 @@ extern "C" const size_t JSC__JSFunction_object_align_ = alignof(JSC::JSFunction)
#ifndef INCLUDED_JavaScriptCore_JSGlobalObject_h
#define INCLUDED_JavaScriptCore_JSGlobalObject_h
-#include JavaScriptCore/JSGlobalObject.h
+#include "JavaScriptCore/JSGlobalObject.h"
#endif
extern "C" const size_t JSC__JSGlobalObject_object_size_ = sizeof(JSC::JSGlobalObject);
@@ -114,7 +114,7 @@ extern "C" const size_t JSC__JSGlobalObject_object_align_ = alignof(JSC::JSGloba
#ifndef INCLUDED_wtf_URL_h
#define INCLUDED_wtf_URL_h
-#include wtf/URL.h
+#include "wtf/URL.h"
#endif
extern "C" const size_t WTF__URL_object_size_ = sizeof(WTF::URL);
@@ -122,7 +122,7 @@ extern "C" const size_t WTF__URL_object_align_ = alignof(WTF::URL);
#ifndef INCLUDED_wtf_text_WTFString_h
#define INCLUDED_wtf_text_WTFString_h
-#include wtf/text/WTFString.h
+#include "wtf/text/WTFString.h"
#endif
extern "C" const size_t WTF__String_object_size_ = sizeof(WTF::String);
@@ -130,7 +130,7 @@ extern "C" const size_t WTF__String_object_align_ = alignof(WTF::String);
#ifndef INCLUDED_JavaScriptCore_JSValue_h
#define INCLUDED_JavaScriptCore_JSValue_h
-#include JavaScriptCore/JSValue.h
+#include "JavaScriptCore/JSValue.h"
#endif
extern "C" const size_t JSC__JSValue_object_size_ = sizeof(JSC::JSValue);
@@ -138,7 +138,7 @@ extern "C" const size_t JSC__JSValue_object_align_ = alignof(JSC::JSValue);
#ifndef INCLUDED_JavaScriptCore_PropertyName_h
#define INCLUDED_JavaScriptCore_PropertyName_h
-#include JavaScriptCore/PropertyName.h
+#include "JavaScriptCore/PropertyName.h"
#endif
extern "C" const size_t JSC__PropertyName_object_size_ = sizeof(JSC::PropertyName);
@@ -146,7 +146,7 @@ extern "C" const size_t JSC__PropertyName_object_align_ = alignof(JSC::PropertyN
#ifndef INCLUDED_JavaScriptCore_Exception_h
#define INCLUDED_JavaScriptCore_Exception_h
-#include JavaScriptCore/Exception.h
+#include "JavaScriptCore/Exception.h"
#endif
extern "C" const size_t JSC__Exception_object_size_ = sizeof(JSC::Exception);
@@ -154,7 +154,7 @@ extern "C" const size_t JSC__Exception_object_align_ = alignof(JSC::Exception);
#ifndef INCLUDED_JavaScriptCore_VM_h
#define INCLUDED_JavaScriptCore_VM_h
-#include JavaScriptCore/VM.h
+#include "JavaScriptCore/VM.h"
#endif
extern "C" const size_t JSC__VM_object_size_ = sizeof(JSC::VM);
@@ -162,7 +162,7 @@ extern "C" const size_t JSC__VM_object_align_ = alignof(JSC::VM);
#ifndef INCLUDED_JavaScriptCore_ThrowScope_h
#define INCLUDED_JavaScriptCore_ThrowScope_h
-#include JavaScriptCore/ThrowScope.h
+#include "JavaScriptCore/ThrowScope.h"
#endif
extern "C" const size_t JSC__ThrowScope_object_size_ = sizeof(JSC::ThrowScope);
@@ -170,7 +170,7 @@ extern "C" const size_t JSC__ThrowScope_object_align_ = alignof(JSC::ThrowScope)
#ifndef INCLUDED_JavaScriptCore_CatchScope_h
#define INCLUDED_JavaScriptCore_CatchScope_h
-#include JavaScriptCore/CatchScope.h
+#include "JavaScriptCore/CatchScope.h"
#endif
extern "C" const size_t JSC__CatchScope_object_size_ = sizeof(JSC::CatchScope);
@@ -178,7 +178,7 @@ extern "C" const size_t JSC__CatchScope_object_align_ = alignof(JSC::CatchScope)
#ifndef INCLUDED_JavaScriptCore_CallFrame_h
#define INCLUDED_JavaScriptCore_CallFrame_h
-#include JavaScriptCore/CallFrame.h
+#include "JavaScriptCore/CallFrame.h"
#endif
extern "C" const size_t JSC__CallFrame_object_size_ = sizeof(JSC::CallFrame);
@@ -186,7 +186,7 @@ extern "C" const size_t JSC__CallFrame_object_align_ = alignof(JSC::CallFrame);
#ifndef INCLUDED_JavaScriptCore_Identifier_h
#define INCLUDED_JavaScriptCore_Identifier_h
-#include JavaScriptCore/Identifier.h
+#include "JavaScriptCore/Identifier.h"
#endif
extern "C" const size_t JSC__Identifier_object_size_ = sizeof(JSC::Identifier);
@@ -194,7 +194,7 @@ extern "C" const size_t JSC__Identifier_object_align_ = alignof(JSC::Identifier)
#ifndef INCLUDED_wtf_text_StringImpl_h
#define INCLUDED_wtf_text_StringImpl_h
-#include wtf/text/StringImpl.h
+#include "wtf/text/StringImpl.h"
#endif
extern "C" const size_t WTF__StringImpl_object_size_ = sizeof(WTF::StringImpl);
@@ -202,7 +202,7 @@ extern "C" const size_t WTF__StringImpl_object_align_ = alignof(WTF::StringImpl)
#ifndef INCLUDED_wtf_text_ExternalStringImpl_h
#define INCLUDED_wtf_text_ExternalStringImpl_h
-#include wtf/text/ExternalStringImpl.h
+#include "wtf/text/ExternalStringImpl.h"
#endif
extern "C" const size_t WTF__ExternalStringImpl_object_size_ = sizeof(WTF::ExternalStringImpl);
@@ -210,7 +210,7 @@ extern "C" const size_t WTF__ExternalStringImpl_object_align_ = alignof(WTF::Ext
#ifndef INCLUDED_wtf_text_StringView_h
#define INCLUDED_wtf_text_StringView_h
-#include wtf/text/StringView.h
+#include "wtf/text/StringView.h"
#endif
extern "C" const size_t WTF__StringView_object_size_ = sizeof(WTF::StringView);
@@ -226,7 +226,7 @@ extern "C" const size_t Zig__GlobalObject_object_align_ = alignof(Zig::GlobalObj
#ifndef INCLUDED_BunStream_h
#define INCLUDED_BunStream_h
-#include BunStream.h
+#include "BunStream.h"
#endif
extern "C" const size_t Bun__Readable_object_size_ = sizeof(Bun__Readable);
@@ -234,7 +234,7 @@ extern "C" const size_t Bun__Readable_object_align_ = alignof(Bun__Readable);
#ifndef INCLUDED_BunStream_h
#define INCLUDED_BunStream_h
-#include BunStream.h
+#include "BunStream.h"
#endif
extern "C" const size_t Bun__Writable_object_size_ = sizeof(Bun__Writable);
@@ -242,7 +242,9 @@ extern "C" const size_t Bun__Writable_object_align_ = alignof(Bun__Writable);
#ifndef INCLUDED_Path_h
#define INCLUDED_Path_h
-#include Path.h
+// #include "Path.h"
+#define Bun__Path void*
+#define Bun__Timer void*
#endif
extern "C" const size_t Bun__Path_object_size_ = sizeof(Bun__Path);
@@ -258,7 +260,7 @@ extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleC
#ifndef INCLUDED_
#define INCLUDED_
-#include
+// #include ""
#endif
extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h
index 2e8b427b1..057e38eb8 100644
--- a/src/javascript/jsc/bindings/headers.h
+++ b/src/javascript/jsc/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format: off
-//-- AUTOGENERATED FILE -- 1651379222
+//-- AUTOGENERATED FILE -- 1651480881
#pragma once
#include <stddef.h>
diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig
index 5996f5808..efb0481f7 100644
--- a/src/javascript/jsc/javascript.zig
+++ b/src/javascript/jsc/javascript.zig
@@ -1081,7 +1081,7 @@ pub const VirtualMachine = struct {
} else if (strings.eqlComptime(_specifier, "bun:ffi")) {
return ResolvedSource{
.allocator = null,
- .source_code = ZigString.init(@embedFile("ffi.exports.js") ++ "export const FFIType = " ++ JSC.FFI.ABIType.map_to_js_object ++ ";\n"),
+ .source_code = ZigString.init("export const FFIType = " ++ JSC.FFI.ABIType.map_to_js_object ++ ";\n\n" ++ @embedFile("ffi.exports.js") ++ "\n"),
.specifier = ZigString.init("bun:ffi"),
.source_url = ZigString.init("bun:ffi"),
.hash = 0,