Make toBunString increment the reference count (#8146)

* Make `toBunString` increment the reference count

* Fix WASI

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2024-01-14 05:36:31 -08:00
committed by GitHub
parent ab40b0e054
commit 317998fdd6
24 changed files with 146 additions and 53 deletions

View File

@@ -496,6 +496,7 @@ pub const String = extern struct {
}
pub fn toErrorInstance(this: *const String, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
defer this.deref();
return JSC__createError(globalObject, this);
}
@@ -1138,15 +1139,14 @@ pub const String = extern struct {
}
pub export fn BunString__getStringWidth(globalObject: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
var str: String = String.dead;
const args = callFrame.arguments(1).slice();
if (args.len == 0 or !args.ptr[0].isString()) {
return JSC.jsNumber(@as(i32, 0));
}
str = args[0].toBunString(globalObject);
const str = args[0].toBunString(globalObject);
defer str.deref();
if (str.isEmpty()) {
return JSC.jsNumber(@as(i32, 0));