This commit is contained in:
Jarred Sumner
2024-08-16 15:42:11 -07:00
committed by GitHub
parent babc907bfe
commit 64d77e33f6
7 changed files with 246 additions and 140 deletions

View File

@@ -360,3 +360,14 @@ extern "C" JSC::EncodedJSValue WebCore__CommonAbortReason__toJS(JSC::JSGlobalObj
{
return JSC::JSValue::encode(WebCore::toJS(globalObject, abortReason));
}
JSC::JSObject* Bun::createInvalidThisError(JSC::JSGlobalObject* globalObject, JSC::JSValue thisValue, const ASCIILiteral typeName)
{
if (thisValue.isEmpty() || thisValue.isUndefined()) {
return Bun::createError(globalObject, Bun::ErrorCode::ERR_INVALID_THIS, makeString("Expected this to be instanceof "_s, typeName));
}
// Pathological case: the this value returns a string which is extremely long or causes an out of memory error.
const auto& typeString = thisValue.isString() ? String("a string"_s) : JSC::errorDescriptionForValue(globalObject, thisValue);
return Bun::createError(globalObject, Bun::ErrorCode::ERR_INVALID_THIS, makeString("Expected this to be instanceof "_s, typeName, ", but received "_s, typeString));
}