diff options
author | 2023-07-03 13:47:37 -0700 | |
---|---|---|
committer | 2023-07-03 13:47:37 -0700 | |
commit | 424717a9737321a3f37f7596f62067d72cd97e25 (patch) | |
tree | 9f7d722f39c038cd9b62c08fa09581615eb17467 | |
parent | e5f93ddf55311a1e29f836676ce7b1a91a35eecb (diff) | |
download | bun-424717a9737321a3f37f7596f62067d72cd97e25.tar.gz bun-424717a9737321a3f37f7596f62067d72cd97e25.tar.zst bun-424717a9737321a3f37f7596f62067d72cd97e25.zip |
Fixes #3317
-rw-r--r-- | src/bun.js/bindings/napi.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index bb62cb2a0..5d7204285 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -1539,8 +1539,10 @@ extern "C" napi_status napi_typeof(napi_env env, napi_value val, JSC::JSValue value = toJS(val); - if (UNLIKELY(value.isEmpty())) { - return napi_invalid_arg; + if (value.isEmpty()) { + // This can happen + *result = napi_undefined; + return napi_ok; } if (value.isCell()) { @@ -1579,17 +1581,18 @@ extern "C" napi_status napi_typeof(napi_env env, napi_value val, *result = napi_object; return napi_ok; - default: - if (cell->isObject()) { - *result = napi_object; + default: { + if (cell->isCallable() || cell->isConstructor()) { + *result = napi_function; return napi_ok; } - if (cell->isCallable() || cell->isConstructor()) { - *result = napi_function; + if (cell->isObject()) { + *result = napi_object; return napi_ok; } } + } } if (value.isNumber()) { |