• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15function validate_typedarray (typedarray, result) {
16  assert(typedarray.length === result.length);
17  for (var i = 0; i < typedarray.length; i++) {
18    assert(typedarray[i] === result[i]);
19  }
20}
21
22var v1 = new Float64Array(6);
23v1.buffer.constructor = Uint8Array;
24var v2 = new Float64Array(v1);
25
26assert(v2.buffer.constructor === Uint8Array);
27validate_typedarray(v2, [0, 0, 0, 0, 0, 0]);
28
29var v3 = new Uint32Array(6);
30v3.buffer.constructor = Float64Array;
31var v4 = new Uint8Array(v3);
32
33assert(v4.buffer.constructor === Float64Array);
34validate_typedarray(v4, [0, 0, 0, 0, 0, 0]);
35
36var v5 = new Uint32Array(6);
37v5.buffer.constructor = Set;
38var v6 = new Uint8Array(v5);
39
40assert(v6.buffer.constructor === Set);
41validate_typedarray(v6, [0, 0, 0, 0, 0, 0]);
42
43var species_called = false;
44
45var v7 = new Float64Array(6);
46var v8 = v7.buffer;
47v8.constructor = {
48  get [Symbol.species] (){
49    species_called = true;
50    return Uint8Array;
51  }
52}
53var v9 = new Float64Array(v7);
54
55assert(species_called);
56assert(Reflect.getPrototypeOf(v9.buffer) === Uint8Array.prototype);
57