mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 13:51:47 +00:00
make node:buffer,zlib,stream,fs exception checker clear (#20494)
This commit is contained in:
@@ -134,20 +134,25 @@ static OnLoadResult handleOnLoadObjectResult(Zig::GlobalObject* globalObject, JS
|
||||
OnLoadResult result {};
|
||||
result.type = OnLoadResultTypeObject;
|
||||
auto& vm = JSC::getVM(globalObject);
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
auto& builtinNames = WebCore::builtinNames(vm);
|
||||
if (JSC::JSValue exportsValue = object->getIfPropertyExists(globalObject, builtinNames.exportsPublicName())) {
|
||||
auto exportsValue = object->getIfPropertyExists(globalObject, builtinNames.exportsPublicName());
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
return result;
|
||||
}
|
||||
if (exportsValue) {
|
||||
if (exportsValue.isObject()) {
|
||||
result.value.object = exportsValue;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
scope.throwException(globalObject, createTypeError(globalObject, "\"object\" loader must return an \"exports\" object"_s));
|
||||
result.type = OnLoadResultTypeError;
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
scope.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -225,11 +230,18 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::
|
||||
scope.throwException(globalObject, JSC::createError(globalObject, "Expected module mock to return an object"_s));
|
||||
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
result.type = OnLoadResultTypeError;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (JSC::JSValue loaderValue = object->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "loader"_s))) {
|
||||
auto loaderValue = object->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "loader"_s));
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
return result;
|
||||
}
|
||||
if (loaderValue) {
|
||||
if (!loaderValue.isUndefinedOrNull()) {
|
||||
// If a loader is passed, we must validate it
|
||||
loader = BunLoaderTypeNone;
|
||||
@@ -258,6 +270,7 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::
|
||||
if (loader == BunLoaderTypeNone) [[unlikely]] {
|
||||
throwException(globalObject, scope, createError(globalObject, "Expected loader to be one of \"js\", \"jsx\", \"object\", \"ts\", \"tsx\", \"toml\", or \"json\""_s));
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -265,7 +278,13 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::
|
||||
result.value.sourceText.value = JSValue {};
|
||||
result.value.sourceText.string = {};
|
||||
|
||||
if (JSC::JSValue contentsValue = object->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "contents"_s))) {
|
||||
auto contentsValue = object->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "contents"_s));
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
return result;
|
||||
}
|
||||
if (contentsValue) {
|
||||
if (contentsValue.isString()) {
|
||||
if (JSC::JSString* contentsJSString = contentsValue.toStringOrNull(globalObject)) {
|
||||
result.value.sourceText.string = Zig::toZigString(contentsJSString, globalObject);
|
||||
@@ -280,6 +299,7 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::
|
||||
if (result.value.sourceText.value.isEmpty()) [[unlikely]] {
|
||||
throwException(globalObject, scope, createError(globalObject, "Expected \"contents\" to be a string or an ArrayBufferView"_s));
|
||||
result.value.error = scope.exception();
|
||||
scope.clearException();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -372,11 +392,15 @@ static JSValue handleVirtualModuleResult(
|
||||
JSC::JSObject* object = onLoadResult.value.object.getObject();
|
||||
if (commonJSModule) {
|
||||
const auto& __esModuleIdentifier = vm.propertyNames->__esModule;
|
||||
JSValue esModuleValue = object->getIfPropertyExists(globalObject, __esModuleIdentifier);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
auto esModuleValue = object->getIfPropertyExists(globalObject, __esModuleIdentifier);
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
return reject(scope.exception());
|
||||
}
|
||||
if (esModuleValue && esModuleValue.toBoolean(globalObject)) {
|
||||
JSValue defaultValue = object->getIfPropertyExists(globalObject, vm.propertyNames->defaultKeyword);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
auto defaultValue = object->getIfPropertyExists(globalObject, vm.propertyNames->defaultKeyword);
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
return reject(scope.exception());
|
||||
}
|
||||
if (defaultValue && !defaultValue.isUndefined()) {
|
||||
commonJSModule->setExportsObject(defaultValue);
|
||||
commonJSModule->hasEvaluated = true;
|
||||
@@ -715,6 +739,7 @@ JSValue fetchCommonJSModule(
|
||||
}
|
||||
|
||||
JSMap* registry = globalObject->esmRegistryMap();
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
|
||||
bool hasAlreadyLoadedESMVersionSoWeShouldntTranspileItTwice = [&]() -> bool {
|
||||
JSValue entry = registry->get(globalObject, specifierValue);
|
||||
@@ -921,6 +946,7 @@ static JSValue fetchESMSourceCode(
|
||||
scope.clearException();
|
||||
return rejectedInternalPromise(globalObject, exception);
|
||||
} else {
|
||||
scope.release();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -984,6 +1010,7 @@ static JSValue fetchESMSourceCode(
|
||||
scope.clearException();
|
||||
return rejectedInternalPromise(globalObject, exception);
|
||||
} else {
|
||||
scope.release();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -1009,7 +1036,7 @@ static JSValue fetchESMSourceCode(
|
||||
if (res->result.value.tag == SyntheticModuleType::JSONForObjectLoader) {
|
||||
WTF::String jsonSource = res->result.value.source_code.toWTFString(BunString::NonNull);
|
||||
JSC::JSValue value = JSC::JSONParseWithException(globalObject, jsonSource);
|
||||
if (scope.exception()) {
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
auto* exception = scope.exception();
|
||||
scope.clearException();
|
||||
return reject(exception);
|
||||
@@ -1109,7 +1136,7 @@ BUN_DEFINE_HOST_FUNCTION(jsFunctionOnLoadObjectResultResolve, (JSC::JSGlobalObje
|
||||
|
||||
JSC::JSValue result = handleVirtualModuleResult<false>(reinterpret_cast<Zig::GlobalObject*>(globalObject), objectResult, &res, &specifier, &referrer, wasModuleMock);
|
||||
if (res.success) {
|
||||
if (scope.exception()) {
|
||||
if (scope.exception()) [[unlikely]] {
|
||||
auto retValue = JSValue::encode(promise->rejectWithCaughtException(globalObject, scope));
|
||||
pendingModule->internalField(2).set(vm, pendingModule, JSC::jsUndefined());
|
||||
return retValue;
|
||||
|
||||
Reference in New Issue
Block a user