Skip to content

Commit

Permalink
[bun.js] GC more strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Jul 13, 2022
1 parent dd7a346 commit b37ffde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,11 +1261,11 @@ JSC__JSValue ZigString__external(const ZigString* arg0, JSC__JSGlobalObject* arg
ZigString str
= *arg0;
if (Zig::isTaggedUTF16Ptr(str.ptr)) {
return JSC::JSValue::encode(JSC::JSValue(JSC::jsOwnedString(
return JSC::JSValue::encode(JSC::JSValue(JSC::jsString(
arg1->vm(),
WTF::String(ExternalStringImpl::create(reinterpret_cast<const UChar*>(Zig::untag(str.ptr)), str.len, arg2, ArgFn3)))));
} else {
return JSC::JSValue::encode(JSC::JSValue(JSC::jsOwnedString(
return JSC::JSValue::encode(JSC::JSValue(JSC::jsString(
arg1->vm(),
WTF::String(ExternalStringImpl::create(reinterpret_cast<const LChar*>(Zig::untag(str.ptr)), str.len, arg2, ArgFn3)))));
}
Expand Down
8 changes: 6 additions & 2 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ pub const JSValue = enum(JSValueReprInt) {
return JSC.C.JSObjectCallAsFunctionReturnValue(
globalThis.ref(),
this.asObjectRef(),
thisValue.asObjectRef(),
@ptrCast(JSC.C.JSValueRef, thisValue.asNullableVoid()),
args.len,
@ptrCast([*]const JSC.C.JSValueRef, args.ptr),
);
Expand Down Expand Up @@ -2905,13 +2905,17 @@ pub const JSValue = enum(JSValueReprInt) {
std.mem.doNotOptimizeAway(@ptrCast(C_API.JSObjectRef, this.asVoid()));
}

pub inline fn asNullableVoid(this: JSValue) ?*anyopaque {
return @intToPtr(?*anyopaque, @bitCast(usize, @enumToInt(this)));
}

pub inline fn asVoid(this: JSValue) *anyopaque {
if (comptime bun.Environment.allow_assert) {
if (@enumToInt(this) == 0) {
@panic("JSValue is null");
}
}
return @intToPtr(*anyopaque, @bitCast(usize, @enumToInt(this)));
return this.asNullableVoid().?;
}

pub const Extern = [_][]const u8{ "createUninitializedUint8Array", "fromInt64NoTruncate", "fromUInt64NoTruncate", "toUInt64NoTruncate", "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
Expand Down

0 comments on commit b37ffde

Please sign in to comment.