function getType(a) { if (a === null || a === undefined) { return"null";
}
if (Array.isArray(a)) { return"array";
}
if (typeof a == "object") { return"object";
}
if (
SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported() &&
a instanceof WebAssembly.Module
) { return"wasm";
}
return"primitive";
}
function compare(a, b) {
is(getType(a), getType(b), "Type matches");
var type = getType(a); if (type == "array") {
is(a.length, b.length, "Array.length matches"); for (var i = 0; i < a.length; ++i) {
compare(a[i], b[i]);
}
return;
}
if (type == "object") {
ok(a !== b, "They should not match");
var aProps = []; for (var p in a) {
aProps.push(p);
}
var bProps = []; for (var p in b) {
bProps.push(p);
}
function create_directory() { if (navigator.userAgent.toLowerCase().includes("Android")) {
next(); return;
}
var url = SimpleTest.getTestFileURL("script_postmessages_fileList.js"); var script = SpecialPowers.loadChromeScript(url);
function onOpened(message) { var fileList = document.getElementById("fileList");
SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
SpecialPowers.wrap(fileList)
.getFilesAndDirectories()
.then(function (list) {
list = SpecialPowers.unwrap(list); // Just a simple test
is(list.length, 1, "This list has 1 element");
ok(list[0] instanceof Directory, "We have a directory.");
WebAssembly.compile(fooModuleCode).then(
m => {
ok(m instanceof WebAssembly.Module, "The WasmModule has been compiled.");
clonableObjects.push({ target: "sameProcess", data: m });
next();
},
() => {
ok(false, "The compilation of the wasmModule failed.");
}
);
}
function runTests(obj) {
ok( "clonableObjectsEveryWhere" in obj && "clonableObjectsSameProcess" in obj && "transferableObjects" in obj &&
(obj.clonableObjectsEveryWhere ||
obj.clonableObjectsSameProcess ||
obj.transferableObjects), "We must run some test!"
);
// cloning tests - everyWhere new Promise(function (resolve, reject) { var clonableObjectsId = 0; function runClonableTest() { if (clonableObjectsId >= clonableObjects.length) {
resolve(); return;
}
var object = clonableObjects[clonableObjectsId++];
if (object.target != "all") {
runClonableTest(); return;
}
// MessagePort returnnew Promise(function (r, rr) { var mc = new MessageChannel();
obj.send(42, [mc.port1]).then(function (received) {
is(received.ports.length, 1, "MessagePort has been transferred");
mc.port2.postMessage("hello world");
received.ports[0].onmessage = function (e) {
is(e.data, "hello world", "Ports are connected!");
r();
};
});
});
})
// no dup transfering
.then(function () { if (!obj.transferableObjects) { return Promise.resolve();
}
// MessagePort returnnew Promise(function (r, rr) { var mc = new MessageChannel();
obj
.send(42, [mc.port1, mc.port1])
.then( function (received) {
ok(false, "Duplicate ports should throw!");
}, function () {
ok(true, "Duplicate ports should throw!");
}
)
.then(r);
});
})
// maintaining order of transferred ports
.then(function () { if (!obj.transferableObjects) { return Promise.resolve();
}
// MessagePort returnnew Promise(function (r, rr) { var mcs = []; const NPORTS = 50; for (let i = 0; i < NPORTS; i++) {
mcs.push(new MessageChannel());
}
obj
.send(
42,
mcs.map(channel => channel.port1)
)
.then(function (received) {
is(
received.ports.length,
NPORTS,
`all ${NPORTS} ports transferred`
); const promises = Array(NPORTS)
.fill()
.map(
(_, i) => new Promise(function (subr, subrr) {
mcs[i].port2.postMessage(i);
received.ports[i].onmessage = e => subr(e.data == i);
})
); return Promise.all(promises);
})
.then(function (result) {
let in_order = 0; for (const correct of result) { if (correct) {
in_order++;
}
}
is(in_order, NPORTS, "All transferred ports are in order");
})
.then(r);
});
})
// non transfering tests
.then(function () { if (obj.transferableObjects) { return Promise.resolve();
}
// MessagePort returnnew Promise(function (r, rr) { var mc = new MessageChannel();
obj
.send(42, [mc.port1])
.then( function (received) {
ok(false, "This object should not support port transferring");
}, function () {
ok(true, "This object should not support port transferring");
}
)
.then(r);
});
})
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.