| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 140 } |
| 141 | 141 |
| 142 // ES#sec-typedarray-typedarray TypedArray ( typedArray ) | 142 // ES#sec-typedarray-typedarray TypedArray ( typedArray ) |
| 143 function NAMEConstructByTypedArray(obj, typedArray) { | 143 function NAMEConstructByTypedArray(obj, typedArray) { |
| 144 // TODO(littledan): Throw on detached typedArray | 144 // TODO(littledan): Throw on detached typedArray |
| 145 var srcData = %TypedArrayGetBuffer(typedArray); | 145 var srcData = %TypedArrayGetBuffer(typedArray); |
| 146 var length = %_TypedArrayGetLength(typedArray); | 146 var length = %_TypedArrayGetLength(typedArray); |
| 147 var byteLength = %_ArrayBufferViewGetByteLength(typedArray); | 147 var byteLength = %_ArrayBufferViewGetByteLength(typedArray); |
| 148 var newByteLength = length * ELEMENT_SIZE; | 148 var newByteLength = length * ELEMENT_SIZE; |
| 149 %typed_array_construct_by_array_like(obj, typedArray, length, ELEMENT_SIZE); | 149 %typed_array_construct_by_array_like(obj, typedArray, length, ELEMENT_SIZE); |
| 150 var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer); | 150 // The spec requires that constructing a typed array using a SAB-backed typed |
| 151 // array use the ArrayBuffer constructor, not the species constructor. See |
| 152 // https://tc39.github.io/ecma262/#sec-typedarray-typedarray. |
| 153 var bufferConstructor = IS_SHAREDARRAYBUFFER(srcData) |
| 154 ? GlobalArrayBuffer |
| 155 : SpeciesConstructor(srcData, GlobalArrayBuffer); |
| 151 var prototype = bufferConstructor.prototype; | 156 var prototype = bufferConstructor.prototype; |
| 152 // TODO(littledan): Use the right prototype based on bufferConstructor's realm | 157 // TODO(littledan): Use the right prototype based on bufferConstructor's realm |
| 153 if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) { | 158 if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) { |
| 154 %InternalSetPrototype(%TypedArrayGetBuffer(obj), prototype); | 159 %InternalSetPrototype(%TypedArrayGetBuffer(obj), prototype); |
| 155 } | 160 } |
| 156 } | 161 } |
| 157 | 162 |
| 158 function NAMEConstructor(arg1, arg2, arg3) { | 163 function NAMEConstructor(arg1, arg2, arg3) { |
| 159 if (!IS_UNDEFINED(new.target)) { | 164 if (!IS_UNDEFINED(new.target)) { |
| 160 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { | 165 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 %AddNamedProperty(GlobalNAME.prototype, | 694 %AddNamedProperty(GlobalNAME.prototype, |
| 690 "constructor", global.NAME, DONT_ENUM); | 695 "constructor", global.NAME, DONT_ENUM); |
| 691 %AddNamedProperty(GlobalNAME.prototype, | 696 %AddNamedProperty(GlobalNAME.prototype, |
| 692 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 697 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 693 READ_ONLY | DONT_ENUM | DONT_DELETE); | 698 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 694 endmacro | 699 endmacro |
| 695 | 700 |
| 696 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 701 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 697 | 702 |
| 698 }) | 703 }) |
| OLD | NEW |