This patch was autogenerated by my decomponents.py
It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.
It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.
It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)
MozReview-Commit-ID: DeSHcClQ7cG
97 lines
3.0 KiB
JavaScript
97 lines
3.0 KiB
JavaScript
"use strict";
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const global = this;
|
|
|
|
add_task(async function test_structuredCloneHolder() {
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(
|
|
Services.io.newURI("http://example.com/"), {});
|
|
|
|
let sandbox = Cu.Sandbox(principal);
|
|
|
|
const obj = {foo: [{bar: "baz"}]};
|
|
|
|
let holder = new StructuredCloneHolder(obj);
|
|
|
|
|
|
// Test same-compartment deserialization
|
|
|
|
let res = holder.deserialize(global);
|
|
|
|
notEqual(res, obj, "Deserialized result is a different object from the original");
|
|
|
|
deepEqual(res, obj, "Deserialized result is deeply equivalent to the original");
|
|
|
|
equal(Cu.getObjectPrincipal(res), Cu.getObjectPrincipal(global),
|
|
"Deserialized result has the correct principal");
|
|
|
|
|
|
// Test non-object-value round-trip.
|
|
|
|
equal(new StructuredCloneHolder("foo").deserialize(global), "foo",
|
|
"Round-tripping non-object values works as expected");
|
|
|
|
|
|
// Test cross-compartment deserialization
|
|
|
|
res = holder.deserialize(sandbox);
|
|
|
|
notEqual(res, obj, "Cross-compartment-deserialized result is a different object from the original");
|
|
|
|
deepEqual(res, obj, "Cross-compartment-deserialized result is deeply equivalent to the original");
|
|
|
|
equal(Cu.getObjectPrincipal(res), principal,
|
|
"Cross-compartment-deserialized result has the correct principal");
|
|
|
|
|
|
// Test message manager transportability
|
|
|
|
const MSG = "StructuredCloneHolder";
|
|
|
|
let resultPromise = new Promise(resolve => {
|
|
Services.ppmm.addMessageListener(MSG, resolve);
|
|
});
|
|
|
|
Services.cpmm.sendAsyncMessage(MSG, holder);
|
|
|
|
res = await resultPromise;
|
|
|
|
ok(res.data instanceof StructuredCloneHolder,
|
|
"Sending structured clone holders through message managers works as expected");
|
|
|
|
deepEqual(res.data.deserialize(global), obj,
|
|
"Sending structured clone holders through message managers works as expected");
|
|
});
|
|
|
|
// Test that X-rays passed to an exported function are serialized
|
|
// through their exported wrappers.
|
|
add_task(async function test_structuredCloneHolder_xray() {
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(
|
|
Services.io.newURI("http://example.com/"), {});
|
|
|
|
let sandbox1 = Cu.Sandbox(principal, {wantXrays: true});
|
|
|
|
let sandbox2 = Cu.Sandbox(principal, {wantXrays: true});
|
|
Cu.evalInSandbox(`this.x = {y: "z", get z() { return "q" }}`, sandbox2);
|
|
|
|
sandbox1.x = sandbox2.x;
|
|
|
|
let holder;
|
|
Cu.exportFunction(function serialize(val) {
|
|
holder = new StructuredCloneHolder(val, sandbox1);
|
|
}, sandbox1, {defineAs: "serialize"});
|
|
|
|
Cu.evalInSandbox(`serialize(x)`, sandbox1);
|
|
|
|
const obj = {y: "z"};
|
|
|
|
let res = holder.deserialize(global);
|
|
|
|
deepEqual(res, obj, "Deserialized result is deeply equivalent to the expected object");
|
|
deepEqual(res, sandbox2.x, "Deserialized result is deeply equivalent to the X-ray-wrapped object");
|
|
|
|
equal(Cu.getObjectPrincipal(res), Cu.getObjectPrincipal(global),
|
|
"Deserialized result has the correct principal");
|
|
});
|