mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1339559 - Identify script that resulted in non-structured-clonable data r=kmag
MozReview-Commit-ID: AURB4Qpwimh --HG-- extra : rebase_source : 51c70e2d18745c49494b2dead4b5863eba88c08b
This commit is contained in:
parent
e1b539510a
commit
8dd875bed5
@ -116,7 +116,8 @@ add_task(function* testExecuteScript() {
|
||||
}).then(result => {
|
||||
browser.test.fail("Expected error when returning non-structured-clonable object");
|
||||
}, error => {
|
||||
browser.test.assertEq("Script returned non-structured-clonable data",
|
||||
browser.test.assertEq("<anonymous code>", error.fileName, "Got expected fileName");
|
||||
browser.test.assertEq("Script '<anonymous code>' result is non-structured-clonable data",
|
||||
error.message, "Got expected error");
|
||||
}),
|
||||
|
||||
@ -125,10 +126,21 @@ add_task(function* testExecuteScript() {
|
||||
}).then(result => {
|
||||
browser.test.fail("Expected error when returning non-structured-clonable object");
|
||||
}, error => {
|
||||
browser.test.assertEq("Script returned non-structured-clonable data",
|
||||
browser.test.assertEq("<anonymous code>", error.fileName, "Got expected fileName");
|
||||
browser.test.assertEq("Script '<anonymous code>' result is non-structured-clonable data",
|
||||
error.message, "Got expected error");
|
||||
}),
|
||||
|
||||
browser.tabs.executeScript({
|
||||
file: "script3.js",
|
||||
}).then(result => {
|
||||
browser.test.fail("Expected error when returning non-structured-clonable object");
|
||||
}, error => {
|
||||
const expected = /Script '.*script3.js' result is non-structured-clonable data/;
|
||||
browser.test.assertTrue(expected.test(error.message), "Got expected error");
|
||||
browser.test.assertTrue(error.fileName.endsWith("script3.js"), "Got expected fileName");
|
||||
}),
|
||||
|
||||
browser.tabs.executeScript({
|
||||
frameId: Number.MAX_SAFE_INTEGER,
|
||||
code: "42",
|
||||
@ -236,6 +248,8 @@ add_task(function* testExecuteScript() {
|
||||
},
|
||||
|
||||
"script2.js": "27",
|
||||
|
||||
"script3.js": "window",
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -99,7 +99,8 @@ add_task(function* testExecuteScript() {
|
||||
}).then(result => {
|
||||
browser.test.fail("Expected error when returning non-structured-clonable object");
|
||||
}, error => {
|
||||
browser.test.assertEq("Script returned non-structured-clonable data",
|
||||
browser.test.assertEq("<anonymous code>", error.fileName, "Got expected fileName");
|
||||
browser.test.assertEq("Script '<anonymous code>' result is non-structured-clonable data",
|
||||
error.message, "Got expected error");
|
||||
}),
|
||||
|
||||
@ -108,10 +109,21 @@ add_task(function* testExecuteScript() {
|
||||
}).then(result => {
|
||||
browser.test.fail("Expected error when returning non-structured-clonable object");
|
||||
}, error => {
|
||||
browser.test.assertEq("Script returned non-structured-clonable data",
|
||||
browser.test.assertEq("<anonymous code>", error.fileName, "Got expected fileName");
|
||||
browser.test.assertEq("Script '<anonymous code>' result is non-structured-clonable data",
|
||||
error.message, "Got expected error");
|
||||
}),
|
||||
|
||||
browser.tabs.executeScript({
|
||||
file: "script3.js",
|
||||
}).then(result => {
|
||||
browser.test.fail("Expected error when returning non-structured-clonable object");
|
||||
}, error => {
|
||||
const expected = /Script '.*script3.js' result is non-structured-clonable data/;
|
||||
browser.test.assertTrue(expected.test(error.message), "Got expected error");
|
||||
browser.test.assertTrue(error.fileName.endsWith("script3.js"), "Got expected fileName");
|
||||
}),
|
||||
|
||||
browser.tabs.executeScript({
|
||||
frameId: Number.MAX_SAFE_INTEGER,
|
||||
code: "42",
|
||||
@ -222,6 +234,8 @@ add_task(function* testExecuteScript() {
|
||||
},
|
||||
|
||||
"script2.js": "27",
|
||||
|
||||
"script3.js": "window",
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -232,17 +232,16 @@ class BaseContext {
|
||||
if (error instanceof this.cloneScope.Error) {
|
||||
return error;
|
||||
}
|
||||
let message;
|
||||
if (instanceOf(error, "Object") || error instanceof ExtensionError) {
|
||||
message = error.message;
|
||||
} else if (typeof error == "object" &&
|
||||
this.principal.subsumes(Cu.getObjectPrincipal(error))) {
|
||||
let message, fileName;
|
||||
if (instanceOf(error, "Object") || error instanceof ExtensionError ||
|
||||
typeof error == "object" && this.principal.subsumes(Cu.getObjectPrincipal(error))) {
|
||||
message = error.message;
|
||||
fileName = error.fileName;
|
||||
} else {
|
||||
Cu.reportError(error);
|
||||
}
|
||||
message = message || "An unexpected error occurred";
|
||||
return new this.cloneScope.Error(message);
|
||||
return new this.cloneScope.Error(message, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1140,7 +1140,10 @@ class ExtensionGlobal {
|
||||
// we try to send it back over the message manager.
|
||||
Cu.cloneInto(result, target);
|
||||
} catch (e) {
|
||||
return Promise.reject({message: "Script returned non-structured-clonable data"});
|
||||
const {js} = options;
|
||||
const fileName = js.length ? js[js.length - 1] : "<anonymous code>";
|
||||
const message = `Script '${fileName}' result is non-structured-clonable data`;
|
||||
return Promise.reject({message, fileName});
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
@ -601,7 +601,7 @@ ParentAPIManager = {
|
||||
reply({result});
|
||||
}, error => {
|
||||
error = context.normalizeError(error);
|
||||
reply({error: {message: error.message}});
|
||||
reply({error: {message: error.message, fileName: error.fileName}});
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user