diff options
author | 2023-06-01 18:02:41 -0700 | |
---|---|---|
committer | 2023-06-01 18:02:41 -0700 | |
commit | 42606d6aed323fa24b6783b24624e9f57cb9ef9d (patch) | |
tree | e7bb1239b6c070b9877f33aa8d430f1ad820e112 /src/bun.js/api/bun.zig | |
parent | c366b621606e3cb53f1c576d7e7bb53cdcb27f31 (diff) | |
download | bun-42606d6aed323fa24b6783b24624e9f57cb9ef9d.tar.gz bun-42606d6aed323fa24b6783b24624e9f57cb9ef9d.tar.zst bun-42606d6aed323fa24b6783b24624e9f57cb9ef9d.zip |
Rename `ptr` to `_unsafe_ptr_do_not_use` (#3163)
* Rename `ptr` to `_unsafe_ptr_do_not_use`
* Fixup
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/api/bun.zig')
-rw-r--r-- | src/bun.js/api/bun.zig | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index f4900d0d2..3e09075e7 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -486,18 +486,17 @@ pub fn getFilePath(ctx: js.JSContextRef, arguments: []const js.JSValueRef, buf: } const value = arguments[0]; - if (js.JSValueIsString(ctx, value)) { - var out = ZigString.Empty; - JSValue.toZigString(JSValue.fromRef(value), &out, ctx.ptr()); - var out_slice = out.slice(); + if (JSC.JSValue.c(value).isString()) { + const out = JSC.JSValue.c(value).toSlice(ctx, bun.default_allocator); + defer out.deinit(); // The dots are kind of unnecessary. They'll be normalized. - if (out.len == 0 or @ptrToInt(out.ptr) == 0 or std.mem.eql(u8, out_slice, ".") or std.mem.eql(u8, out_slice, "..") or std.mem.eql(u8, out_slice, "../")) { + if (out.len == 0 or std.mem.eql(u8, out.slice(), "..") or std.mem.eql(u8, out.slice(), "../")) { JSError(getAllocator(ctx), "Expected a file path as a string or an array of strings to be part of a file path.", .{}, ctx, exception); return null; } - var parts = [_]string{out_slice}; + var parts = [_]string{out.slice()}; // This does the equivalent of Node's path.normalize(path.join(cwd, out_slice)) var res = VirtualMachine.get().bundler.fs.absBuf(&parts, buf); @@ -522,8 +521,15 @@ pub fn getFilePath(ctx: js.JSContextRef, arguments: []const js.JSValueRef, buf: return null; } - var out = ZigString.Empty; - JSValue.toZigString(item, &out, ctx.ptr()); + const out = JSC.JSValue.c(value).toSlice(ctx, bun.default_allocator); + defer out.deinit(); + + // The dots are kind of unnecessary. They'll be normalized. + if (out.len == 0 or std.mem.eql(u8, out.slice(), "..") or std.mem.eql(u8, out.slice(), "../")) { + JSError(getAllocator(ctx), "Expected a file path as a string or an array of strings to be part of a file path.", .{}, ctx, exception); + return null; + } + const out_slice = out.slice(); temp_strings_list[temp_strings_list_len] = out_slice; @@ -2632,7 +2638,7 @@ pub const Unsafe = struct { switch (array_buffer.typed_array_type) { .Uint16Array, .Int16Array => { var zig_str = ZigString.init(""); - zig_str.ptr = @ptrCast([*]const u8, @alignCast(@alignOf([*]align(1) const u16), array_buffer.ptr)); + zig_str._unsafe_ptr_do_not_use = @ptrCast([*]const u8, @alignCast(@alignOf([*]align(1) const u16), array_buffer.ptr)); zig_str.len = array_buffer.len; zig_str.markUTF16(); // the deinitializer for string causes segfaults |