aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/javascript/jsc/api/transpiler.zig8
-rw-r--r--src/javascript/jsc/bindings/bindings.zig12
-rw-r--r--src/javascript/jsc/bindings/helpers.h12
3 files changed, 14 insertions, 18 deletions
diff --git a/src/javascript/jsc/api/transpiler.zig b/src/javascript/jsc/api/transpiler.zig
index cdc5dc39a..0390be154 100644
--- a/src/javascript/jsc/api/transpiler.zig
+++ b/src/javascript/jsc/api/transpiler.zig
@@ -203,13 +203,11 @@ pub const TransformTask = struct {
if (printed > 0) {
buffer_writer = printer.ctx;
- buffer_writer.buffer.list.expandToCapacity();
+ buffer_writer.buffer.list.items = buffer_writer.written;
// This works around a mimalloc and/or Zig allocator bug
- buffer_writer.buffer.list.items = buffer_writer.buffer.list.items[0..printed];
- var output_code = JSC.ZigString.init(buffer_writer.buffer.toOwnedSlice());
- output_code.mark();
- this.output_code = output_code;
+ this.output_code = JSC.ZigString.init(buffer_writer.written);
+ this.output_code.mark();
} else {
this.output_code = ZigString.init("");
}
diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig
index f7b270a40..6c7cbd523 100644
--- a/src/javascript/jsc/bindings/bindings.zig
+++ b/src/javascript/jsc/bindings/bindings.zig
@@ -97,7 +97,7 @@ pub const ZigString = extern struct {
}
pub inline fn utf16Slice(this: *const ZigString) []align(1) const u16 {
- return @ptrCast([*]align(1) const u16, this.ptr)[0..this.len];
+ return @ptrCast([*]align(1) const u16, untagged(this.ptr))[0..this.len];
}
pub fn fromStringPointer(ptr: StringPointer, buf: string, to: *ZigString) void {
@@ -163,8 +163,14 @@ pub const ZigString = extern struct {
pub const Empty = ZigString{ .ptr = "", .len = 0 };
+ inline fn untagged(ptr: [*]const u8) [*]const u8 {
+ // this can be null ptr, so long as it's also a 0 length string
+ @setRuntimeSafety(false);
+ return @intToPtr([*]const u8, @truncate(u53, @ptrToInt(ptr)));
+ }
+
pub fn slice(this: *const ZigString) []const u8 {
- return this.ptr[0..@minimum(this.len, std.math.maxInt(u32))];
+ return untagged(this.ptr)[0..@minimum(this.len, std.math.maxInt(u32))];
}
pub fn sliceZBuf(this: ZigString, buf: *[std.fs.MAX_PATH_BYTES]u8) ![:0]const u8 {
@@ -172,7 +178,7 @@ pub const ZigString = extern struct {
}
pub inline fn full(this: *const ZigString) []const u8 {
- return this.ptr[0..this.len];
+ return untagged(this.ptr)[0..this.len];
}
pub fn trimmedSlice(this: *const ZigString) []const u8 {
diff --git a/src/javascript/jsc/bindings/helpers.h b/src/javascript/jsc/bindings/helpers.h
index 1c1237969..9aa1c218a 100644
--- a/src/javascript/jsc/bindings/helpers.h
+++ b/src/javascript/jsc/bindings/helpers.h
@@ -90,19 +90,11 @@ static const WTF::String toString(ZigString str) {
}
static const WTF::String toStringCopy(ZigString str) {
- if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); }
-
- return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(str.ptr, str.len))
- : WTF::String(WTF::StringImpl::create(
- reinterpret_cast<const UChar *>(str.ptr), str.len));
+ return toString(str).isolatedCopy();
}
static WTF::String toStringNotConst(ZigString str) {
- if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); }
-
- return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(str.ptr, str.len))
- : WTF::String(WTF::StringImpl::create(
- reinterpret_cast<const UChar *>(str.ptr), str.len));
+ return toString(str).isolatedCopy();
}
static const JSC::JSString *toJSString(ZigString str, JSC::JSGlobalObject *global) {