Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/harmony-typedarray.js

Issue 1136663005: Implement %TypedArray%.{fill,find,findIndex} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, exports) { 5 (function(global, exports) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // ES6 draft 08-24-14, section 22.2.3.12 52 // ES6 draft 08-24-14, section 22.2.3.12
53 function TypedArrayForEach(f, receiver) { 53 function TypedArrayForEach(f, receiver) {
54 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 54 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
55 55
56 var length = %_TypedArrayGetLength(this); 56 var length = %_TypedArrayGetLength(this);
57 57
58 $innerArrayForEach(f, receiver, this, length); 58 $innerArrayForEach(f, receiver, this, length);
59 } 59 }
60 %FunctionSetLength(TypedArrayForEach, 1); 60 %FunctionSetLength(TypedArrayForEach, 1);
61 61
62 // ES6 draft 04-05-14 section 22.2.3.8
63 function TypedArrayFill(value, start , end) {
64 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
65
66 var length = %_TypedArrayGetLength(this);
67
68 return $innerArrayFill(value, start, end, this, length);
69 }
70 %FunctionSetLength(TypedArrayFill, 1);
71
72 // ES6 draft 07-15-13, section 22.2.3.10
73 function TypedArrayFind(predicate, thisArg) {
74 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
75
76 var length = %_TypedArrayGetLength(this);
77
78 return $innerArrayFind(predicate, thisArg, this, length);
79 }
80 %FunctionSetLength(TypedArrayFind, 1);
81
82 // ES6 draft 07-15-13, section 22.2.3.11
83 function TypedArrayFindIndex(predicate, thisArg) {
84 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
85
86 var length = %_TypedArrayGetLength(this);
87
88 return $innerArrayFindIndex(predicate, thisArg, this, length);
89 }
90 %FunctionSetLength(TypedArrayFindIndex, 1);
91
92
62 // ES6 draft 08-24-14, section 22.2.2.2 93 // ES6 draft 08-24-14, section 22.2.2.2
63 function TypedArrayOf() { 94 function TypedArrayOf() {
64 var length = %_ArgumentsLength(); 95 var length = %_ArgumentsLength();
65 var array = new this(length); 96 var array = new this(length);
66 for (var i = 0; i < length; i++) { 97 for (var i = 0; i < length; i++) {
67 array[i] = %_Arguments(i); 98 array[i] = %_Arguments(i);
68 } 99 }
69 return array; 100 return array;
70 } 101 }
71 102
72 macro EXTEND_TYPED_ARRAY(NAME) 103 macro EXTEND_TYPED_ARRAY(NAME)
73 // Set up non-enumerable functions on the object. 104 // Set up non-enumerable functions on the object.
74 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ 105 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [
75 "of", TypedArrayOf 106 "of", TypedArrayOf
76 ]); 107 ]);
77 108
78 // Set up non-enumerable functions on the prototype object. 109 // Set up non-enumerable functions on the prototype object.
79 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ 110 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [
80 "copyWithin", TypedArrayCopyWithin, 111 "copyWithin", TypedArrayCopyWithin,
81 "every", TypedArrayEvery, 112 "every", TypedArrayEvery,
82 "forEach", TypedArrayForEach 113 "forEach", TypedArrayForEach,
114 "find", TypedArrayFind,
115 "findIndex", TypedArrayFindIndex,
116 "fill", TypedArrayFill
83 ]); 117 ]);
84 endmacro 118 endmacro
85 119
86 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 120 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
87 121
88 }) 122 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698