mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Fix crash in CJS (#3294)
* Fix crash in CJS * Add std.heap.ArenaAllocator * Use our arena allocator * Reduce JS parser memory usage and make HMR faster * Write some comments * fix test failure & clean up this code * Update javascript.zig * make arena usage safer --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -239,6 +239,17 @@ pub const String = extern struct {
|
||||
pub const dead = String{ .tag = .Dead, .value = .{ .Dead = {} } };
|
||||
pub const StringImplAllocator = Parent.StringImplAllocator;
|
||||
|
||||
extern fn BunString__fromLatin1(bytes: [*]const u8, len: usize) String;
|
||||
extern fn BunString__fromBytes(bytes: [*]const u8, len: usize) String;
|
||||
|
||||
pub fn createLatin1(bytes: []const u8) String {
|
||||
return BunString__fromLatin1(bytes.ptr, bytes.len);
|
||||
}
|
||||
|
||||
pub fn create(bytes: []const u8) String {
|
||||
return BunString__fromBytes(bytes.ptr, bytes.len);
|
||||
}
|
||||
|
||||
pub fn initWithType(comptime Type: type, value: Type) String {
|
||||
switch (comptime Type) {
|
||||
ZigString => return String{ .tag = .ZigString, .value = .{ .ZigString = value } },
|
||||
@@ -273,6 +284,18 @@ pub const String = extern struct {
|
||||
return initWithType(@TypeOf(value), value);
|
||||
}
|
||||
|
||||
extern fn BunString__createExternal(
|
||||
bytes: [*]const u8,
|
||||
len: usize,
|
||||
isLatin1: bool,
|
||||
ptr: ?*anyopaque,
|
||||
callback: ?*const fn (*anyopaque, *anyopaque, u32) callconv(.C) void,
|
||||
) String;
|
||||
|
||||
pub fn createExternal(bytes: []const u8, isLatin1: bool, ctx: ?*anyopaque, callback: ?*const fn (*anyopaque, *anyopaque, u32) callconv(.C) void) String {
|
||||
return BunString__createExternal(bytes.ptr, bytes.len, isLatin1, ctx, callback);
|
||||
}
|
||||
|
||||
pub fn fromUTF8(value: []const u8) String {
|
||||
return String.initWithType(ZigString, ZigString.initUTF8(value));
|
||||
}
|
||||
@@ -339,7 +362,7 @@ pub const String = extern struct {
|
||||
if (self.tag == .Empty)
|
||||
return &[_]u16{};
|
||||
std.debug.assert(self.tag == .WTFStringImpl);
|
||||
return self.value.WTFStringImpl.utf16();
|
||||
return self.value.WTFStringImpl.utf16Slice();
|
||||
}
|
||||
|
||||
pub inline fn latin1(self: String) []const u8 {
|
||||
@@ -347,7 +370,7 @@ pub const String = extern struct {
|
||||
return &[_]u8{};
|
||||
|
||||
std.debug.assert(self.tag == .WTFStringImpl);
|
||||
return self.value.WTFStringImpl.latin1();
|
||||
return self.value.WTFStringImpl.latin1Slice();
|
||||
}
|
||||
|
||||
pub fn isUTF8(self: String) bool {
|
||||
|
||||
Reference in New Issue
Block a user