Bug 830716 - Show class-name of object that failed to be cloned. r=smaug

This has one small wrinkle that I might fix in the future: DOM classes that are proxies
like window show up as "Proxy".

Differential Revision: https://phabricator.services.mozilla.com/D152566
This commit is contained in:
Tom Schuster 2022-07-26 08:19:40 +00:00
Родитель 54b26a2cf8
Коммит b2b0bdeec1
5 изменённых файлов: 32 добавлений и 4 удалений

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

@ -500,7 +500,11 @@ bool StructuredCloneHolder::WriteFullySerializableObjects(
}
// Don't know what this is
xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
ErrorResult rv;
const char* className = JS::GetClass(obj)->name;
rv.ThrowDataCloneError(nsDependentCString(className) +
" object could not be cloned."_ns);
MOZ_ALWAYS_TRUE(rv.MaybeSetPendingException(aCx));
return false;
}

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

@ -897,6 +897,7 @@ skip-if = debug == false
[test_shared_compartment1.html]
[test_shared_compartment2.html]
[test_structuredclone_backref.html]
[test_structuredclone_error.html]
[test_style_cssText.html]
[test_suppressed_events_and_scrolling.html]
support-files =

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

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=XXX">Mozilla Bug XXX</a>
<script>
const tests = [
{obj: (() => {}), msg: "Function object could not be cloned."},
{obj: document.body, msg: "HTMLBodyElement object could not be cloned."},
{obj: {foo: new Audio()}, msg: "HTMLAudioElement object could not be cloned."},
]
for (const test of tests) {
let message = undefined;
try {
structuredClone(test.obj);
} catch (e) {
message = e.message;
}
is(message, test.msg, 'Threw correct DataCloneError');
}
</script>

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

@ -54,7 +54,7 @@ add_task(async function test_unhandled_dom_exception() {
equal(msg.lineNumber, 2, "Got expected line number");
equal(
msg.errorMessage,
"DataCloneError: The object could not be cloned.",
"DataCloneError: Function object could not be cloned.",
"Got expected error message"
);
});

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

@ -31,8 +31,8 @@ add_task(async function test_sendMessage_error() {
],
// Structured cloning doesn't work with DOM objects
[[null, location, null], "The object could not be cloned."],
[[null, [circ, location], null], "The object could not be cloned."],
[[null, location, null], "Location object could not be cloned."],
[[null, [circ, location], null], "Location object could not be cloned."],
];
// Repeat all tests with the undefined value instead of null.