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() { | 5 (function() { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 146 } |
147 return %_ArrayBufferViewGetByteOffset(this); | 147 return %_ArrayBufferViewGetByteOffset(this); |
148 } | 148 } |
149 | 149 |
150 function NAME_GetLength() { | 150 function NAME_GetLength() { |
151 if (!(%_ClassOf(this) === 'NAME')) { | 151 if (!(%_ClassOf(this) === 'NAME')) { |
152 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); | 152 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); |
153 } | 153 } |
154 return %_TypedArrayGetLength(this); | 154 return %_TypedArrayGetLength(this); |
155 } | 155 } |
156 endmacro | |
156 | 157 |
157 function NAMESubArray(begin, end) { | 158 function TypedArraySubArray(begin, end) { |
adamk
2015/05/08 01:13:34
We probably want to change this in the future, but
| |
158 if (!(%_ClassOf(this) === 'NAME')) { | 159 if (!%IsTypedArray(this)) { |
159 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | 160 throw MakeTypeError('not_typed_array', []); |
160 } | 161 } |
161 var beginInt = TO_INTEGER(begin); | 162 var beginInt = TO_INTEGER(begin); |
162 if (!IS_UNDEFINED(end)) { | 163 if (!IS_UNDEFINED(end)) { |
163 end = TO_INTEGER(end); | 164 end = TO_INTEGER(end); |
164 } | 165 } |
165 | 166 |
166 var srcLength = %_TypedArrayGetLength(this); | 167 var srcLength = %_TypedArrayGetLength(this); |
167 if (beginInt < 0) { | 168 if (beginInt < 0) { |
168 beginInt = $max(0, srcLength + beginInt); | 169 beginInt = $max(0, srcLength + beginInt); |
169 } else { | 170 } else { |
170 beginInt = $min(srcLength, beginInt); | 171 beginInt = $min(srcLength, beginInt); |
171 } | 172 } |
172 | 173 |
173 var endInt = IS_UNDEFINED(end) ? srcLength : end; | 174 var endInt = IS_UNDEFINED(end) ? srcLength : end; |
174 if (endInt < 0) { | 175 if (endInt < 0) { |
175 endInt = $max(0, srcLength + endInt); | 176 endInt = $max(0, srcLength + endInt); |
176 } else { | 177 } else { |
177 endInt = $min(endInt, srcLength); | 178 endInt = $min(endInt, srcLength); |
178 } | 179 } |
179 if (endInt < beginInt) { | 180 if (endInt < beginInt) { |
180 endInt = beginInt; | 181 endInt = beginInt; |
181 } | 182 } |
182 var newLength = endInt - beginInt; | 183 var newLength = endInt - beginInt; |
183 var beginByteOffset = | 184 var beginByteOffset = |
184 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 185 %_ArrayBufferViewGetByteOffset(this) + beginInt * this.BYTES_PER_ELEMENT; |
185 return new GlobalNAME(%TypedArrayGetBuffer(this), | 186 return new this.constructor(%TypedArrayGetBuffer(this), |
186 beginByteOffset, newLength); | 187 beginByteOffset, newLength); |
187 } | 188 } |
188 endmacro | |
189 | 189 |
190 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 190 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
191 | 191 |
192 | 192 |
193 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { | 193 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
194 if (offset > 0) { | 194 if (offset > 0) { |
195 for (var i = 0; i < sourceLength; i++) { | 195 for (var i = 0; i < sourceLength; i++) { |
196 target[offset + i] = source[i]; | 196 target[offset + i] = source[i]; |
197 } | 197 } |
198 } | 198 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 $installGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer); | 315 $installGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer); |
316 $installGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset, | 316 $installGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset, |
317 DONT_ENUM | DONT_DELETE); | 317 DONT_ENUM | DONT_DELETE); |
318 $installGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength, | 318 $installGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength, |
319 DONT_ENUM | DONT_DELETE); | 319 DONT_ENUM | DONT_DELETE); |
320 $installGetter(GlobalNAME.prototype, "length", NAME_GetLength, | 320 $installGetter(GlobalNAME.prototype, "length", NAME_GetLength, |
321 DONT_ENUM | DONT_DELETE); | 321 DONT_ENUM | DONT_DELETE); |
322 $installGetter(GlobalNAME.prototype, symbolToStringTag, | 322 $installGetter(GlobalNAME.prototype, symbolToStringTag, |
323 TypedArrayGetToStringTag); | 323 TypedArrayGetToStringTag); |
324 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 324 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
325 "subarray", NAMESubArray, | 325 "subarray", TypedArraySubArray, |
326 "set", TypedArraySet | 326 "set", TypedArraySet |
327 ]); | 327 ]); |
328 endmacro | 328 endmacro |
329 | 329 |
330 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 330 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
331 | 331 |
332 // --------------------------- DataView ----------------------------- | 332 // --------------------------- DataView ----------------------------- |
333 | 333 |
334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
335 if (%_IsConstructCall()) { | 335 if (%_IsConstructCall()) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 "setUint32", DataViewSetUint32JS, | 451 "setUint32", DataViewSetUint32JS, |
452 | 452 |
453 "getFloat32", DataViewGetFloat32JS, | 453 "getFloat32", DataViewGetFloat32JS, |
454 "setFloat32", DataViewSetFloat32JS, | 454 "setFloat32", DataViewSetFloat32JS, |
455 | 455 |
456 "getFloat64", DataViewGetFloat64JS, | 456 "getFloat64", DataViewGetFloat64JS, |
457 "setFloat64", DataViewSetFloat64JS | 457 "setFloat64", DataViewSetFloat64JS |
458 ]); | 458 ]); |
459 | 459 |
460 })(); | 460 })(); |
OLD | NEW |