[internal] Introduce JSPromise.Strong

This commit is contained in:
Jarred Sumner
2022-11-19 04:57:59 -08:00
parent d6d04cab24
commit 6cc89eff2c

View File

@@ -1472,6 +1472,30 @@ pub const JSPromise = extern struct {
Rejected = 2,
};
pub const Strong = struct {
strong: JSC.Strong = .{},
pub fn init(globalThis: *JSC.JSGlobalObject) Strong {
return Strong{
.strong = JSC.Strong.create(globalThis, JSC.JSPromise.create(globalThis).asValue(globalThis)),
};
}
pub fn get(this: *Strong) *JSC.JSPromise {
return this.strong.get().?.asPromise().?;
}
pub fn value(this: *Strong) JSValue {
return this.strong.get().?;
}
pub fn swap(this: *Strong) *JSC.JSPromise {
var prom = this.strong.swap().asPromise().?;
this.strong.deinit();
return prom;
}
};
pub fn wrap(
globalObject: *JSGlobalObject,
value: JSValue,