| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 function ConstructTypedArrayLike(typedArray, arg) { | 98 function ConstructTypedArrayLike(typedArray, arg) { |
| 99 // TODO(littledan): The spec requires that we actuallly use | 99 // TODO(littledan): The spec requires that we actuallly use |
| 100 // typedArray.constructor[Symbol.species] (bug v8:4093) | 100 // typedArray.constructor[Symbol.species] (bug v8:4093) |
| 101 // Also, it should default to the default constructor from | 101 // Also, it should default to the default constructor from |
| 102 // table 49 if typedArray.constructor doesn't exist. | 102 // table 49 if typedArray.constructor doesn't exist. |
| 103 return ConstructTypedArray(typedArray.constructor, arg); | 103 return ConstructTypedArray(typedArray.constructor, arg); |
| 104 } | 104 } |
| 105 | 105 |
| 106 function TypedArrayCopyWithin(target, start, end) { | 106 function TypedArrayCopyWithin(target, start, end) { |
| 107 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 107 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 108 | 108 |
| 109 var length = %_TypedArrayGetLength(this); | 109 var length = %_TypedArrayGetLength(this); |
| 110 | 110 |
| 111 // TODO(littledan): Replace with a memcpy for better performance | 111 // TODO(littledan): Replace with a memcpy for better performance |
| 112 return InnerArrayCopyWithin(target, start, end, this, length); | 112 return InnerArrayCopyWithin(target, start, end, this, length); |
| 113 } | 113 } |
| 114 %FunctionSetLength(TypedArrayCopyWithin, 2); | 114 %FunctionSetLength(TypedArrayCopyWithin, 2); |
| 115 | 115 |
| 116 // ES6 draft 05-05-15, section 22.2.3.7 | 116 // ES6 draft 05-05-15, section 22.2.3.7 |
| 117 function TypedArrayEvery(f, receiver) { | 117 function TypedArrayEvery(f, receiver) { |
| 118 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 118 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 119 | 119 |
| 120 var length = %_TypedArrayGetLength(this); | 120 var length = %_TypedArrayGetLength(this); |
| 121 | 121 |
| 122 return InnerArrayEvery(f, receiver, this, length); | 122 return InnerArrayEvery(f, receiver, this, length); |
| 123 } | 123 } |
| 124 %FunctionSetLength(TypedArrayEvery, 1); | 124 %FunctionSetLength(TypedArrayEvery, 1); |
| 125 | 125 |
| 126 // ES6 draft 08-24-14, section 22.2.3.12 | 126 // ES6 draft 08-24-14, section 22.2.3.12 |
| 127 function TypedArrayForEach(f, receiver) { | 127 function TypedArrayForEach(f, receiver) { |
| 128 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 128 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 129 | 129 |
| 130 var length = %_TypedArrayGetLength(this); | 130 var length = %_TypedArrayGetLength(this); |
| 131 | 131 |
| 132 InnerArrayForEach(f, receiver, this, length); | 132 InnerArrayForEach(f, receiver, this, length); |
| 133 } | 133 } |
| 134 %FunctionSetLength(TypedArrayForEach, 1); | 134 %FunctionSetLength(TypedArrayForEach, 1); |
| 135 | 135 |
| 136 // ES6 draft 04-05-14 section 22.2.3.8 | 136 // ES6 draft 04-05-14 section 22.2.3.8 |
| 137 function TypedArrayFill(value, start, end) { | 137 function TypedArrayFill(value, start, end) { |
| 138 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 138 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 139 | 139 |
| 140 var length = %_TypedArrayGetLength(this); | 140 var length = %_TypedArrayGetLength(this); |
| 141 | 141 |
| 142 return InnerArrayFill(value, start, end, this, length); | 142 return InnerArrayFill(value, start, end, this, length); |
| 143 } | 143 } |
| 144 %FunctionSetLength(TypedArrayFill, 1); | 144 %FunctionSetLength(TypedArrayFill, 1); |
| 145 | 145 |
| 146 // ES6 draft 07-15-13, section 22.2.3.9 | 146 // ES6 draft 07-15-13, section 22.2.3.9 |
| 147 function TypedArrayFilter(predicate, thisArg) { | 147 function TypedArrayFilter(predicate, thisArg) { |
| 148 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 148 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 149 | 149 |
| 150 var length = %_TypedArrayGetLength(this); | 150 var length = %_TypedArrayGetLength(this); |
| 151 var array = InnerArrayFilter(predicate, thisArg, this, length); | 151 var array = InnerArrayFilter(predicate, thisArg, this, length); |
| 152 return ConstructTypedArrayLike(this, array); | 152 return ConstructTypedArrayLike(this, array); |
| 153 } | 153 } |
| 154 %FunctionSetLength(TypedArrayFilter, 1); | 154 %FunctionSetLength(TypedArrayFilter, 1); |
| 155 | 155 |
| 156 // ES6 draft 07-15-13, section 22.2.3.10 | 156 // ES6 draft 07-15-13, section 22.2.3.10 |
| 157 function TypedArrayFind(predicate, thisArg) { | 157 function TypedArrayFind(predicate, thisArg) { |
| 158 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 158 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 159 | 159 |
| 160 var length = %_TypedArrayGetLength(this); | 160 var length = %_TypedArrayGetLength(this); |
| 161 | 161 |
| 162 return InnerArrayFind(predicate, thisArg, this, length); | 162 return InnerArrayFind(predicate, thisArg, this, length); |
| 163 } | 163 } |
| 164 %FunctionSetLength(TypedArrayFind, 1); | 164 %FunctionSetLength(TypedArrayFind, 1); |
| 165 | 165 |
| 166 // ES6 draft 07-15-13, section 22.2.3.11 | 166 // ES6 draft 07-15-13, section 22.2.3.11 |
| 167 function TypedArrayFindIndex(predicate, thisArg) { | 167 function TypedArrayFindIndex(predicate, thisArg) { |
| 168 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 168 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 169 | 169 |
| 170 var length = %_TypedArrayGetLength(this); | 170 var length = %_TypedArrayGetLength(this); |
| 171 | 171 |
| 172 return InnerArrayFindIndex(predicate, thisArg, this, length); | 172 return InnerArrayFindIndex(predicate, thisArg, this, length); |
| 173 } | 173 } |
| 174 %FunctionSetLength(TypedArrayFindIndex, 1); | 174 %FunctionSetLength(TypedArrayFindIndex, 1); |
| 175 | 175 |
| 176 // ES6 draft 05-18-15, section 22.2.3.21 | 176 // ES6 draft 05-18-15, section 22.2.3.21 |
| 177 function TypedArrayReverse() { | 177 function TypedArrayReverse() { |
| 178 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 178 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 179 | 179 |
| 180 var length = %_TypedArrayGetLength(this); | 180 var length = %_TypedArrayGetLength(this); |
| 181 | 181 |
| 182 return InnerArrayReverse(this, length); | 182 return InnerArrayReverse(this, length); |
| 183 } | 183 } |
| 184 | 184 |
| 185 | 185 |
| 186 function TypedArrayComparefn(x, y) { | 186 function TypedArrayComparefn(x, y) { |
| 187 if (IsNaN(x) && IsNaN(y)) { | 187 if (IsNaN(x) && IsNaN(y)) { |
| 188 return IsNaN(y) ? 0 : 1; | 188 return IsNaN(y) ? 0 : 1; |
| 189 } | 189 } |
| 190 if (IsNaN(x)) { | 190 if (IsNaN(x)) { |
| 191 return 1; | 191 return 1; |
| 192 } | 192 } |
| 193 if (x === 0 && x === y) { | 193 if (x === 0 && x === y) { |
| 194 if (%_IsMinusZero(x)) { | 194 if (%_IsMinusZero(x)) { |
| 195 if (!%_IsMinusZero(y)) { | 195 if (!%_IsMinusZero(y)) { |
| 196 return -1; | 196 return -1; |
| 197 } | 197 } |
| 198 } else if (%_IsMinusZero(y)) { | 198 } else if (%_IsMinusZero(y)) { |
| 199 return 1; | 199 return 1; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 return x - y; | 202 return x - y; |
| 203 } | 203 } |
| 204 | 204 |
| 205 | 205 |
| 206 // ES6 draft 05-18-15, section 22.2.3.25 | 206 // ES6 draft 05-18-15, section 22.2.3.25 |
| 207 function TypedArraySort(comparefn) { | 207 function TypedArraySort(comparefn) { |
| 208 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 208 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 209 | 209 |
| 210 var length = %_TypedArrayGetLength(this); | 210 var length = %_TypedArrayGetLength(this); |
| 211 | 211 |
| 212 if (IS_UNDEFINED(comparefn)) { | 212 if (IS_UNDEFINED(comparefn)) { |
| 213 comparefn = TypedArrayComparefn; | 213 comparefn = TypedArrayComparefn; |
| 214 } | 214 } |
| 215 | 215 |
| 216 return %_CallFunction(this, length, comparefn, InnerArraySort); | 216 return %_CallFunction(this, length, comparefn, InnerArraySort); |
| 217 } | 217 } |
| 218 | 218 |
| 219 | 219 |
| 220 // ES6 section 22.2.3.13 | 220 // ES6 section 22.2.3.13 |
| 221 function TypedArrayIndexOf(element, index) { | 221 function TypedArrayIndexOf(element, index) { |
| 222 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 222 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 223 | 223 |
| 224 var length = %_TypedArrayGetLength(this); | 224 var length = %_TypedArrayGetLength(this); |
| 225 | 225 |
| 226 return %_CallFunction(this, element, index, length, InnerArrayIndexOf); | 226 return %_CallFunction(this, element, index, length, InnerArrayIndexOf); |
| 227 } | 227 } |
| 228 %FunctionSetLength(TypedArrayIndexOf, 1); | 228 %FunctionSetLength(TypedArrayIndexOf, 1); |
| 229 | 229 |
| 230 | 230 |
| 231 // ES6 section 22.2.3.16 | 231 // ES6 section 22.2.3.16 |
| 232 function TypedArrayLastIndexOf(element, index) { | 232 function TypedArrayLastIndexOf(element, index) { |
| 233 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 233 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 234 | 234 |
| 235 var length = %_TypedArrayGetLength(this); | 235 var length = %_TypedArrayGetLength(this); |
| 236 | 236 |
| 237 return %_CallFunction(this, element, index, length, | 237 return %_CallFunction(this, element, index, length, |
| 238 %_ArgumentsLength(), InnerArrayLastIndexOf); | 238 %_ArgumentsLength(), InnerArrayLastIndexOf); |
| 239 } | 239 } |
| 240 %FunctionSetLength(TypedArrayLastIndexOf, 1); | 240 %FunctionSetLength(TypedArrayLastIndexOf, 1); |
| 241 | 241 |
| 242 | 242 |
| 243 // ES6 draft 07-15-13, section 22.2.3.18 | 243 // ES6 draft 07-15-13, section 22.2.3.18 |
| 244 function TypedArrayMap(predicate, thisArg) { | 244 function TypedArrayMap(predicate, thisArg) { |
| 245 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 245 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 246 | 246 |
| 247 // TODO(littledan): Preallocate rather than making an intermediate | 247 // TODO(littledan): Preallocate rather than making an intermediate |
| 248 // InternalArray, for better performance. | 248 // InternalArray, for better performance. |
| 249 var length = %_TypedArrayGetLength(this); | 249 var length = %_TypedArrayGetLength(this); |
| 250 var array = InnerArrayMap(predicate, thisArg, this, length); | 250 var array = InnerArrayMap(predicate, thisArg, this, length); |
| 251 return ConstructTypedArrayLike(this, array); | 251 return ConstructTypedArrayLike(this, array); |
| 252 } | 252 } |
| 253 %FunctionSetLength(TypedArrayMap, 1); | 253 %FunctionSetLength(TypedArrayMap, 1); |
| 254 | 254 |
| 255 | 255 |
| 256 // ES6 draft 05-05-15, section 22.2.3.24 | 256 // ES6 draft 05-05-15, section 22.2.3.24 |
| 257 function TypedArraySome(f, receiver) { | 257 function TypedArraySome(f, receiver) { |
| 258 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 258 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 259 | 259 |
| 260 var length = %_TypedArrayGetLength(this); | 260 var length = %_TypedArrayGetLength(this); |
| 261 | 261 |
| 262 return InnerArraySome(f, receiver, this, length); | 262 return InnerArraySome(f, receiver, this, length); |
| 263 } | 263 } |
| 264 %FunctionSetLength(TypedArraySome, 1); | 264 %FunctionSetLength(TypedArraySome, 1); |
| 265 | 265 |
| 266 | 266 |
| 267 // ES6 section 22.2.3.27 | 267 // ES6 section 22.2.3.27 |
| 268 function TypedArrayToLocaleString() { | 268 function TypedArrayToLocaleString() { |
| 269 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 269 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 270 | 270 |
| 271 var length = %_TypedArrayGetLength(this); | 271 var length = %_TypedArrayGetLength(this); |
| 272 | 272 |
| 273 return InnerArrayToLocaleString(this, length); | 273 return InnerArrayToLocaleString(this, length); |
| 274 } | 274 } |
| 275 | 275 |
| 276 | 276 |
| 277 // ES6 section 22.2.3.28 | 277 // ES6 section 22.2.3.28 |
| 278 function TypedArrayToString() { | 278 function TypedArrayToString() { |
| 279 return %_CallFunction(this, ArrayToString); | 279 return %_CallFunction(this, ArrayToString); |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 // ES6 section 22.2.3.14 | 283 // ES6 section 22.2.3.14 |
| 284 function TypedArrayJoin(separator) { | 284 function TypedArrayJoin(separator) { |
| 285 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 285 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 286 | 286 |
| 287 var length = %_TypedArrayGetLength(this); | 287 var length = %_TypedArrayGetLength(this); |
| 288 | 288 |
| 289 return InnerArrayJoin(separator, this, length); | 289 return InnerArrayJoin(separator, this, length); |
| 290 } | 290 } |
| 291 | 291 |
| 292 | 292 |
| 293 // ES6 draft 07-15-13, section 22.2.3.19 | 293 // ES6 draft 07-15-13, section 22.2.3.19 |
| 294 function TypedArrayReduce(callback, current) { | 294 function TypedArrayReduce(callback, current) { |
| 295 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 295 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 296 | 296 |
| 297 var length = %_TypedArrayGetLength(this); | 297 var length = %_TypedArrayGetLength(this); |
| 298 return InnerArrayReduce(callback, current, this, length, | 298 return InnerArrayReduce(callback, current, this, length, |
| 299 %_ArgumentsLength()); | 299 %_ArgumentsLength()); |
| 300 } | 300 } |
| 301 %FunctionSetLength(TypedArrayReduce, 1); | 301 %FunctionSetLength(TypedArrayReduce, 1); |
| 302 | 302 |
| 303 | 303 |
| 304 // ES6 draft 07-15-13, section 22.2.3.19 | 304 // ES6 draft 07-15-13, section 22.2.3.19 |
| 305 function TypedArrayReduceRight(callback, current) { | 305 function TypedArrayReduceRight(callback, current) { |
| 306 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 306 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 307 | 307 |
| 308 var length = %_TypedArrayGetLength(this); | 308 var length = %_TypedArrayGetLength(this); |
| 309 return InnerArrayReduceRight(callback, current, this, length, | 309 return InnerArrayReduceRight(callback, current, this, length, |
| 310 %_ArgumentsLength()); | 310 %_ArgumentsLength()); |
| 311 } | 311 } |
| 312 %FunctionSetLength(TypedArrayReduceRight, 1); | 312 %FunctionSetLength(TypedArrayReduceRight, 1); |
| 313 | 313 |
| 314 | 314 |
| 315 function TypedArraySlice(start, end) { | 315 function TypedArraySlice(start, end) { |
| 316 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 316 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 317 var len = %_TypedArrayGetLength(this); | 317 var len = %_TypedArrayGetLength(this); |
| 318 | 318 |
| 319 var relativeStart = TO_INTEGER(start); | 319 var relativeStart = TO_INTEGER(start); |
| 320 | 320 |
| 321 var k; | 321 var k; |
| 322 if (relativeStart < 0) { | 322 if (relativeStart < 0) { |
| 323 k = MathMax(len + relativeStart, 0); | 323 k = MathMax(len + relativeStart, 0); |
| 324 } else { | 324 } else { |
| 325 k = MathMin(relativeStart, len); | 325 k = MathMin(relativeStart, len); |
| 326 } | 326 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 "some", TypedArraySome, | 404 "some", TypedArraySome, |
| 405 "sort", TypedArraySort, | 405 "sort", TypedArraySort, |
| 406 "toString", TypedArrayToString, | 406 "toString", TypedArrayToString, |
| 407 "toLocaleString", TypedArrayToLocaleString | 407 "toLocaleString", TypedArrayToLocaleString |
| 408 ]); | 408 ]); |
| 409 endmacro | 409 endmacro |
| 410 | 410 |
| 411 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 411 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
| 412 | 412 |
| 413 }) | 413 }) |
| OLD | NEW |