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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.set-typedarray-offset
description: >
Set values from different instances using the different buffer and same
constructor. srcBuffer values are cached.
includes: [testTypedArray.js, compareArray.js]
features: [SharedArrayBuffer, TypedArray]
---*/
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(TA) {
var sample, result;
var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT);
var src = new TA(sab);
src[0] = 42;
src[1] = 43;
sample = new TA([1, 2, 3, 4]);
result = sample.set(src, 1);
assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
sample = new TA([1, 2, 3, 4]);
result = sample.set(src, 0);
assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
sample = new TA([1, 2, 3, 4]);
result = sample.set(src, 2);
assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
src = new TA([42, 43]);
sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
sample = new TA(sab);
sample[0] = 1;
sample[1] = 2;
sample[2] = 3;
sample[3] = 4;
result = sample.set(src, 1);
assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
sample = new TA(sab);
sample[0] = 1;
sample[1] = 2;
sample[2] = 3;
sample[3] = 4;
result = sample.set(src, 0);
assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
sample = new TA(sab);
sample[0] = 1;
sample[1] = 2;
sample[2] = 3;
sample[3] = 4;
result = sample.set(src, 2);
assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT);
src = new TA(sab1);
src[0] = 42;
src[1] = 43;
var sab2;
sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
sample = new TA(sab2);
sample[0] = 1;
sample[1] = 2;
sample[2] = 3;
sample[3] = 4;
result = sample.set(src, 1);
assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
sample = new TA(sab2);
sample[0] = 1;
sample[1] = 2;
sample[2] = 3;
sample[3] = 4;
result = sample.set(src, 0);
assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
sample = new TA(sab2);
sample[0] = 1;
sample[1] = 2;
sample[2] = 3;
sample[3] = 4;
result = sample.set(src, 2);
assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample);
assert.sameValue(result, undefined, "returns undefined");
}, int_views);
reportCompare(0, 0);
|