Bug 1791292 - Expose nsresult for file-not-found error. r=jonco

Differential Revision: https://phabricator.services.mozilla.com/D157700
This commit is contained in:
Tooru Fujisawa 2022-09-21 23:58:54 +00:00
Родитель 6a17046678
Коммит b270506fd9
2 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -9,6 +9,9 @@
#include "nsISupportsImpl.h"
#include "js/loader/ModuleLoadRequest.h"
#include "js/RootingAPI.h" // JS::Rooted
#include "js/PropertyAndElement.h" // JS_SetProperty
#include "js/Value.h" // JS::Value, JS::NumberValue
#include "mozJSModuleLoader.h"
using namespace JS::loader;
@ -125,6 +128,17 @@ nsresult ComponentModuleLoader::StartFetch(ModuleLoadRequest* aRequest) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mLoadException.isObject()) {
// Expose `nsresult`.
JS::Rooted<JS::Value> resultVal(cx, JS::NumberValue(uint32_t(rv)));
JS::Rooted<JSObject*> exceptionObj(cx, &mLoadException.toObject());
if (!JS_SetProperty(cx, exceptionObj, "result", resultVal)) {
// Ignore the error and keep reporting the exception without the result
// property.
JS_ClearPendingException(cx);
}
}
return rv;
}

Просмотреть файл

@ -26,6 +26,7 @@ add_task(async function() {
stack: "testFailure",
lineNumber: "*",
columnNumber: "*",
result: Cr.NS_ERROR_FILE_NOT_FOUND,
});
// Test load failure in import.
@ -36,6 +37,7 @@ add_task(async function() {
stack: "testFailure",
lineNumber: "*",
columnNumber: "*",
result: Cr.NS_ERROR_FILE_NOT_FOUND,
});
// Test parse error.
@ -172,4 +174,7 @@ function checkException(exception, expected, importLine, importColumn) {
}
Assert.equal(exception.columnNumber, expectedColumn, "columnNumber");
}
if ("result" in expected) {
Assert.equal(exception.result, expected.result, "result");
}
}