Bug 1753860 - Test using `structuredClone` in xpcshell. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D137959
This commit is contained in:
Mathew Hodson 2022-02-09 09:26:28 +00:00
Родитель 4f6cbee5d3
Коммит 55384efb10
1 изменённых файлов: 15 добавлений и 7 удалений

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

@ -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);
}