Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bug/fetch-options-15082' into bu…
Browse files Browse the repository at this point in the history
…g/fetch-options-15082
  • Loading branch information
Kapsonfire-DE committed Nov 13, 2024
2 parents 7d6f000 + 0fb0675 commit 71bd417
Show file tree
Hide file tree
Showing 57 changed files with 3,574 additions and 3,161 deletions.
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ If you see this error when compiling, run:
$ xcode-select --install
```

## Cannot find `libatomic.a`
### Cannot find `libatomic.a`

Bun defaults to linking `libatomic` statically, as not all systems have it. If you are building on a distro that does not have a static libatomic available, you can run the following command to enable dynamic linking:

Expand All @@ -295,11 +295,17 @@ $ bun run build -DUSE_STATIC_LIBATOMIC=OFF

The built version of Bun may not work on other systems if compiled this way.

## ccache conflicts with building TinyCC on macOS
### ccache conflicts with building TinyCC on macOS

If you run into issues with `ccache` when building TinyCC, try reinstalling ccache

```bash
brew uninstall ccache
brew install ccache
```

## Using bun-debug

- Disable logging: `BUN_DEBUG_QUIET_LOGS=1 bun-debug ...` (to disable all debug logging)
- Enable logging for a specific zig scope: `BUN_DEBUG_EventLoop=1 bun-debug ...` (to allow `std.log.scoped(.EventLoop)`)
- Bun transpiles every file it runs, to see the actual executed source in a debug build find it in `/tmp/bun-debug-src/...path/to/file`, for example the transpiled version of `/home/bun/index.ts` would be in `/tmp/bun-debug-src/home/bun/index.ts`
5 changes: 5 additions & 0 deletions cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ else()
set(LLD_NAME lld-${LLVM_VERSION_MAJOR})
endif()

if (NOT IS_MUSL)
if (IS_ARM64)
set(ARCH_WRAP_FLAGS
-Wl,--wrap=fcntl64
Expand All @@ -901,6 +902,10 @@ else()
-Wl,--wrap=statx
)
endif()
else()
set(ARCH_WRAP_FLAGS
)
endif()

if (NOT IS_MUSL)
set(ABI_WRAP_FLAGS
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 73b551e25d97e463e8e2c86cb819b8639fcbda06)
set(WEBKIT_VERSION 3bc4abf2d5875baf500b4687ef869987f6d19e00)
endif()

if(WEBKIT_LOCAL)
Expand Down
4 changes: 2 additions & 2 deletions src/StandaloneModuleGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ pub const StandaloneModuleGraph = struct {
if (item.data != .e_string)
return error.InvalidSourceMap;

const decoded = try item.data.e_string.stringDecodedUTF8(arena);
const decoded = try item.data.e_string.stringCloned(arena);

const offset = string_payload.items.len;
try string_payload.appendSlice(decoded);
Expand All @@ -1089,7 +1089,7 @@ pub const StandaloneModuleGraph = struct {
if (item.data != .e_string)
return error.InvalidSourceMap;

const utf8 = try item.data.e_string.stringDecodedUTF8(arena);
const utf8 = try item.data.e_string.stringCloned(arena);
defer arena.free(utf8);

const offset = string_payload.items.len;
Expand Down
2 changes: 1 addition & 1 deletion src/api/schema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2816,7 +2816,7 @@ pub const Api = struct {

fn expectString(this: *Parser, expr: js_ast.Expr) !void {
switch (expr.data) {
.e_string, .e_utf8_string => {},
.e_string => {},
else => {
this.log.addErrorFmt(this.source, expr.loc, this.allocator, "expected string but received {}", .{
@as(js_ast.Expr.Tag, expr.data),
Expand Down
3 changes: 2 additions & 1 deletion src/bun.js/RuntimeTranspilerCache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
/// Version 6: `use strict` is preserved in CommonJS modules when at the top of the file
/// Version 7: Several bundler changes that are likely to impact the runtime as well.
/// Version 8: Fix for generated symbols
const expected_version = 8;
/// Version 9: String printing changes
const expected_version = 9;

const bun = @import("root").bun;
const std = @import("std");
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/postgres.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default [
length: 0,
},
},
values: ["pendingValue", "binding"],
values: ["pendingValue", "columns", "binding"],
estimatedSize: true,
}),
];
15 changes: 10 additions & 5 deletions src/bun.js/bindings/BunJSCEventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

extern "C" int Bun__JSC_onBeforeWait(JSC::VM* vm)
{
if (vm->heap.hasAccess()) {
vm->heap.releaseAccess();
return 1;
}
UNUSED_PARAM(vm);
// TODO: use JSC timers, run the incremental sweeper.
// That will fix this.
// In the meantime, we're disabling this due to https://github.com/oven-sh/bun/issues/14982
// if (vm->heap.hasAccess()) {
// vm->heap.releaseAccess();
// return 1;
// }
return 0;
}

extern "C" void Bun__JSC_onAfterWait(JSC::VM* vm)
{
vm->heap.acquireAccess();
UNUSED_PARAM(vm);
// vm->heap.acquireAccess();
}
10 changes: 10 additions & 0 deletions src/bun.js/bindings/BunObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ static JSValue constructPluginObject(VM& vm, JSObject* bunObject)
return pluginFunction;
}

static JSValue constructBunSQLObject(VM& vm, JSObject* bunObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
auto* globalObject = defaultGlobalObject(bunObject->globalObject());
JSValue sqlValue = globalObject->internalModuleRegistry()->requireId(globalObject, vm, InternalModuleRegistry::BunSql);
RETURN_IF_EXCEPTION(scope, {});
return sqlValue.getObject()->get(globalObject, vm.propertyNames->defaultKeyword);
}

extern "C" JSC::EncodedJSValue JSPasswordObject__create(JSGlobalObject*);

static JSValue constructPasswordObject(VM& vm, JSObject* bunObject)
Expand Down Expand Up @@ -630,6 +639,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
resolveSync BunObject_callback_resolveSync DontDelete|Function 1
revision constructBunRevision ReadOnly|DontDelete|PropertyCallback
semver BunObject_getter_wrap_semver ReadOnly|DontDelete|PropertyCallback
sql constructBunSQLObject DontDelete|PropertyCallback
serve BunObject_callback_serve DontDelete|Function 1
sha BunObject_callback_sha DontDelete|Function 1
shrink BunObject_callback_shrink DontDelete|Function 1
Expand Down
14 changes: 9 additions & 5 deletions src/bun.js/bindings/SQLClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef union DataCellValue {
int64_t bigint;
uint8_t boolean;
double date;
double date_with_time_zone;
size_t bytea[2];
WTF::StringImpl* json;
DataCellArray array;
Expand All @@ -62,10 +63,11 @@ enum class DataCellTag : uint8_t {
Bigint = 4,
Boolean = 5,
Date = 6,
Bytea = 7,
Json = 8,
Array = 9,
TypedArray = 10,
DateWithTimeZone = 7,
Bytea = 8,
Json = 9,
Array = 10,
TypedArray = 11,
};

typedef struct DataCell {
Expand Down Expand Up @@ -96,9 +98,11 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel
case DataCellTag::Boolean:
return jsBoolean(cell.value.boolean);
break;
case DataCellTag::Date:
case DataCellTag::DateWithTimeZone:
case DataCellTag::Date: {
return JSC::DateInstance::create(vm, globalObject->dateStructure(), cell.value.date);
break;
}
case DataCellTag::Bytea: {
Zig::GlobalObject* zigGlobal = jsCast<Zig::GlobalObject*>(globalObject);
auto* subclassStructure = zigGlobal->JSBufferSubclassStructure();
Expand Down
39 changes: 38 additions & 1 deletion src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5628,7 +5628,37 @@ CPP_DECL double JSC__JSValue__getUnixTimestamp(JSC__JSValue timeValue)
if (!date)
return PNaN;

return date->internalNumber();
double number = date->internalNumber();

return number;
}

extern "C" JSC::EncodedJSValue JSC__JSValue__getOwnByValue(JSC__JSValue value, JSC__JSGlobalObject* globalObject, JSC__JSValue propertyValue)
{
auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSC::JSObject* object = JSValue::decode(value).getObject();
JSC::JSValue property = JSValue::decode(propertyValue);
uint32_t index;

PropertySlot slot(object, PropertySlot::InternalMethodType::GetOwnProperty);
if (property.getUInt32(index)) {
if (!object->getOwnPropertySlotByIndex(object, globalObject, index, slot))
return JSC::JSValue::encode({});

RETURN_IF_EXCEPTION(scope, {});

return JSC::JSValue::encode(slot.getValue(globalObject, index));
} else {
auto propertyName = property.toPropertyKey(globalObject);
RETURN_IF_EXCEPTION(scope, {});
if (!object->getOwnNonIndexPropertySlot(vm, object->structure(), propertyName, slot))
return JSC::JSValue::encode({});

RETURN_IF_EXCEPTION(scope, {});

return JSC::JSValue::encode(slot.getValue(globalObject, propertyName));
}
}

extern "C" double Bun__parseDate(JSC::JSGlobalObject* globalObject, BunString* str)
Expand All @@ -5637,6 +5667,13 @@ extern "C" double Bun__parseDate(JSC::JSGlobalObject* globalObject, BunString* s
return vm.dateCache.parseDate(globalObject, vm, str->toWTFString());
}

extern "C" EncodedJSValue JSC__JSValue__dateInstanceFromNumber(JSC::JSGlobalObject* globalObject, double unixTimestamp)
{
auto& vm = globalObject->vm();
JSC::DateInstance* date = JSC::DateInstance::create(vm, globalObject->dateStructure(), unixTimestamp);
return JSValue::encode(date);
}

extern "C" EncodedJSValue JSC__JSValue__dateInstanceFromNullTerminatedString(JSC::JSGlobalObject* globalObject, const LChar* nullTerminatedChars)
{
double dateSeconds = WTF::parseDate(std::span<const LChar>(nullTerminatedChars, strlen(reinterpret_cast<const char*>(nullTerminatedChars))));
Expand Down
19 changes: 19 additions & 0 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4327,6 +4327,12 @@ pub const JSValue = enum(JSValueReprInt) {
return JSC__JSValue__dateInstanceFromNullTerminatedString(globalObject, str);
}

extern fn JSC__JSValue__dateInstanceFromNumber(*JSGlobalObject, f64) JSValue;
pub fn fromDateNumber(globalObject: *JSGlobalObject, value: f64) JSValue {
JSC.markBinding(@src());
return JSC__JSValue__dateInstanceFromNumber(globalObject, value);
}

extern fn JSBuffer__isBuffer(*JSGlobalObject, JSValue) bool;
pub fn isBuffer(value: JSValue, global: *JSGlobalObject) bool {
JSC.markBinding(@src());
Expand Down Expand Up @@ -5288,6 +5294,13 @@ pub const JSValue = enum(JSValueReprInt) {
return if (@intFromEnum(value) != 0) value else return null;
}

extern fn JSC__JSValue__getOwnByValue(value: JSValue, globalObject: *JSGlobalObject, propertyValue: JSValue) JSValue;

pub fn getOwnByValue(this: JSValue, global: *JSGlobalObject, property_value: JSValue) ?JSValue {
const value = JSC__JSValue__getOwnByValue(this, global, property_value);
return if (@intFromEnum(value) != 0) value else return null;
}

pub fn getOwnTruthy(this: JSValue, global: *JSGlobalObject, property_name: anytype) ?JSValue {
if (getOwn(this, global, property_name)) |prop| {
if (prop == .undefined) return null;
Expand Down Expand Up @@ -5627,6 +5640,12 @@ pub const JSValue = enum(JSValueReprInt) {
});
}

extern fn JSC__JSValue__getUTCTimestamp(globalObject: *JSC.JSGlobalObject, this: JSValue) f64;
/// Calls getTime() - getUTCT
pub fn getUTCTimestamp(this: JSValue, globalObject: *JSC.JSGlobalObject) f64 {
return JSC__JSValue__getUTCTimestamp(globalObject, this);
}

pub const StringFormatter = struct {
value: JSC.JSValue,
globalObject: *JSC.JSGlobalObject,
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/module_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ pub const ModuleLoader = struct {
.specifier = input_specifier,
.source_url = input_specifier.createIfDifferent(path.text),
.hash = 0,
.jsvalue_for_export = parse_result.ast.parts.@"[0]"().stmts[0].data.s_expr.value.toJS(allocator, globalObject orelse jsc_vm.global, .{}) catch @panic("Unexpected JS error"),
.jsvalue_for_export = parse_result.ast.parts.@"[0]"().stmts[0].data.s_expr.value.toJS(allocator, globalObject orelse jsc_vm.global) catch @panic("Unexpected JS error"),
.tag = .exports_object,
};
}
Expand Down Expand Up @@ -2472,7 +2472,7 @@ pub const ModuleLoader = struct {
return jsSyntheticModule(.@"bun:sql", specifier);
},
.@"bun:sqlite" => return jsSyntheticModule(.@"bun:sqlite", specifier),
.@"detect-libc" => return jsSyntheticModule(if (Environment.isLinux) .@"detect-libc/linux" else .@"detect-libc", specifier),
.@"detect-libc" => return jsSyntheticModule(if (!Environment.isLinux) .@"detect-libc" else if (!Environment.isMusl) .@"detect-libc/linux" else .@"detect-libc/musl", specifier),
.@"node:assert" => return jsSyntheticModule(.@"node:assert", specifier),
.@"node:assert/strict" => return jsSyntheticModule(.@"node:assert/strict", specifier),
.@"node:async_hooks" => return jsSyntheticModule(.@"node:async_hooks", specifier),
Expand Down
21 changes: 8 additions & 13 deletions src/bun.js/node/node_fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4002,11 +4002,7 @@ pub const NodeFS = struct {

pub fn access(this: *NodeFS, args: Arguments.Access, comptime _: Flavor) Maybe(Return.Access) {
const path = args.path.sliceZ(&this.sync_error_buf);
if (Environment.isWindows) {
return Syscall.access(path, @intFromEnum(args.mode));
}
const rc = Syscall.system.access(path, @intFromEnum(args.mode));
return Maybe(Return.Access).errnoSysP(rc, .access, path) orelse Maybe(Return.Access).success;
return Syscall.access(path, @intFromEnum(args.mode));
}

pub fn appendFile(this: *NodeFS, args: Arguments.AppendFile, comptime flavor: Flavor) Maybe(Return.AppendFile) {
Expand Down Expand Up @@ -5925,16 +5921,15 @@ pub const NodeFS = struct {
// on mac, it's relatively positioned
0
else brk: {
// on linux, it's absolutely positioned
const pos = bun.sys.system.lseek(
fd.cast(),
// on linux, it's absolutely positione

switch (Syscall.lseek(
fd,
@as(std.posix.off_t, @intCast(0)),
std.os.linux.SEEK.CUR,
);

switch (bun.sys.getErrno(pos)) {
.SUCCESS => break :brk @as(usize, @intCast(pos)),
else => break :preallocate,
)) {
.err => break :preallocate,
.result => |pos| break :brk @as(usize, @intCast(pos)),
}
};

Expand Down
23 changes: 13 additions & 10 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,18 @@ pub fn getRuntimeFeatureFlag(comptime flag: [:0]const u8) bool {
}.get();
}

pub fn getenvZAnyCase(key: [:0]const u8) ?[]const u8 {
for (std.os.environ) |lineZ| {
const line = sliceTo(lineZ, 0);
const key_end = strings.indexOfCharUsize(line, '=') orelse line.len;
if (strings.eqlCaseInsensitiveASCII(line[0..key_end], key, true)) {
return line[@min(key_end + 1, line.len)..];
}
}

return null;
}

/// This wrapper exists to avoid the call to sliceTo(0)
/// Zig's sliceTo(0) is scalar
pub fn getenvZ(key: [:0]const u8) ?[]const u8 {
Expand All @@ -917,16 +929,7 @@ pub fn getenvZ(key: [:0]const u8) ?[]const u8 {
}

if (comptime Environment.isWindows) {
// Windows UCRT will fill this in for us
for (std.os.environ) |lineZ| {
const line = sliceTo(lineZ, 0);
const key_end = strings.indexOfCharUsize(line, '=') orelse line.len;
if (strings.eqlCaseInsensitiveASCII(line[0..key_end], key, true)) {
return line[@min(key_end + 1, line.len)..];
}
}

return null;
return getenvZAnyCase(key);
}

const ptr = std.c.getenv(key.ptr) orelse return null;
Expand Down
2 changes: 1 addition & 1 deletion src/bundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ pub const Bundler = struct {
},
// TODO: use lazy export AST
.text => {
const expr = js_ast.Expr.init(js_ast.E.UTF8String, js_ast.E.UTF8String{
const expr = js_ast.Expr.init(js_ast.E.String, js_ast.E.String{
.data = source.contents,
}, logger.Loc.Empty);
const stmt = js_ast.Stmt.alloc(js_ast.S.ExportDefault, js_ast.S.ExportDefault{
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/bundle_v2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3504,7 +3504,7 @@ pub const ParseTask = struct {
return JSAst.init((try js_parser.newLazyExportAST(allocator, bundler.options.define, opts, log, root, &source, "")).?);
},
.text => {
const root = Expr.init(E.UTF8String, E.UTF8String{
const root = Expr.init(E.String, E.String{
.data = source.contents,
}, Logger.Loc{ .start = 0 });
var ast = JSAst.init((try js_parser.newLazyExportAST(allocator, bundler.options.define, opts, log, root, &source, "")).?);
Expand Down
2 changes: 1 addition & 1 deletion src/bunfig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ pub const Bunfig = struct {

pub fn expectString(this: *Parser, expr: js_ast.Expr) !void {
switch (expr.data) {
.e_string, .e_utf8_string => {},
.e_string => {},
else => {
this.log.addErrorFmtOpts(
this.allocator,
Expand Down
Loading

0 comments on commit 71bd417

Please sign in to comment.