|
| 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 | + |
| 15 | +function 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 | + |
| 22 | +var v1 = new Float64Array(6); |
| 23 | +v1.buffer.constructor = Uint8Array; |
| 24 | +var v2 = new Float64Array(v1); |
| 25 | + |
| 26 | +assert(v2.buffer.constructor === Uint8Array); |
| 27 | +validate_typedarray(v2, [0, 0, 0, 0, 0, 0]); |
| 28 | + |
| 29 | +var v3 = new Uint32Array(6); |
| 30 | +v3.buffer.constructor = Float64Array; |
| 31 | +var v4 = new Uint8Array(v3); |
| 32 | + |
| 33 | +assert(v4.buffer.constructor === Float64Array); |
| 34 | +validate_typedarray(v4, [0, 0, 0, 0, 0, 0]); |
| 35 | + |
| 36 | +var v5 = new Uint32Array(6); |
| 37 | +v5.buffer.constructor = Set; |
| 38 | +var v6 = new Uint8Array(v5); |
| 39 | + |
| 40 | +assert(v6.buffer.constructor === Set); |
| 41 | +validate_typedarray(v6, [0, 0, 0, 0, 0, 0]); |
| 42 | + |
| 43 | +var species_called = false; |
| 44 | + |
| 45 | +var v7 = new Float64Array(6); |
| 46 | +var v8 = v7.buffer; |
| 47 | +v8.constructor = { |
| 48 | + get [Symbol.species] (){ |
| 49 | + species_called = true; |
| 50 | + return Uint8Array; |
| 51 | + } |
| 52 | +} |
| 53 | +var v9 = new Float64Array(v7); |
| 54 | + |
| 55 | +assert(species_called); |
| 56 | +assert(Reflect.getPrototypeOf(v9.buffer) === Uint8Array.prototype); |
0 commit comments