Skip to content

Commit 89fb624

Browse files
committed
Fix crash from checking if something is an object when it is undefined
1 parent 6bcaa33 commit 89fb624

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/javascript/jsc/bindings/bindings.zig

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,9 @@ pub const JSValue = enum(u64) {
18651865
}
18661866

18671867
pub fn as(value: JSValue, comptime ZigType: type) ?*ZigType {
1868+
if (value.isUndefinedOrNull())
1869+
return null;
1870+
18681871
return JSC.GetJSPrivateData(ZigType, value.asObjectRef());
18691872
}
18701873

@@ -1977,13 +1980,16 @@ pub const JSValue = enum(u64) {
19771980
}
19781981

19791982
pub fn isUndefined(this: JSValue) bool {
1980-
return cppFn("isUndefined", .{this});
1983+
return @enumToInt(this) == 0xa;
19811984
}
19821985
pub fn isNull(this: JSValue) bool {
1983-
return cppFn("isNull", .{this});
1986+
return @enumToInt(this) == 0x2;
19841987
}
19851988
pub fn isUndefinedOrNull(this: JSValue) bool {
1986-
return cppFn("isUndefinedOrNull", .{this});
1989+
return switch (@enumToInt(this)) {
1990+
0xa, 0x2 => true,
1991+
else => false,
1992+
};
19871993
}
19881994
pub fn isBoolean(this: JSValue) bool {
19891995
return cppFn("isBoolean", .{this});
@@ -2285,7 +2291,7 @@ pub const JSValue = enum(u64) {
22852291
return @intToPtr(*anyopaque, @enumToInt(this));
22862292
}
22872293

2288-
pub const Extern = [_][]const u8{ "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "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", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isUndefined", "isNull", "isUndefinedOrNull", "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" };
2294+
pub const Extern = [_][]const u8{ "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "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", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "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" };
22892295
};
22902296

22912297
extern "c" fn Microtask__run(*Microtask, *JSGlobalObject) void;

src/javascript/jsc/bindings/headers-cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-- AUTOGENERATED FILE -- 1647432636
1+
//-- AUTOGENERATED FILE -- 1647445628
22
// clang-format off
33
#pragma once
44

src/javascript/jsc/bindings/headers.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// clang-format: off
2-
//-- AUTOGENERATED FILE -- 1647432636
2+
//-- AUTOGENERATED FILE -- 1647445628
33
#pragma once
44

55
#include <stddef.h>
@@ -467,7 +467,6 @@ CPP_DECL bool JSC__JSValue__isHeapBigInt(JSC__JSValue JSValue0);
467467
CPP_DECL bool JSC__JSValue__isInt32(JSC__JSValue JSValue0);
468468
CPP_DECL bool JSC__JSValue__isInt32AsAnyInt(JSC__JSValue JSValue0);
469469
CPP_DECL bool JSC__JSValue__isIterable(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
470-
CPP_DECL bool JSC__JSValue__isNull(JSC__JSValue JSValue0);
471470
CPP_DECL bool JSC__JSValue__isNumber(JSC__JSValue JSValue0);
472471
CPP_DECL bool JSC__JSValue__isObject(JSC__JSValue JSValue0);
473472
CPP_DECL bool JSC__JSValue__isPrimitive(JSC__JSValue JSValue0);
@@ -476,8 +475,6 @@ CPP_DECL bool JSC__JSValue__isString(JSC__JSValue JSValue0);
476475
CPP_DECL bool JSC__JSValue__isSymbol(JSC__JSValue JSValue0);
477476
CPP_DECL bool JSC__JSValue__isTerminationException(JSC__JSValue JSValue0, JSC__VM* arg1);
478477
CPP_DECL bool JSC__JSValue__isUInt32AsAnyInt(JSC__JSValue JSValue0);
479-
CPP_DECL bool JSC__JSValue__isUndefined(JSC__JSValue JSValue0);
480-
CPP_DECL bool JSC__JSValue__isUndefinedOrNull(JSC__JSValue JSValue0);
481478
CPP_DECL JSC__JSValue JSC__JSValue__jsBoolean(bool arg0);
482479
CPP_DECL JSC__JSValue JSC__JSValue__jsDoubleNumber(double arg0);
483480
CPP_DECL JSC__JSValue JSC__JSValue__jsNull();

src/javascript/jsc/bindings/headers.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ pub extern fn JSC__JSValue__isHeapBigInt(JSValue0: JSC__JSValue) bool;
315315
pub extern fn JSC__JSValue__isInt32(JSValue0: JSC__JSValue) bool;
316316
pub extern fn JSC__JSValue__isInt32AsAnyInt(JSValue0: JSC__JSValue) bool;
317317
pub extern fn JSC__JSValue__isIterable(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) bool;
318-
pub extern fn JSC__JSValue__isNull(JSValue0: JSC__JSValue) bool;
319318
pub extern fn JSC__JSValue__isNumber(JSValue0: JSC__JSValue) bool;
320319
pub extern fn JSC__JSValue__isObject(JSValue0: JSC__JSValue) bool;
321320
pub extern fn JSC__JSValue__isPrimitive(JSValue0: JSC__JSValue) bool;
@@ -324,8 +323,6 @@ pub extern fn JSC__JSValue__isString(JSValue0: JSC__JSValue) bool;
324323
pub extern fn JSC__JSValue__isSymbol(JSValue0: JSC__JSValue) bool;
325324
pub extern fn JSC__JSValue__isTerminationException(JSValue0: JSC__JSValue, arg1: [*c]JSC__VM) bool;
326325
pub extern fn JSC__JSValue__isUInt32AsAnyInt(JSValue0: JSC__JSValue) bool;
327-
pub extern fn JSC__JSValue__isUndefined(JSValue0: JSC__JSValue) bool;
328-
pub extern fn JSC__JSValue__isUndefinedOrNull(JSValue0: JSC__JSValue) bool;
329326
pub extern fn JSC__JSValue__jsBoolean(arg0: bool) JSC__JSValue;
330327
pub extern fn JSC__JSValue__jsDoubleNumber(arg0: f64) JSC__JSValue;
331328
pub extern fn JSC__JSValue__jsNull(...) JSC__JSValue;

0 commit comments

Comments
 (0)