summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/structured-clone/array-buffers.js
blob: fcb61f6ecad8e176a5b667dd749ddd844784a193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Tests for ArrayBuffer, TypedArray, and DataView encoding/decoding. 

var clonebuffer = serialize("dummy");

// ========= V2 =========

function testV2Int32Array() {
    var buf = new Uint8Array([3,0,0,0,0,0,241,255,3,0,0,0,16,0,255,255,4,0,0,0,0,0,0,0,12,0,0,0,9,0,255,255,1,0,0,0,177,127,57,5,133,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0]);
    clonebuffer.clonebuffer = buf.buffer;
    var ta = deserialize(clonebuffer);
    assertEq(ta instanceof Int32Array, true);
    assertEq(ta.toString(), "1,87654321,-123");
}
testV2Int32Array();

function testV2Float64Array() {
    var buf = new Uint8Array([3,0,0,0,0,0,241,255,4,0,0,0,16,0,255,255,7,0,0,0,0,0,0,0,32,0,0,0,9,0,255,255,0,0,0,0,0,0,248,127,31,133,235,81,184,30,9,64,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
    clonebuffer.clonebuffer = buf.buffer;
    var ta = deserialize(clonebuffer);
    assertEq(ta instanceof Float64Array, true);
    assertEq(ta.toString(), "NaN,3.14,0,0");
}
testV2Float64Array();

function testV2DataView() {
    var buf = new Uint8Array([3,0,0,0,0,0,241,255,3,0,0,0,21,0,255,255,3,0,0,0,9,0,255,255,5,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0]);
    clonebuffer.clonebuffer = buf.buffer;
    var dv = deserialize(clonebuffer);
    assertEq(dv instanceof DataView, true);
    assertEq(new Uint8Array(dv.buffer).toString(), "5,0,255");
}
testV2DataView();

function testV2ArrayBuffer() {
    var buf = new Uint8Array([3,0,0,0,0,0,241,255,4,0,0,0,9,0,255,255,33,44,55,66,0,0,0,0]);
    clonebuffer.clonebuffer = buf.buffer;
    var ab = deserialize(clonebuffer);
    assertEq(ab instanceof ArrayBuffer, true);
    assertEq(new Uint8Array(ab).toString(), "33,44,55,66");
}
testV2ArrayBuffer();

// ========= Current =========

function testInt32Array() {
    var ta1 = new Int32Array([1, 87654321, -123]);
    var clonebuf = serialize(ta1, undefined, {scope: "DifferentProcessForIndexedDB"});
    var ta2 = deserialize(clonebuf);
    assertEq(ta2 instanceof Int32Array, true);
    assertEq(ta2.toString(), "1,87654321,-123");
}
testInt32Array();

function testFloat64Array() {
    var ta1 = new Float64Array([NaN, 3.14, 0, 0]);
    var clonebuf = serialize(ta1, undefined, {scope: "DifferentProcessForIndexedDB"});
    var ta2 = deserialize(clonebuf);
    assertEq(ta2 instanceof Float64Array, true);
    assertEq(ta2.toString(), "NaN,3.14,0,0");
}
testFloat64Array();

function testDataView() {
    var ta = new Uint8Array([5, 0, 255]);
    var dv1 = new DataView(ta.buffer);
    var clonebuf = serialize(dv1, undefined, {scope: "DifferentProcessForIndexedDB"});
    var dv2 = deserialize(clonebuf);
    assertEq(dv2 instanceof DataView, true);
    assertEq(new Uint8Array(dv2.buffer).toString(), "5,0,255");
}
testDataView();

function testArrayBuffer() {
    var ta = new Uint8Array([33, 44, 55, 66]);
    var clonebuf = serialize(ta.buffer, undefined, {scope: "DifferentProcessForIndexedDB"});
    var ab = deserialize(clonebuf);
    assertEq(ab instanceof ArrayBuffer, true);
    assertEq(new Uint8Array(ab).toString(), "33,44,55,66");
}
testArrayBuffer();