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 | |
88 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
89 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
90 if (!IS_UNDEFINED(byteOffset)) { | 52 if (!IS_UNDEFINED(byteOffset)) { |
91 byteOffset = | 53 byteOffset = |
92 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); | 54 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
93 } | 55 } |
94 if (!IS_UNDEFINED(length)) { | 56 if (!IS_UNDEFINED(length)) { |
95 length = $toPositiveInteger(length, kInvalidTypedArrayLength); | 57 length = $toPositiveInteger(length, kInvalidTypedArrayLength); |
96 } | 58 } |
97 | 59 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 NAMEConstructByArrayLike(this, arg1); | 165 NAMEConstructByArrayLike(this, arg1); |
204 } else { | 166 } else { |
205 NAMEConstructByIterable(this, arg1, iteratorFn); | 167 NAMEConstructByIterable(this, arg1, iteratorFn); |
206 } | 168 } |
207 } | 169 } |
208 } else { | 170 } else { |
209 throw MakeTypeError(kConstructorNotFunction, "NAME") | 171 throw MakeTypeError(kConstructorNotFunction, "NAME") |
210 } | 172 } |
211 } | 173 } |
212 | 174 |
| 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 |
213 function NAMESubArray(begin, end) { | 203 function NAMESubArray(begin, end) { |
214 if (!(%_ClassOf(this) === 'NAME')) { | 204 if (!(%_ClassOf(this) === 'NAME')) { |
215 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | 205 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
216 } | 206 } |
217 var beginInt = TO_INTEGER(begin); | 207 var beginInt = TO_INTEGER(begin); |
218 if (!IS_UNDEFINED(end)) { | 208 if (!IS_UNDEFINED(end)) { |
219 end = TO_INTEGER(end); | 209 end = TO_INTEGER(end); |
220 } | 210 } |
221 | 211 |
222 var srcLength = %_TypedArrayGetLength(this); | 212 var srcLength = %_TypedArrayGetLength(this); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 340 |
351 function TypedArrayGetToStringTag() { | 341 function TypedArrayGetToStringTag() { |
352 if (!%_IsTypedArray(this)) return; | 342 if (!%_IsTypedArray(this)) return; |
353 var name = %_ClassOf(this); | 343 var name = %_ClassOf(this); |
354 if (IS_UNDEFINED(name)) return; | 344 if (IS_UNDEFINED(name)) return; |
355 return name; | 345 return name; |
356 } | 346 } |
357 | 347 |
358 // ------------------------------------------------------------------- | 348 // ------------------------------------------------------------------- |
359 | 349 |
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 | |
373 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 350 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
374 %SetCode(GlobalNAME, NAMEConstructor); | 351 %SetCode(GlobalNAME, NAMEConstructor); |
375 %InternalSetPrototype(GlobalNAME, TypedArray); | 352 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
376 %FunctionSetPrototype(GlobalNAME, new TypedArray()); | |
377 %AddNamedProperty(GlobalNAME.prototype, | |
378 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | |
379 READ_ONLY | DONT_ENUM | DONT_DELETE); | |
380 | 353 |
381 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 354 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
382 READ_ONLY | DONT_ENUM | DONT_DELETE); | 355 READ_ONLY | DONT_ENUM | DONT_DELETE); |
383 %AddNamedProperty(GlobalNAME.prototype, | 356 %AddNamedProperty(GlobalNAME.prototype, |
384 "constructor", global.NAME, DONT_ENUM); | 357 "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); |
385 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 370 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
386 "subarray", NAMESubArray | 371 "subarray", NAMESubArray, |
| 372 "set", TypedArraySet |
387 ]); | 373 ]); |
388 endmacro | 374 endmacro |
389 | 375 |
390 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 376 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
391 | 377 |
392 // --------------------------- DataView ----------------------------- | 378 // --------------------------- DataView ----------------------------- |
393 | 379 |
394 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 380 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
395 if (%_IsConstructCall()) { | 381 if (%_IsConstructCall()) { |
396 // TODO(binji): support SharedArrayBuffers? | 382 // TODO(binji): support SharedArrayBuffers? |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 "setUint32", DataViewSetUint32JS, | 500 "setUint32", DataViewSetUint32JS, |
515 | 501 |
516 "getFloat32", DataViewGetFloat32JS, | 502 "getFloat32", DataViewGetFloat32JS, |
517 "setFloat32", DataViewSetFloat32JS, | 503 "setFloat32", DataViewSetFloat32JS, |
518 | 504 |
519 "getFloat64", DataViewGetFloat64JS, | 505 "getFloat64", DataViewGetFloat64JS, |
520 "setFloat64", DataViewSetFloat64JS | 506 "setFloat64", DataViewSetFloat64JS |
521 ]); | 507 ]); |
522 | 508 |
523 }) | 509 }) |
OLD | NEW |