diff options
author | 2023-02-08 17:18:02 -0800 | |
---|---|---|
committer | 2023-02-08 17:18:02 -0800 | |
commit | ddec9e0bf639ae2f672c71c228759f741f805735 (patch) | |
tree | b07007dfd5716525761f08394e3092ee70efac34 | |
parent | 4962bea4fc269e537a8f505e2484d1bb289b8d9f (diff) | |
download | bun-ddec9e0bf639ae2f672c71c228759f741f805735.tar.gz bun-ddec9e0bf639ae2f672c71c228759f741f805735.tar.zst bun-ddec9e0bf639ae2f672c71c228759f741f805735.zip |
handle more cases with util.isErrorbun-v0.5.6
-rw-r--r-- | src/bun.js/bindings/node_util_types.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/util.exports.js | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/bun.js/bindings/node_util_types.cpp b/src/bun.js/bindings/node_util_types.cpp index 54fcca78b..bf135ed0b 100644 --- a/src/bun.js/bindings/node_util_types.cpp +++ b/src/bun.js/bindings/node_util_types.cpp @@ -84,7 +84,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSymbolObject, (JSC::JSGlobalObject * global JSC_DEFINE_HOST_FUNCTION(jsFunctionIsNativeError, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe)) { GET_FIRST_VALUE - return JSValue::encode(jsBoolean(value.isCell() && jsDynamicCast<ErrorInstance*>(value) != nullptr)); + return JSValue::encode(jsBoolean(value.isCell() && (value.inherits<JSC::ErrorInstance>() || value.asCell()->type() == ErrorInstanceType))); } JSC_DEFINE_HOST_FUNCTION(jsFunctionIsRegExp, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe)) { diff --git a/src/bun.js/util.exports.js b/src/bun.js/util.exports.js index c0adc0344..ce618784d 100644 --- a/src/bun.js/util.exports.js +++ b/src/bun.js/util.exports.js @@ -3,11 +3,16 @@ var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; + +function isBufferInterface({ copy, fill, readUint8 }) { + return typeof copy === "function" && typeof fill === "function" && typeof readUint8 === "function"; +} + export function isBuffer(value) { return ( Buffer.isBuffer(value) || // incase it ends up as a browserify buffer - (typeof arg?.copy === "function" && typeof arg?.fill === "function" && typeof arg?.readUInt8 === "function") + (typeof value === "object" && isBufferInterface(value || {})) ); } |