aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/bindings/bindings.cpp2
-rw-r--r--src/bun.js/bindings/bindings.zig27
-rw-r--r--src/bun.js/bindings/headers-cpp.h2
-rw-r--r--src/bun.js/bindings/headers.h4
-rw-r--r--src/bun.js/bindings/headers.zig2
-rw-r--r--src/bun.js/node/node_fs.zig42
6 files changed, 55 insertions, 24 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index e971a74a9..02a79c1b0 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -1764,7 +1764,7 @@ CPP_DECL void JSC__JSValue__putIndex(JSC__JSValue JSValue0, JSC__JSGlobalObject*
array->putDirectIndex(arg1, arg2, value2);
}
-JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* globalObject, ZigString* arg1,
+JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* globalObject, const ZigString* arg1,
size_t arg2, bool clone)
{
JSC::VM& vm = globalObject->vm();
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index aa051e712..0c1f21bba 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -108,6 +108,27 @@ pub const ZigString = extern struct {
};
}
+ pub fn dupeForJS(utf8: []const u8, allocator: std.mem.Allocator) !ZigString {
+ if (try strings.toUTF16Alloc(allocator, utf8, false)) |utf16| {
+ var out = ZigString.init16(utf16);
+ out.mark();
+ out.markUTF16();
+ return out;
+ } else {
+ var out = ZigString.init(try allocator.dupe(u8, utf8));
+ out.mark();
+ return out;
+ }
+ }
+
+ pub fn toJS(this: ZigString, ctx: *JSC.JSGlobalObject, _: JSC.C.ExceptionRef) JSValue {
+ if (this.isGloballyAllocated()) {
+ return this.toExternalValue(ctx);
+ }
+
+ return this.toValueAuto(ctx);
+ }
+
/// This function is not optimized!
pub fn eqlCaseInsensitive(this: ZigString, other: ZigString) bool {
var fallback = std.heap.stackFallback(1024, bun.default_allocator);
@@ -519,7 +540,9 @@ pub const ZigString = extern struct {
bun.default_allocator.free(this.slice());
}
- pub inline fn mark(this: *ZigString) void {
+ pub const mark = markGlobal;
+
+ pub inline fn markGlobal(this: *ZigString) void {
this.ptr = @intToPtr([*]const u8, @ptrToInt(this.ptr) | (1 << 62));
}
@@ -2937,7 +2960,7 @@ pub const JSValue = enum(JSValueReprInt) {
return str;
}
- pub fn createStringArray(globalThis: *JSGlobalObject, str: [*c]ZigString, strings_count: usize, clone: bool) JSValue {
+ pub fn createStringArray(globalThis: *JSGlobalObject, str: [*c]const ZigString, strings_count: usize, clone: bool) JSValue {
return cppFn("createStringArray", .{
globalThis,
str,
diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h
index f13fba3d3..f1e7de1dd 100644
--- a/src/bun.js/bindings/headers-cpp.h
+++ b/src/bun.js/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1674373581
+//-- AUTOGENERATED FILE -- 1674546420
// clang-format off
#pragma once
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index 836c7d46e..2d0f567d8 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1674373581
+//-- AUTOGENERATED FILE -- 1674546420
#pragma once
#include <stddef.h>
@@ -260,7 +260,7 @@ CPP_DECL JSC__JSValue JSC__JSValue__createInternalPromise(JSC__JSGlobalObject* a
CPP_DECL JSC__JSValue JSC__JSValue__createObject2(JSC__JSGlobalObject* arg0, const ZigString* arg1, const ZigString* arg2, JSC__JSValue JSValue3, JSC__JSValue JSValue4);
CPP_DECL JSC__JSValue JSC__JSValue__createRangeError(const ZigString* arg0, const ZigString* arg1, JSC__JSGlobalObject* arg2);
CPP_DECL JSC__JSValue JSC__JSValue__createRopeString(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2);
-CPP_DECL JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* arg0, ZigString* arg1, size_t arg2, bool arg3);
+CPP_DECL JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* arg0, const ZigString* arg1, size_t arg2, bool arg3);
CPP_DECL JSC__JSValue JSC__JSValue__createTypeError(const ZigString* arg0, const ZigString* arg1, JSC__JSGlobalObject* arg2);
CPP_DECL JSC__JSValue JSC__JSValue__createUninitializedUint8Array(JSC__JSGlobalObject* arg0, size_t arg1);
CPP_DECL bool JSC__JSValue__deepEquals(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2);
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index 207327b67..f28a765fe 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -185,7 +185,7 @@ pub extern fn JSC__JSValue__createInternalPromise(arg0: *bindings.JSGlobalObject
pub extern fn JSC__JSValue__createObject2(arg0: *bindings.JSGlobalObject, arg1: [*c]const ZigString, arg2: [*c]const ZigString, JSValue3: JSC__JSValue, JSValue4: JSC__JSValue) JSC__JSValue;
pub extern fn JSC__JSValue__createRangeError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__JSValue__createRopeString(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: *bindings.JSGlobalObject) JSC__JSValue;
-pub extern fn JSC__JSValue__createStringArray(arg0: *bindings.JSGlobalObject, arg1: [*c]ZigString, arg2: usize, arg3: bool) JSC__JSValue;
+pub extern fn JSC__JSValue__createStringArray(arg0: *bindings.JSGlobalObject, arg1: [*c]const ZigString, arg2: usize, arg3: bool) JSC__JSValue;
pub extern fn JSC__JSValue__createTypeError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__JSValue__createUninitializedUint8Array(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue;
pub extern fn JSC__JSValue__deepEquals(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: *bindings.JSGlobalObject) bool;
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig
index 5f36532ca..53f128a2b 100644
--- a/src/bun.js/node/node_fs.zig
+++ b/src/bun.js/node/node_fs.zig
@@ -866,14 +866,23 @@ const Arguments = struct {
};
const MkdirTemp = struct {
- prefix: string = "",
+ prefix: JSC.Node.SliceOrBuffer = .{ .buffer = .{ .buffer = JSC.ArrayBuffer.empty } },
encoding: Encoding = Encoding.utf8,
pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?MkdirTemp {
const prefix_value = arguments.next() orelse return MkdirTemp{};
- var prefix = JSC.ZigString.Empty;
- prefix_value.toZigString(&prefix, ctx.ptr());
+ var prefix = JSC.Node.SliceOrBuffer.fromJS(ctx, arguments.arena.allocator(), prefix_value) orelse {
+ if (exception.* == null) {
+ JSC.throwInvalidArguments(
+ "prefix must be a string or TypedArray",
+ .{},
+ ctx,
+ exception,
+ );
+ }
+ return null;
+ };
if (exception.* != null) return null;
@@ -899,7 +908,7 @@ const Arguments = struct {
}
return MkdirTemp{
- .prefix = prefix.slice(),
+ .prefix = prefix,
.encoding = encoding,
};
}
@@ -2241,7 +2250,7 @@ const Return = struct {
pub const Link = void;
pub const Lstat = Stats;
pub const Mkdir = string;
- pub const Mkdtemp = PathString;
+ pub const Mkdtemp = JSC.ZigString;
pub const Open = FileDescriptor;
pub const WriteFile = void;
pub const Read = struct {
@@ -2313,7 +2322,7 @@ const Return = struct {
pub const Readdir = union(Tag) {
with_file_types: []Dirent,
buffers: []const Buffer,
- files: []const PathString,
+ files: []const JSC.ZigString,
pub const Tag = enum {
with_file_types,
@@ -2325,7 +2334,7 @@ const Return = struct {
return switch (this) {
.with_file_types => JSC.To.JS.withType([]const Dirent, this.with_file_types, ctx, exception),
.buffers => JSC.To.JS.withType([]const Buffer, this.buffers, ctx, exception),
- .files => JSC.To.JS.withTypeClone([]const PathString, this.files, ctx, exception, true),
+ .files => JSC.To.JS.withType([]const JSC.ZigString, this.files, ctx, exception),
};
}
};
@@ -3004,9 +3013,10 @@ pub const NodeFS = struct {
pub fn mkdtemp(this: *NodeFS, args: Arguments.MkdirTemp, comptime _: Flavor) Maybe(Return.Mkdtemp) {
var prefix_buf = &this.sync_error_buf;
- const len = @min(args.prefix.len, prefix_buf.len - 7);
+ const prefix_slice = args.prefix.slice();
+ const len = @min(prefix_slice.len, prefix_buf.len -| 7);
if (len > 0) {
- @memcpy(prefix_buf, args.prefix.ptr, len);
+ @memcpy(prefix_buf, prefix_slice.ptr, len);
}
prefix_buf[len..][0..6].* = "XXXXXX".*;
prefix_buf[len..][6] = 0;
@@ -3018,7 +3028,7 @@ pub const NodeFS = struct {
}
return .{
- .result = PathString.init(bun.default_allocator.dupe(u8, std.mem.span(rc.?)) catch unreachable),
+ .result = JSC.ZigString.dupeForJS(bun.sliceTo(rc.?, 0), bun.default_allocator) catch unreachable,
};
}
pub fn open(this: *NodeFS, args: Arguments.Open, comptime flavor: Flavor) Maybe(Return.Open) {
@@ -3170,7 +3180,7 @@ pub const NodeFS = struct {
return _readdir(
this,
args,
- PathString,
+ JSC.ZigString,
flavor,
);
}
@@ -3193,7 +3203,7 @@ pub const NodeFS = struct {
) Maybe(Return.Readdir) {
const file_type = comptime switch (ExpectedType) {
Dirent => "with_file_types",
- PathString => "files",
+ JSC.ZigString => "files",
Buffer => "buffers",
else => unreachable,
};
@@ -3226,7 +3236,7 @@ pub const NodeFS = struct {
Buffer => {
item.destroy();
},
- PathString => {
+ JSC.ZigString => {
bun.default_allocator.free(item.slice());
},
else => unreachable,
@@ -3252,10 +3262,8 @@ pub const NodeFS = struct {
const slice = current.name.slice();
entries.append(Buffer.fromString(slice, bun.default_allocator) catch unreachable) catch unreachable;
},
- PathString => {
- entries.append(
- PathString.init(bun.default_allocator.dupe(u8, current.name.slice()) catch unreachable),
- ) catch unreachable;
+ JSC.ZigString => {
+ entries.append(JSC.ZigString.dupeForJS(current.name.slice(), bun.default_allocator) catch unreachable) catch unreachable;
},
else => unreachable,
}