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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 function NAME_GetLength() { | 141 function NAME_GetLength() { |
142 if (!(%_ClassOf(this) === 'NAME')) { | 142 if (!(%_ClassOf(this) === 'NAME')) { |
143 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); | 143 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); |
144 } | 144 } |
145 return %_TypedArrayGetLength(this); | 145 return %_TypedArrayGetLength(this); |
146 } | 146 } |
147 | 147 |
148 var $NAME = global.NAME; | 148 var $NAME = global.NAME; |
149 | 149 |
| 150 function NAMESlice(begin, end) { |
| 151 if (!(%_ClassOf(this) === 'NAME')) { |
| 152 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.slice", this); |
| 153 } |
| 154 var beginInt = TO_INTEGER(begin); |
| 155 if (!IS_UNDEFINED(end)) { |
| 156 end = TO_INTEGER(end); |
| 157 } |
| 158 |
| 159 var srcLength = %_TypedArrayGetLength(this); |
| 160 if (beginInt < 0) { |
| 161 beginInt = $max(0, srcLength + beginInt); |
| 162 } else { |
| 163 beginInt = $min(srcLength, beginInt); |
| 164 } |
| 165 |
| 166 var endInt = IS_UNDEFINED(end) ? srcLength : end; |
| 167 if (endInt < 0) { |
| 168 endInt = $max(0, srcLength + endInt); |
| 169 } else { |
| 170 endInt = $min(endInt, srcLength); |
| 171 } |
| 172 if (endInt < beginInt) { |
| 173 endInt = beginInt; |
| 174 } |
| 175 var newLength = endInt - beginInt; |
| 176 var beginByteOffset = |
| 177 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 178 var arrayBuffer = %TypedArrayGetBuffer(this); |
| 179 var arrayBufferSlice = new GlobalArrayBuffer(newLength * ELEMENT_SIZE); |
| 180 %ArrayBufferSliceImpl(arrayBuffer, arrayBufferSlice, beginByteOffset); |
| 181 return new $NAME(arrayBufferSlice, 0, newLength); |
| 182 } |
| 183 |
150 function NAMESubArray(begin, end) { | 184 function NAMESubArray(begin, end) { |
151 if (!(%_ClassOf(this) === 'NAME')) { | 185 if (!(%_ClassOf(this) === 'NAME')) { |
152 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | 186 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
153 } | 187 } |
154 var beginInt = TO_INTEGER(begin); | 188 var beginInt = TO_INTEGER(begin); |
155 if (!IS_UNDEFINED(end)) { | 189 if (!IS_UNDEFINED(end)) { |
156 end = TO_INTEGER(end); | 190 end = TO_INTEGER(end); |
157 } | 191 } |
158 | 192 |
159 var srcLength = %_TypedArrayGetLength(this); | 193 var srcLength = %_TypedArrayGetLength(this); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer); | 344 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer); |
311 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset, | 345 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset, |
312 DONT_ENUM | DONT_DELETE); | 346 DONT_ENUM | DONT_DELETE); |
313 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength, | 347 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength, |
314 DONT_ENUM | DONT_DELETE); | 348 DONT_ENUM | DONT_DELETE); |
315 InstallGetter(global.NAME.prototype, "length", NAME_GetLength, | 349 InstallGetter(global.NAME.prototype, "length", NAME_GetLength, |
316 DONT_ENUM | DONT_DELETE); | 350 DONT_ENUM | DONT_DELETE); |
317 InstallGetter(global.NAME.prototype, symbolToStringTag, | 351 InstallGetter(global.NAME.prototype, symbolToStringTag, |
318 TypedArrayGetToStringTag); | 352 TypedArrayGetToStringTag); |
319 InstallFunctions(global.NAME.prototype, DONT_ENUM, [ | 353 InstallFunctions(global.NAME.prototype, DONT_ENUM, [ |
| 354 "slice", NAMESlice, |
320 "subarray", NAMESubArray, | 355 "subarray", NAMESubArray, |
321 "set", TypedArraySet | 356 "set", TypedArraySet |
322 ]); | 357 ]); |
323 endmacro | 358 endmacro |
324 | 359 |
325 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 360 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
326 | 361 |
327 // --------------------------- DataView ----------------------------- | 362 // --------------------------- DataView ----------------------------- |
328 | 363 |
329 var $DataView = global.DataView; | 364 var $DataView = global.DataView; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 "setUint32", DataViewSetUint32JS, | 497 "setUint32", DataViewSetUint32JS, |
463 | 498 |
464 "getFloat32", DataViewGetFloat32JS, | 499 "getFloat32", DataViewGetFloat32JS, |
465 "setFloat32", DataViewSetFloat32JS, | 500 "setFloat32", DataViewSetFloat32JS, |
466 | 501 |
467 "getFloat64", DataViewGetFloat64JS, | 502 "getFloat64", DataViewGetFloat64JS, |
468 "setFloat64", DataViewSetFloat64JS | 503 "setFloat64", DataViewSetFloat64JS |
469 ]); | 504 ]); |
470 | 505 |
471 })(); | 506 })(); |
OLD | NEW |