Fix JSON parsing failure

This commit is contained in:
Jarred Sumner
2022-03-18 20:54:09 -07:00
parent 7dc76bf709
commit d87ea9c88a
4 changed files with 33 additions and 1 deletions

View File

@@ -249,7 +249,14 @@ unsigned char JSC__JSValue__jsType(JSC__JSValue JSValue0)
JSC__JSValue JSC__JSValue__parseJSON(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1)
{
JSC::JSValue jsValue = JSC::JSValue::decode(JSValue0);
return JSC::JSValue::encode(JSC::JSONParse(arg1, jsValue.toWTFString(arg1)));
JSC::JSValue result = JSC::JSONParse(arg1, jsValue.toWTFString(arg1));
if (!result) {
result = JSC::JSValue(JSC::createSyntaxError(arg1->globalObject(), "Failed to parse JSON"));
}
return JSC::JSValue::encode(result);
}
void JSC__JSGlobalObject__deleteModuleRegistryEntry(JSC__JSGlobalObject* global, ZigString* arg1)

View File

@@ -2007,6 +2007,13 @@ pub const JSValue = enum(u64) {
else => false,
};
}
/// Empty as in "JSValue {}" rather than an empty string
pub fn isEmpty(this: JSValue) bool {
return switch (@enumToInt(this)) {
0 => true,
else => false,
};
}
pub fn isBoolean(this: JSValue) bool {
return cppFn("isBoolean", .{this});
}

View File

@@ -1708,6 +1708,9 @@ pub const Blob = struct {
value: JSC.JSValue,
global: *JSGlobalObject,
) JSC.JSValue {
if (value.isError()) {
return JSC.JSPromise.rejectedPromiseValue(global, value);
}
return JSC.JSPromise.resolvedPromiseValue(global, value);
}