<!DOCTYPE HTML><!-- webkit-test-runner [ jscOptions=--useResizableArrayBuffer=true,--useSharedArrayBuffer=true ] -->
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Checks that window.postMessage clones growable SharedArrayBuffers");

jsTestIsAsync = true;

var sab = new SharedArrayBuffer(4, { maxByteLength: 1024 });
var memory = new Int32Array(sab);
var otherMemory;

window.addEventListener("message", function (event) {
    otherMemory = event.data;
    memory[0] = 42;
    shouldBe("memory[0]", "42");
    shouldBe("otherMemory[0]", "0");
    otherMemory[0] = 43;
    shouldBe("memory[0]", "42");
    shouldBe("otherMemory[0]", "43");
    shouldBe("memory.length", "1");
    shouldBe("otherMemory.length", "1");
    sab.grow(1024);
    shouldBe("memory.length", "256");
    shouldBe("otherMemory.length", "1");
    otherMemory.buffer.resize(1024); // Cloning it as resizable ArrayBuffer.
    shouldBe("memory.length", "256");
    shouldBe("otherMemory.length", "256");
    finishJSTest();
});

window.postMessage(memory, "*");
</script>
</body>
</html>
