bake: csr, streaming ssr, serve integration, safer jsvalue functions, &more (#14900)

Co-authored-by: paperdave <paperdave@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
dave caruso
2024-11-13 18:19:12 -08:00
committed by GitHub
parent bceb0a2327
commit 32ddf343ee
89 changed files with 5382 additions and 2559 deletions

View File

@@ -691,6 +691,7 @@ pub const String = extern struct {
try self.toZigString().format(fmt, opts, writer);
}
/// Deprecated: use `fromJS2` to handle errors explicitly
pub fn fromJS(value: bun.JSC.JSValue, globalObject: *JSC.JSGlobalObject) String {
JSC.markBinding(@src());
@@ -702,6 +703,16 @@ pub const String = extern struct {
}
}
pub fn fromJS2(value: bun.JSC.JSValue, globalObject: *JSC.JSGlobalObject) bun.JSError!String {
var out: String = String.dead;
if (BunString__fromJS(globalObject, value, &out)) {
bun.assert(out.tag != .Dead);
return out;
} else {
return globalObject.jsErrorFromCPP();
}
}
pub fn fromJSRef(value: bun.JSC.JSValue, globalObject: *JSC.JSGlobalObject) String {
JSC.markBinding(@src());
@@ -1331,6 +1342,11 @@ pub const String = extern struct {
const width = str.visibleWidth(false);
return JSC.jsNumber(width);
}
// TODO: move ZigString.Slice here
/// A UTF-8 encoded slice tied to the lifetime of a `bun.String`
/// Must call `.deinit` to release memory
pub const Slice = ZigString.Slice;
};
pub const SliceWithUnderlyingString = struct {