Skip to content

Commit

Permalink
Merge branch 'main' into jarred/regress
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Jan 26, 2025
2 parents bc1b61f + 75a95aa commit 86db693
Show file tree
Hide file tree
Showing 49 changed files with 1,273 additions and 977 deletions.
1 change: 1 addition & 0 deletions .buildkite/ci.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ function getBuildZigStep(platform, options) {
cancel_on_build_failing: isMergeQueue(),
env: getBuildEnv(platform, options),
command: `bun run build:ci --target bun-zig --toolchain ${toolchain}`,
timeout_in_minutes: 25,
};
}

Expand Down
12 changes: 12 additions & 0 deletions bench/snippets/buffer-create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ bench("Buffer.from('short string')", () => {
return Buffer.from("short string");
});

bench("new Buffer('short string')", () => {
return new Buffer("short string");
});

const loooong = "long string".repeat(9999).split("").join(" ");
bench("Buffer.byteLength('long string'.repeat(9999))", () => {
return Buffer.byteLength(loooong);
Expand All @@ -35,11 +39,19 @@ bench("Buffer.from(ArrayBuffer(100))", () => {
return Buffer.from(hundred);
});

bench("new Buffer(ArrayBuffer(100))", () => {
return new Buffer(hundred);
});

var hundredArray = new Uint8Array(100);
bench("Buffer.from(Uint8Array(100))", () => {
return Buffer.from(hundredArray);
});

bench("new Buffer(Uint8Array(100))", () => {
return new Buffer(hundredArray);
});

var empty = new Uint8Array(0);
bench("Buffer.from(Uint8Array(0))", () => {
return Buffer.from(empty);
Expand Down
11 changes: 9 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub fn getCpuModel(os: OperatingSystem, arch: Arch) ?Target.Query.CpuModel {

pub fn build(b: *Build) !void {
std.log.info("zig compiler v{s}", .{builtin.zig_version_string});
checked_file_exists = std.AutoHashMap(u64, void).init(b.allocator);

b.zig_lib_dir = b.zig_lib_dir orelse b.path("vendor/zig/lib");

Expand Down Expand Up @@ -481,9 +482,15 @@ pub fn addInstallObjectFile(
}, b.fmt("{s}.o", .{name})).step;
}

var checked_file_exists: std.AutoHashMap(u64, void) = undefined;
fn exists(path: []const u8) bool {
const file = std.fs.openFileAbsolute(path, .{ .mode = .read_only }) catch return false;
file.close();
const entry = checked_file_exists.getOrPut(std.hash.Wyhash.hash(0, path)) catch unreachable;
if (entry.found_existing) {
// It would've panicked.
return true;
}

std.fs.accessAbsolute(path, .{ .mode = .read_only }) catch return false;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "bun",
"version": "1.2.0",
"version": "1.2.1",
"workspaces": [
"./packages/bun-types"
],
Expand Down
2 changes: 1 addition & 1 deletion src/bake/FrameworkRouter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ pub const JSFrameworkRouter = struct {
return global.throwInvalidArguments("parseRoutePattern takes two arguments", .{});

const style_js, const filepath_js = frame.argumentsAsArray(2);
const filepath = try filepath_js.toSlice2(global, alloc);
const filepath = try filepath_js.toSlice(global, alloc);
defer filepath.deinit();
var style = try Style.fromJS(style_js, global);
errdefer style.deinit();
Expand Down
6 changes: 3 additions & 3 deletions src/bake/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ pub const Framework = struct {

const extensions: []const []const u8 = if (try fsr_opts.get(global, "extensions")) |exts_js| exts: {
if (exts_js.isString()) {
const str = try exts_js.toSlice2(global, arena);
const str = try exts_js.toSlice(global, arena);
defer str.deinit();
if (bun.strings.eqlComptime(str.slice(), "*")) {
break :exts &.{};
Expand All @@ -468,7 +468,7 @@ pub const Framework = struct {
var i_2: usize = 0;
const extensions = try arena.alloc([]const u8, exts_js.getLength(global));
while (it_2.next()) |array_item| : (i_2 += 1) {
const slice = refs.track(try array_item.toSlice2(global, arena));
const slice = refs.track(try array_item.toSlice(global, arena));
if (bun.strings.eqlComptime(slice, "*"))
return global.throwInvalidArguments("'extensions' cannot include \"*\" as an extension. Pass \"*\" instead of the array.", .{});

Expand All @@ -493,7 +493,7 @@ pub const Framework = struct {
var i_2: usize = 0;
const dirs = try arena.alloc([]const u8, len);
while (it_2.next()) |array_item| : (i_2 += 1) {
dirs[i_2] = refs.track(try array_item.toSlice2(global, arena));
dirs[i_2] = refs.track(try array_item.toSlice(global, arena));
}
break :exts dirs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/ConsoleObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,7 @@ pub const Formatter = struct {

switch (comptime Format) {
.StringPossiblyFormatted => {
var str = value.toSlice(this.globalThis, bun.default_allocator);
var str = try value.toSlice(this.globalThis, bun.default_allocator);
defer str.deinit();
this.addForNewLine(str.len);
const slice = str.slice();
Expand Down
22 changes: 11 additions & 11 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub fn which(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE
return JSC.JSValue.jsNull();
}

bin_str = path_arg.toSlice(globalThis, globalThis.bunVM().allocator);
bin_str = try path_arg.toSlice(globalThis, globalThis.bunVM().allocator);
if (globalThis.hasException()) {
return .zero;
}
Expand All @@ -391,11 +391,11 @@ pub fn which(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE
if (arguments.nextEat()) |arg| {
if (!arg.isEmptyOrUndefinedOrNull() and arg.isObject()) {
if (try arg.get(globalThis, "PATH")) |str_| {
path_str = str_.toSlice(globalThis, globalThis.bunVM().allocator);
path_str = try str_.toSlice(globalThis, globalThis.bunVM().allocator);
}

if (try arg.get(globalThis, "cwd")) |str_| {
cwd_str = str_.toSlice(globalThis, globalThis.bunVM().allocator);
cwd_str = try str_.toSlice(globalThis, globalThis.bunVM().allocator);
}
}
}
Expand Down Expand Up @@ -699,13 +699,13 @@ pub fn openInEditor(globalThis: js.JSContextRef, callframe: *JSC.CallFrame) bun.
var column: ?string = null;

if (arguments.nextEat()) |file_path_| {
path = file_path_.toSlice(globalThis, arguments.arena.allocator()).slice();
path = (try file_path_.toSlice(globalThis, arguments.arena.allocator())).slice();
}

if (arguments.nextEat()) |opts| {
if (!opts.isUndefinedOrNull()) {
if (try opts.getTruthy(globalThis, "editor")) |editor_val| {
var sliced = editor_val.toSlice(globalThis, arguments.arena.allocator());
var sliced = try editor_val.toSlice(globalThis, arguments.arena.allocator());
const prev_name = edit.name;

if (!strings.eqlLong(prev_name, sliced.slice(), true)) {
Expand All @@ -724,11 +724,11 @@ pub fn openInEditor(globalThis: js.JSContextRef, callframe: *JSC.CallFrame) bun.
}

if (try opts.getTruthy(globalThis, "line")) |line_| {
line = line_.toSlice(globalThis, arguments.arena.allocator()).slice();
line = (try line_.toSlice(globalThis, arguments.arena.allocator())).slice();
}

if (try opts.getTruthy(globalThis, "column")) |column_| {
column = column_.toSlice(globalThis, arguments.arena.allocator()).slice();
column = (try column_.toSlice(globalThis, arguments.arena.allocator())).slice();
}
}
}
Expand Down Expand Up @@ -1411,7 +1411,7 @@ pub const Crypto = struct {
}

if (!globalThis.hasException()) {
const slice = arguments[4].toSlice(globalThis, bun.default_allocator);
const slice = try arguments[4].toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
const name = slice.slice();
return globalThis.ERR_CRYPTO_INVALID_DIGEST("Invalid digest: {s}", .{name}).throw();
Expand Down Expand Up @@ -3233,7 +3233,7 @@ pub fn mmapFile(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.
const path = brk: {
if (args.nextEat()) |path| {
if (path.isString()) {
const path_str = path.toSlice(globalThis, args.arena.allocator());
const path_str = try path.toSlice(globalThis, args.arena.allocator());
if (path_str.len > bun.MAX_PATH_BYTES) {
return globalThis.throwInvalidArguments("Path too long", .{});
}
Expand Down Expand Up @@ -3401,7 +3401,7 @@ const HashObject = struct {
input = array_buffer.byteSlice();
},
else => {
input_slice = arg.toSlice(globalThis, bun.default_allocator);
input_slice = try arg.toSlice(globalThis, bun.default_allocator);
input = input_slice.slice();
},
}
Expand Down Expand Up @@ -3588,7 +3588,7 @@ const TOMLObject = struct {
return globalThis.throwInvalidArguments("Expected a string to parse", .{});
}

var input_slice = arguments[0].toSlice(globalThis, bun.default_allocator);
var input_slice = try arguments[0].toSlice(globalThis, bun.default_allocator);
defer input_slice.deinit();
var source = logger.Source.initPathString("input.toml", input_slice.slice());
const parse_result = TOMLParser.parse(&source, &log, allocator, false) catch {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub const JSBundler = struct {
} else if (env == .true or (env.isNumber() and env.asNumber() == 1)) {
this.env_behavior = .load_all;
} else if (env.isString()) {
const slice = try env.toSlice2(globalThis, bun.default_allocator);
const slice = try env.toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
if (strings.eqlComptime(slice.slice(), "inline")) {
this.env_behavior = .load_all;
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/JSTranspiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
const replacementValue = JSC.JSObject.getIndex(value, globalThis, 1);
if (exportReplacementValue(replacementValue, globalThis)) |to_replace| {
const replacementKey = JSC.JSObject.getIndex(value, globalThis, 0);
var slice = (try replacementKey.toSlice(globalThis, bun.default_allocator).cloneIfNeeded(bun.default_allocator));
var slice = (try (try replacementKey.toSlice(globalThis, bun.default_allocator)).cloneIfNeeded(bun.default_allocator));
const replacement_name = slice.slice();

if (!JSLexer.isIdentifier(replacement_name)) {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/bun/dns_resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ pub const InternalDNS = struct {
defer hostname_slice.deinit();

if (hostname_or_url.isString()) {
hostname_slice = hostname_or_url.toSlice(globalThis, bun.default_allocator);
hostname_slice = try hostname_or_url.toSlice(globalThis, bun.default_allocator);
} else {
return globalThis.throwInvalidArguments("hostname must be a string", .{});
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/bun/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ pub const Listener = struct {
if (!hostname.isString()) {
return global.throwInvalidArguments("hostname pattern expects a string", .{});
}
const host_str = hostname.toSlice(
const host_str = try hostname.toSlice(
global,
bun.default_allocator,
);
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/api/ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ pub const FFI = struct {
if (!value.isString()) {
return globalThis.throwInvalidArgumentTypeValue("flags", "array of strings", value);
}
const slice = value.toSlice(globalThis, bun.default_allocator);
const slice = try value.toSlice(globalThis, bun.default_allocator);
if (slice.len == 0) continue;
defer slice.deinit();
flags.append(' ') catch bun.outOfMemory();
Expand Down Expand Up @@ -1338,7 +1338,7 @@ pub const FFI = struct {
return ZigString.static("param must be a string (type name) or number").toErrorInstance(global);
}

var type_name = val.toSlice(global, allocator);
var type_name = try val.toSlice(global, allocator);
defer type_name.deinit();
abi_types.appendAssumeCapacity(ABIType.label.get(type_name.slice()) orelse {
abi_types.clearAndFree(allocator);
Expand Down Expand Up @@ -1370,7 +1370,7 @@ pub const FFI = struct {
}
}

var ret_slice = ret_value.toSlice(global, allocator);
var ret_slice = try ret_value.toSlice(global, allocator);
defer ret_slice.deinit();
return_type = ABIType.label.get(ret_slice.slice()) orelse {
abi_types.clearAndFree(allocator);
Expand Down
10 changes: 5 additions & 5 deletions src/bun.js/api/filesystem_router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub const FileSystemRouter = struct {
if (!dir.isString()) {
return globalThis.throwInvalidArguments("Expected dir to be a string", .{});
}
const root_dir_path_ = dir.toSlice(globalThis, globalThis.allocator());
const root_dir_path_ = try dir.toSlice(globalThis, globalThis.allocator());
if (!(root_dir_path_.len == 0 or strings.eqlComptime(root_dir_path_.slice(), "."))) {
// resolve relative path if needed
const path = root_dir_path_.slice();
Expand Down Expand Up @@ -115,7 +115,7 @@ pub const FileSystemRouter = struct {
return globalThis.throwInvalidArguments("Expected fileExtensions to be an Array of strings", .{});
}
if (val.getLength(globalThis) == 0) continue;
extensions.appendAssumeCapacity((val.toSlice(globalThis, allocator).clone(allocator) catch unreachable).slice()[1..]);
extensions.appendAssumeCapacity(((try val.toSlice(globalThis, allocator)).clone(allocator) catch unreachable).slice()[1..]);
}
}

Expand All @@ -127,7 +127,7 @@ pub const FileSystemRouter = struct {
return globalThis.throwInvalidArguments("Expected assetPrefix to be a string", .{});
}

asset_prefix_slice = asset_prefix.toSlice(globalThis, allocator).clone(allocator) catch unreachable;
asset_prefix_slice = (try asset_prefix.toSlice(globalThis, allocator)).clone(allocator) catch unreachable;
}
const orig_log = vm.transpiler.resolver.log;
var log = Log.Log.init(allocator);
Expand Down Expand Up @@ -167,7 +167,7 @@ pub const FileSystemRouter = struct {
globalThis.allocator().destroy(arena);
return globalThis.throwInvalidArguments("Expected origin to be a string", .{});
}
origin_str = origin.toSlice(globalThis, globalThis.allocator());
origin_str = try origin.toSlice(globalThis, globalThis.allocator());
}

if (log.errors + log.warnings > 0) {
Expand Down Expand Up @@ -299,7 +299,7 @@ pub const FileSystemRouter = struct {

var path: ZigString.Slice = brk: {
if (argument.isString()) {
break :brk argument.toSlice(globalThis, globalThis.allocator()).clone(globalThis.allocator()) catch unreachable;
break :brk (try argument.toSlice(globalThis, globalThis.allocator())).clone(globalThis.allocator()) catch unreachable;
}

if (argument.isCell()) {
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/glob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ScanOpts = struct {
error_on_broken_symlinks: bool,

fn parseCWD(globalThis: *JSGlobalObject, allocator: std.mem.Allocator, cwdVal: JSC.JSValue, absolute: bool, comptime fnName: string) bun.JSError![]const u8 {
const cwd_str_raw = cwdVal.toSlice(globalThis, allocator);
const cwd_str_raw = try cwdVal.toSlice(globalThis, allocator);
if (cwd_str_raw.len == 0) return "";

const cwd_str = cwd_str: {
Expand Down Expand Up @@ -403,7 +403,7 @@ pub fn match(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame
return globalThis.throw("Glob.matchString: first argument is not a string", .{});
}

var str = str_arg.toSlice(globalThis, arena.allocator());
var str = try str_arg.toSlice(globalThis, arena.allocator());
defer str.deinit();

if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImpl.Ascii.match(this.pattern, str.slice()).matches());
Expand Down
7 changes: 3 additions & 4 deletions src/bun.js/api/html_rewriter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ pub const Comment = struct {
) callconv(.C) bool {
if (this.comment == null)
return false;
var text = value.toSlice(global, bun.default_allocator);
var text = value.toSlice(global, bun.default_allocator) catch return false;
defer text.deinit();
this.comment.?.setText(text.slice()) catch {
global.throwValue(createLOLHTMLError(global)) catch {};
Expand Down Expand Up @@ -1517,7 +1517,7 @@ pub const EndTag = struct {
) callconv(.C) bool {
if (this.end_tag == null)
return false;
var text = value.toSlice(global, bun.default_allocator);
var text = value.toSlice(global, bun.default_allocator) catch return false;
defer text.deinit();
this.end_tag.?.setName(text.slice()) catch {
global.throwValue(createLOLHTMLError(global)) catch {};
Expand Down Expand Up @@ -1826,8 +1826,7 @@ pub const Element = struct {
) bool {
if (this.element == null)
return false;

var text = value.toSlice(global, bun.default_allocator);
var text = value.toSlice(global, bun.default_allocator) catch return false;
defer text.deinit();

this.element.?.setTagName(text.slice()) catch {
Expand Down
Loading

0 comments on commit 86db693

Please sign in to comment.