зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1621916 - Provide a usable stack when requestFinished throws; r=dom-workers-and-storage-reviewers,sg,asuth
Differential Revision: https://phabricator.services.mozilla.com/D77217
This commit is contained in:
Родитель
bf2c33ba86
Коммит
e72a3e7779
|
@ -542,16 +542,27 @@ function getPrincipal(url) {
|
|||
return Services.scriptSecurityManager.createContentPrincipal(uri, {});
|
||||
}
|
||||
|
||||
function requestFinished(request) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request.callback = function(req) {
|
||||
if (req.resultCode == Cr.NS_OK) {
|
||||
resolve(req.result);
|
||||
} else {
|
||||
reject(req.resultCode);
|
||||
}
|
||||
class RequestError extends Error {
|
||||
constructor(resultCode, resultName) {
|
||||
super(`Request failed (code: ${resultCode}, name: ${resultName})`);
|
||||
this.name = "RequestError";
|
||||
this.resultCode = resultCode;
|
||||
this.resultName = resultName;
|
||||
}
|
||||
}
|
||||
|
||||
async function requestFinished(request) {
|
||||
await new Promise(function(resolve) {
|
||||
request.callback = function() {
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
if (request.resultCode !== Cr.NS_OK) {
|
||||
throw new RequestError(request.resultCode, request.resultName);
|
||||
}
|
||||
|
||||
return request.result;
|
||||
}
|
||||
|
||||
// TODO: Rename to openDBRequestSucceeded ?
|
||||
|
|
|
@ -62,14 +62,25 @@ function getLocalStorage() {
|
|||
return localStorage;
|
||||
}
|
||||
|
||||
function requestFinished(request) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request.callback = SpecialPowers.wrapCallback(function(requestInner) {
|
||||
if (requestInner.resultCode === SpecialPowers.Cr.NS_OK) {
|
||||
resolve(requestInner.result);
|
||||
} else {
|
||||
reject(requestInner.resultCode);
|
||||
}
|
||||
class RequestError extends Error {
|
||||
constructor(resultCode, resultName) {
|
||||
super(`Request failed (code: ${resultCode}, name: ${resultName})`);
|
||||
this.name = "RequestError";
|
||||
this.resultCode = resultCode;
|
||||
this.resultName = resultName;
|
||||
}
|
||||
}
|
||||
|
||||
async function requestFinished(request) {
|
||||
await new Promise(function(resolve) {
|
||||
request.callback = SpecialPowers.wrapCallback(function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
if (request.resultCode !== SpecialPowers.Cr.NS_OK) {
|
||||
throw new RequestError(request.resultCode, request.resultName);
|
||||
}
|
||||
|
||||
return request.result;
|
||||
}
|
||||
|
|
|
@ -289,16 +289,27 @@ function getLocalStorage(principal) {
|
|||
);
|
||||
}
|
||||
|
||||
function requestFinished(request) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request.callback = function(requestInner) {
|
||||
if (requestInner.resultCode == Cr.NS_OK) {
|
||||
resolve(requestInner.result);
|
||||
} else {
|
||||
reject(requestInner.resultCode);
|
||||
}
|
||||
class RequestError extends Error {
|
||||
constructor(resultCode, resultName) {
|
||||
super(`Request failed (code: ${resultCode}, name: ${resultName})`);
|
||||
this.name = "RequestError";
|
||||
this.resultCode = resultCode;
|
||||
this.resultName = resultName;
|
||||
}
|
||||
}
|
||||
|
||||
async function requestFinished(request) {
|
||||
await new Promise(function(resolve) {
|
||||
request.callback = function() {
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
if (request.resultCode !== Cr.NS_OK) {
|
||||
throw new RequestError(request.resultCode, request.resultName);
|
||||
}
|
||||
|
||||
return request.result;
|
||||
}
|
||||
|
||||
function loadSubscript(path) {
|
||||
|
|
|
@ -74,6 +74,18 @@ RequestBase::GetResultCode(nsresult* aResultCode) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RequestBase::GetResultName(nsACString& aResultName) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
if (!mHaveResultOrErrorCode) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mozilla::GetErrorName(mResultCode, aResultName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
UsageRequest::UsageRequest(nsIQuotaUsageCallback* aCallback)
|
||||
: mCallback(aCallback), mBackgroundActor(nullptr), mCanceled(false) {
|
||||
AssertIsOnOwningThread();
|
||||
|
|
|
@ -17,6 +17,8 @@ interface nsIQuotaRequestBase : nsISupports
|
|||
readonly attribute nsIPrincipal principal;
|
||||
|
||||
[must_use] readonly attribute nsresult resultCode;
|
||||
|
||||
[must_use] readonly attribute ACString resultName;
|
||||
};
|
||||
|
||||
[scriptable, uuid(166e28e6-cf6d-4927-a6d7-b51bca9d3469)]
|
||||
|
|
|
@ -47,14 +47,16 @@ function getSimpleDatabase() {
|
|||
return connection;
|
||||
}
|
||||
|
||||
function requestFinished(request) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request.callback = SpecialPowers.wrapCallback(function(req) {
|
||||
if (req.resultCode === SpecialPowers.Cr.NS_OK) {
|
||||
resolve(req.result);
|
||||
} else {
|
||||
reject(req.resultCode);
|
||||
}
|
||||
async function requestFinished(request) {
|
||||
await new Promise(function(resolve) {
|
||||
request.callback = SpecialPowers.wrapCallback(function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
if (request.resultCode != SpecialPowers.Cr.NS_OK) {
|
||||
throw new RequestError(request.resultCode, request.resultName);
|
||||
}
|
||||
|
||||
return request.result;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,15 @@
|
|||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
class RequestError extends Error {
|
||||
constructor(resultCode, resultName) {
|
||||
super(`Request failed (code: ${resultCode}, name: ${resultName})`);
|
||||
this.name = "RequestError";
|
||||
this.resultCode = resultCode;
|
||||
this.resultName = resultName;
|
||||
}
|
||||
}
|
||||
|
||||
function openDBRequestUpgradeNeeded(request) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request.onerror = function(event) {
|
||||
|
|
|
@ -57,14 +57,16 @@ function getSimpleDatabase(principal, persistence) {
|
|||
return connection;
|
||||
}
|
||||
|
||||
function requestFinished(request) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request.callback = function(req) {
|
||||
if (req.resultCode == Cr.NS_OK) {
|
||||
resolve(req.result);
|
||||
} else {
|
||||
reject(req.resultCode);
|
||||
}
|
||||
async function requestFinished(request) {
|
||||
await new Promise(function(resolve) {
|
||||
request.callback = function() {
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
if (request.resultCode !== Cr.NS_OK) {
|
||||
throw new RequestError(request.resultCode, request.resultName);
|
||||
}
|
||||
|
||||
return request.result;
|
||||
}
|
||||
|
|
|
@ -56,9 +56,12 @@ async function testSteps() {
|
|||
await requestFinished(request);
|
||||
|
||||
ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
} catch (e) {
|
||||
ok(true, "Should have thrown");
|
||||
ok(ex === NS_ERROR_FILE_NO_DEVICE_SPACE, "Threw right code");
|
||||
ok(
|
||||
e.resultCode === NS_ERROR_FILE_NO_DEVICE_SPACE,
|
||||
"Threw right result code"
|
||||
);
|
||||
}
|
||||
|
||||
info("Closing the database and clearing");
|
||||
|
|
|
@ -67,9 +67,12 @@ async function testSteps() {
|
|||
request = databases[index].write(new ArrayBuffer(1));
|
||||
await requestFinished(request);
|
||||
ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
} catch (e) {
|
||||
ok(true, "Should have thrown");
|
||||
ok(ex == NS_ERROR_FILE_NO_DEVICE_SPACE, "Threw right code");
|
||||
ok(
|
||||
e.resultCode == NS_ERROR_FILE_NO_DEVICE_SPACE,
|
||||
"Threw right result code"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,9 +84,12 @@ async function testSteps() {
|
|||
await requestFinished(request);
|
||||
|
||||
ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
} catch (e) {
|
||||
ok(true, "Should have thrown");
|
||||
ok(ex === NS_ERROR_FILE_NO_DEVICE_SPACE, "Threw right code");
|
||||
ok(
|
||||
e.resultCode === NS_ERROR_FILE_NO_DEVICE_SPACE,
|
||||
"Threw right result code"
|
||||
);
|
||||
}
|
||||
|
||||
info("Checking the storage pressure event");
|
||||
|
|
Загрузка…
Ссылка в новой задаче