diff options
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/buffer.test.js | 36 | ||||
-rw-r--r-- | src/c.zig | 72 | ||||
-rw-r--r-- | src/fs.zig | 9 | ||||
-rw-r--r-- | src/global.zig | 2 |
5 files changed, 132 insertions, 2 deletions
@@ -369,7 +369,20 @@ tinycc: make -j10 generate-builtins: - $(shell which python || which python2) $(realpath $(WEBKIT_DIR)/Source/JavaScriptCore/Scripts/generate-js-builtins.py) -i $(realpath src/javascript/jsc/bindings/builtins/js) -o $(realpath src/javascript/jsc/bindings) --framework WebCore + rm -f src/javascript/jsc/bindings/WebCoreBuiltins.cpp src/javascript/jsc/bindings/WebCoreBuiltins.h src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp src/javascript/jsc/bindings/WebCore*Builtins* || echo "" + $(shell which python || which python2) $(realpath $(WEBKIT_DIR)/Source/JavaScriptCore/Scripts/generate-js-builtins.py) -i $(realpath src/javascript/jsc/bindings/builtins/js) -o $(realpath src/javascript/jsc/bindings) --framework WebCore --force + $(shell which python || which python2) $(realpath $(WEBKIT_DIR)/Source/JavaScriptCore/Scripts/generate-js-builtins.py) -i $(realpath src/javascript/jsc/bindings/builtins/js) -o $(realpath src/javascript/jsc/bindings) --framework WebCore --wrappers-only + echo '//clang-format off' > /tmp/1.h + echo 'namespace Zig { class GlobalObject; }' >> /tmp/1.h + cat /tmp/1.h src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h > src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h.1 + mv src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h.1 src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h + $(SED) -i -e 's/class JSDOMGlobalObject/using JSDOMGlobalObject = Zig::GlobalObject/' src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h +# Since we don't currently support web streams, we don't need this line +# so we comment it out + $(SED) -i -e 's/globalObject.addStaticGlobals/\/\/globalObject.addStaticGlobals/' src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp +# We delete this file because our script already builds all .cpp files +# We will get duplicate symbols if we don't delete it + rm src/javascript/jsc/bindings/WebCoreJSBuiltins.cpp vendor-without-check: api analytics node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive libbacktrace lolhtml usockets uws base64 diff --git a/integration/bunjs-only-snippets/buffer.test.js b/integration/bunjs-only-snippets/buffer.test.js index d1a5c7ff3..18b31cae8 100644 --- a/integration/bunjs-only-snippets/buffer.test.js +++ b/integration/bunjs-only-snippets/buffer.test.js @@ -88,6 +88,42 @@ it("writeInt", () => { expect(childBuf.readInt32BE(0, false)).toBe(100); }); +it("Buffer.from", () => { + expect(Buffer.from("hello world").toString("utf8")).toBe("hello world"); + expect(Buffer.from("hello world", "ascii").toString("utf8")).toBe( + "hello world" + ); + expect(Buffer.from("hello world", "latin1").toString("utf8")).toBe( + "hello world" + ); + expect(Buffer.from([254]).join(",")).toBe("254"); + expect(Buffer.from(123).join(",")).toBe(Uint8Array.from(123).join(",")); + expect(Buffer.from({ length: 124 }).join(",")).toBe( + Uint8Array.from({ length: 124 }).join(",") + ); + + expect(Buffer.from(new ArrayBuffer(1024), 0, 512).join(",")).toBe( + new Uint8Array(512).join(",") + ); + + expect(Buffer.from(new Buffer(new ArrayBuffer(1024), 0, 512)).join(",")).toBe( + new Uint8Array(512).join(",") + ); +}); + +it("Buffer.copy", () => { + var array1 = new Uint8Array(128); + array1.fill(100); + Buffer.toBuffer(array1); + var array2 = new Uint8Array(128); + array2.fill(200); + Buffer.toBuffer(array2); + var array3 = new Uint8Array(128); + Buffer.toBuffer(array3); + expect(array1.copy(array2)).toBe(128); + expect(array1.join("")).toBe(array2.join("")); +}); + it("read", () => { var buf = new Buffer(1024); var data = new DataView(buf.buffer); @@ -177,3 +177,75 @@ pub fn kindFromMode(mode: os.mode_t) std.fs.File.Kind { else => .Unknown, }; } + +pub fn getSelfExeSharedLibPaths(allocator: std.mem.Allocator) error{OutOfMemory}![][:0]u8 { + const List = std.ArrayList([:0]u8); + switch (builtin.os.tag) { + .linux, + .freebsd, + .netbsd, + .dragonfly, + .openbsd, + .solaris, + => { + var paths = List.init(allocator); + errdefer { + const slice = paths.toOwnedSlice(); + for (slice) |item| { + allocator.free(item); + } + allocator.free(slice); + } + try os.dl_iterate_phdr(&paths, error{OutOfMemory}, struct { + fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void { + _ = size; + const name = info.dlpi_name orelse return; + if (name[0] == '/') { + const item = try list.allocator.dupeZ(u8, mem.sliceTo(name, 0)); + errdefer list.allocator.free(item); + try list.append(item); + } + } + }.callback); + return paths.toOwnedSlice(); + }, + .macos, .ios, .watchos, .tvos => { + var paths = List.init(allocator); + errdefer { + const slice = paths.toOwnedSlice(); + for (slice) |item| { + allocator.free(item); + } + allocator.free(slice); + } + const img_count = std.c._dyld_image_count(); + var i: u32 = 0; + while (i < img_count) : (i += 1) { + const name = std.c._dyld_get_image_name(i); + const item = try allocator.dupeZ(u8, mem.sliceTo(name, 0)); + errdefer allocator.free(item); + try paths.append(item); + } + return paths.toOwnedSlice(); + }, + // revisit if Haiku implements dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743) + .haiku => { + var paths = List.init(allocator); + errdefer { + const slice = paths.toOwnedSlice(); + for (slice) |item| { + allocator.free(item); + } + allocator.free(slice); + } + + var b = "/boot/system/runtime_loader"; + const item = try allocator.dupeZ(u8, mem.sliceTo(b, 0)); + errdefer allocator.free(item); + try paths.append(item); + + return paths.toOwnedSlice(); + }, + else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"), + } +} diff --git a/src/fs.zig b/src/fs.zig index e4a2268dc..78888dcd4 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -490,6 +490,15 @@ pub const FileSystem = struct { return try allocator.dupe(u8, joined); } + pub fn absAllocZ(f: *@This(), allocator: std.mem.Allocator, parts: anytype) ![*:0]const u8 { + const joined = path_handler.joinAbsString( + f.top_level_dir, + parts, + .auto, + ); + return try allocator.dupeZ(u8, joined); + } + pub fn abs(f: *@This(), parts: anytype) string { return path_handler.joinAbsString( f.top_level_dir, diff --git a/src/global.zig b/src/global.zig index 5bec684b0..25b908543 100644 --- a/src/global.zig +++ b/src/global.zig @@ -15,7 +15,7 @@ const root = @import("root"); pub const meta = @import("./meta.zig"); pub const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap; pub const base64 = @import("./base64/base64.zig"); - +pub const path = @import("./resolver/resolve_path.zig"); pub const fmt = struct { pub usingnamespace std.fmt; |