зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1753860
- Test using `structuredClone` in xpcshell. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D137959
This commit is contained in:
Родитель
4f6cbee5d3
Коммит
55384efb10
|
@ -1,25 +1,33 @@
|
|||
function run_test() {
|
||||
var sb = new Cu.Sandbox('http://www.example.com',
|
||||
{ wantGlobalProperties: ["structuredClone"] });
|
||||
var sb = new Cu.Sandbox("http://www.example.com", {
|
||||
wantGlobalProperties: ["structuredClone"],
|
||||
});
|
||||
|
||||
sb.equal = equal;
|
||||
|
||||
sb.testing = Components.utils.cloneInto({xyz: 123}, sb);
|
||||
Cu.evalInSandbox(`
|
||||
sb.testing = Cu.cloneInto({ xyz: 123 }, sb);
|
||||
Cu.evalInSandbox(
|
||||
`
|
||||
equal(structuredClone("abc"), "abc");
|
||||
|
||||
var obj = {a: 1};
|
||||
var obj = { a: 1 };
|
||||
obj.self = obj;
|
||||
var clone = structuredClone(obj);
|
||||
equal(clone.a, 1);
|
||||
equal(clone.self, clone);
|
||||
|
||||
var ab = new ArrayBuffer(1);
|
||||
clone = structuredClone(ab, {transfer: [ab]});
|
||||
clone = structuredClone(ab, { transfer: [ab] });
|
||||
equal(clone.byteLength, 1);
|
||||
equal(ab.byteLength, 0);
|
||||
|
||||
clone = structuredClone(testing);
|
||||
equal(clone.xyz, 123);
|
||||
`, sb);
|
||||
`,
|
||||
sb
|
||||
);
|
||||
|
||||
Cu.importGlobalProperties(["structuredClone"]);
|
||||
const clone = structuredClone({ b: 2 });
|
||||
Assert.equal(clone.b, 2);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче