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 29 matching lines...) Expand all Loading... |
40 | 40 |
41 utils.Import(function(from) { | 41 utils.Import(function(from) { |
42 MathMax = from.MathMax; | 42 MathMax = from.MathMax; |
43 MathMin = from.MathMin; | 43 MathMin = from.MathMin; |
44 }); | 44 }); |
45 | 45 |
46 var InternalArray = utils.InternalArray; | 46 var InternalArray = utils.InternalArray; |
47 | 47 |
48 // --------------- Typed Arrays --------------------- | 48 // --------------- Typed Arrays --------------------- |
49 | 49 |
| 50 function TypedArray() { |
| 51 if (!%_IsConstructCall()) { |
| 52 throw MakeTypeError(kConstructorNotFunction, "TypedArray") |
| 53 } |
| 54 // TODO(littledan): When the TypedArrays code is refactored to provide |
| 55 // a common constructor entrypoint for v8:4182, call that here. |
| 56 } |
| 57 |
| 58 function TypedArray_GetBuffer() { |
| 59 if (!%_IsTypedArray(this)) { |
| 60 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this); |
| 61 } |
| 62 return %TypedArrayGetBuffer(this); |
| 63 } |
| 64 |
| 65 function TypedArray_GetByteLength() { |
| 66 if (!%_IsTypedArray(this)) { |
| 67 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteLength", |
| 68 this); |
| 69 } |
| 70 return %_ArrayBufferViewGetByteLength(this); |
| 71 } |
| 72 |
| 73 function TypedArray_GetByteOffset() { |
| 74 if (!%_IsTypedArray(this)) { |
| 75 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteOffset", |
| 76 this); |
| 77 } |
| 78 return %_ArrayBufferViewGetByteOffset(this); |
| 79 } |
| 80 |
| 81 function TypedArray_GetLength() { |
| 82 if (!%_IsTypedArray(this)) { |
| 83 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.length", this); |
| 84 } |
| 85 return %_TypedArrayGetLength(this); |
| 86 } |
| 87 |
50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 88 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 89 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
52 if (!IS_UNDEFINED(byteOffset)) { | 90 if (!IS_UNDEFINED(byteOffset)) { |
53 byteOffset = | 91 byteOffset = |
54 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); | 92 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
55 } | 93 } |
56 if (!IS_UNDEFINED(length)) { | 94 if (!IS_UNDEFINED(length)) { |
57 length = $toPositiveInteger(length, kInvalidTypedArrayLength); | 95 length = $toPositiveInteger(length, kInvalidTypedArrayLength); |
58 } | 96 } |
59 | 97 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 NAMEConstructByArrayLike(this, arg1); | 203 NAMEConstructByArrayLike(this, arg1); |
166 } else { | 204 } else { |
167 NAMEConstructByIterable(this, arg1, iteratorFn); | 205 NAMEConstructByIterable(this, arg1, iteratorFn); |
168 } | 206 } |
169 } | 207 } |
170 } else { | 208 } else { |
171 throw MakeTypeError(kConstructorNotFunction, "NAME") | 209 throw MakeTypeError(kConstructorNotFunction, "NAME") |
172 } | 210 } |
173 } | 211 } |
174 | 212 |
175 function NAME_GetBuffer() { | |
176 if (!(%_ClassOf(this) === 'NAME')) { | |
177 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); | |
178 } | |
179 return %TypedArrayGetBuffer(this); | |
180 } | |
181 | |
182 function NAME_GetByteLength() { | |
183 if (!(%_ClassOf(this) === 'NAME')) { | |
184 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteLength", this); | |
185 } | |
186 return %_ArrayBufferViewGetByteLength(this); | |
187 } | |
188 | |
189 function NAME_GetByteOffset() { | |
190 if (!(%_ClassOf(this) === 'NAME')) { | |
191 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteOffset", this); | |
192 } | |
193 return %_ArrayBufferViewGetByteOffset(this); | |
194 } | |
195 | |
196 function NAME_GetLength() { | |
197 if (!(%_ClassOf(this) === 'NAME')) { | |
198 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); | |
199 } | |
200 return %_TypedArrayGetLength(this); | |
201 } | |
202 | |
203 function NAMESubArray(begin, end) { | 213 function NAMESubArray(begin, end) { |
204 if (!(%_ClassOf(this) === 'NAME')) { | 214 if (!(%_ClassOf(this) === 'NAME')) { |
205 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | 215 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
206 } | 216 } |
207 var beginInt = TO_INTEGER(begin); | 217 var beginInt = TO_INTEGER(begin); |
208 if (!IS_UNDEFINED(end)) { | 218 if (!IS_UNDEFINED(end)) { |
209 end = TO_INTEGER(end); | 219 end = TO_INTEGER(end); |
210 } | 220 } |
211 | 221 |
212 var srcLength = %_TypedArrayGetLength(this); | 222 var srcLength = %_TypedArrayGetLength(this); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 350 |
341 function TypedArrayGetToStringTag() { | 351 function TypedArrayGetToStringTag() { |
342 if (!%_IsTypedArray(this)) return; | 352 if (!%_IsTypedArray(this)) return; |
343 var name = %_ClassOf(this); | 353 var name = %_ClassOf(this); |
344 if (IS_UNDEFINED(name)) return; | 354 if (IS_UNDEFINED(name)) return; |
345 return name; | 355 return name; |
346 } | 356 } |
347 | 357 |
348 // ------------------------------------------------------------------- | 358 // ------------------------------------------------------------------- |
349 | 359 |
| 360 utils.InstallGetter(TypedArray.prototype, "buffer", TypedArray_GetBuffer); |
| 361 utils.InstallGetter(TypedArray.prototype, "byteOffset", |
| 362 TypedArray_GetByteOffset, DONT_ENUM); |
| 363 utils.InstallGetter(TypedArray.prototype, "byteLength", |
| 364 TypedArray_GetByteLength, DONT_ENUM); |
| 365 utils.InstallGetter(TypedArray.prototype, "length", TypedArray_GetLength, |
| 366 DONT_ENUM); |
| 367 utils.InstallGetter(TypedArray.prototype, symbolToStringTag, |
| 368 TypedArrayGetToStringTag, DONT_ENUM); |
| 369 utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [ |
| 370 "set", TypedArraySet |
| 371 ]); |
| 372 |
350 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 373 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
351 %SetCode(GlobalNAME, NAMEConstructor); | 374 %SetCode(GlobalNAME, NAMEConstructor); |
352 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); | 375 %InternalSetPrototype(GlobalNAME, TypedArray); |
| 376 %FunctionSetPrototype(GlobalNAME, new TypedArray()); |
| 377 %AddNamedProperty(GlobalNAME.prototype, |
| 378 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 379 READ_ONLY | DONT_ENUM | DONT_DELETE); |
353 | 380 |
354 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 381 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
355 READ_ONLY | DONT_ENUM | DONT_DELETE); | 382 READ_ONLY | DONT_ENUM | DONT_DELETE); |
356 %AddNamedProperty(GlobalNAME.prototype, | 383 %AddNamedProperty(GlobalNAME.prototype, |
357 "constructor", global.NAME, DONT_ENUM); | 384 "constructor", global.NAME, DONT_ENUM); |
358 %AddNamedProperty(GlobalNAME.prototype, | |
359 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | |
360 READ_ONLY | DONT_ENUM | DONT_DELETE); | |
361 utils.InstallGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer); | |
362 utils.InstallGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset, | |
363 DONT_ENUM | DONT_DELETE); | |
364 utils.InstallGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength, | |
365 DONT_ENUM | DONT_DELETE); | |
366 utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength, | |
367 DONT_ENUM | DONT_DELETE); | |
368 utils.InstallGetter(GlobalNAME.prototype, symbolToStringTag, | |
369 TypedArrayGetToStringTag); | |
370 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 385 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
371 "subarray", NAMESubArray, | 386 "subarray", NAMESubArray |
372 "set", TypedArraySet | |
373 ]); | 387 ]); |
374 endmacro | 388 endmacro |
375 | 389 |
376 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 390 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
377 | 391 |
378 // --------------------------- DataView ----------------------------- | 392 // --------------------------- DataView ----------------------------- |
379 | 393 |
380 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 394 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
381 if (%_IsConstructCall()) { | 395 if (%_IsConstructCall()) { |
382 // TODO(binji): support SharedArrayBuffers? | 396 // TODO(binji): support SharedArrayBuffers? |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 "setUint32", DataViewSetUint32JS, | 514 "setUint32", DataViewSetUint32JS, |
501 | 515 |
502 "getFloat32", DataViewGetFloat32JS, | 516 "getFloat32", DataViewGetFloat32JS, |
503 "setFloat32", DataViewSetFloat32JS, | 517 "setFloat32", DataViewSetFloat32JS, |
504 | 518 |
505 "getFloat64", DataViewGetFloat64JS, | 519 "getFloat64", DataViewGetFloat64JS, |
506 "setFloat64", DataViewSetFloat64JS | 520 "setFloat64", DataViewSetFloat64JS |
507 ]); | 521 ]); |
508 | 522 |
509 }) | 523 }) |
OLD | NEW |