Even More Comments

This commit is contained in:
Jarred Sumner
2022-04-13 04:44:05 -07:00
parent 3db3057d42
commit bb79687f8e
4 changed files with 58 additions and 8 deletions

View File

@@ -136,6 +136,7 @@ pub const ZigString = extern struct {
return @intToPtr([*]u8, @ptrToInt(this.ptr))[0..this.len];
}
/// Does nothing if the slice is not allocated
pub fn deinit(this: *const Slice) void {
if (!this.allocated) {
return;

View File

@@ -190,10 +190,9 @@ pub const Encoding = enum(u8) {
const Eight = strings.ExactSizeMatcher(8);
/// Caller must verify the value is a string
pub fn fromStringValue(value: JSC.JSValue, global: *JSC.JSGlobalObject) ?Encoding {
var str = JSC.ZigString.Empty;
value.toZigString(&str, global);
const slice = str.slice();
return from(slice);
var sliced = value.toSlice(global, bun.default_allocator);
defer sliced.deinit();
return from(sliced.slice());
}
/// Caller must verify the value is a string