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

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

Issue 1154743003: Revert of Hook up more import/exports in natives. (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
« no previous file with comments | « src/generator.js ('k') | src/harmony-array-includes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 var $innerArrayCopyWithin;
6 var $innerArrayFill;
7 var $innerArrayFind;
8 var $innerArrayFindIndex;
9 var $arrayFrom;
10
5 (function(global, utils) { 11 (function(global, utils) {
6 12
7 'use strict'; 13 'use strict';
8 14
9 %CheckIsBootstrapping(); 15 %CheckIsBootstrapping();
10 16
11 // ------------------------------------------------------------------- 17 // -------------------------------------------------------------------
12 // Imports 18 // Imports
13 19
14 var GlobalArray = global.Array; 20 var GlobalArray = global.Array;
15 var GlobalSymbol = global.Symbol; 21 var GlobalSymbol = global.Symbol;
16 22
17 var GetIterator;
18 var GetMethod;
19 var MathMax; 23 var MathMax;
20 var MathMin; 24 var MathMin;
21 var ObjectIsFrozen;
22 25
23 utils.Import(function(from) { 26 utils.Import(function(from) {
24 GetIterator = from.GetIterator;
25 GetMethod = from.GetMethod;
26 MathMax = from.MathMax; 27 MathMax = from.MathMax;
27 MathMin = from.MathMin; 28 MathMin = from.MathMin;
28 ObjectIsFrozen = from.ObjectIsFrozen;
29 }); 29 });
30 30
31 // ------------------------------------------------------------------- 31 // -------------------------------------------------------------------
32 32
33 function InnerArrayCopyWithin(target, start, end, array, length) { 33 function InnerArrayCopyWithin(target, start, end, array, length) {
34 target = TO_INTEGER(target); 34 target = TO_INTEGER(target);
35 var to; 35 var to;
36 if (target < 0) { 36 if (target < 0) {
37 to = MathMax(length + target, 0); 37 to = MathMax(length + target, 0);
38 } else { 38 } else {
(...skipping 30 matching lines...) Expand all
69 } else { 69 } else {
70 delete array[to]; 70 delete array[to];
71 } 71 }
72 from = from + direction; 72 from = from + direction;
73 to = to + direction; 73 to = to + direction;
74 count--; 74 count--;
75 } 75 }
76 76
77 return array; 77 return array;
78 } 78 }
79 $innerArrayCopyWithin = InnerArrayCopyWithin;
79 80
80 // ES6 draft 03-17-15, section 22.1.3.3 81 // ES6 draft 03-17-15, section 22.1.3.3
81 function ArrayCopyWithin(target, start, end) { 82 function ArrayCopyWithin(target, start, end) {
82 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); 83 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin");
83 84
84 var array = TO_OBJECT_INLINE(this); 85 var array = TO_OBJECT_INLINE(this);
85 var length = $toLength(array.length); 86 var length = $toLength(array.length);
86 87
87 return InnerArrayCopyWithin(target, start, end, array, length); 88 return InnerArrayCopyWithin(target, start, end, array, length);
88 } 89 }
(...skipping 15 matching lines...) Expand all
104 var element = array[i]; 105 var element = array[i];
105 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; 106 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg;
106 if (%_CallFunction(newThisArg, element, i, array, predicate)) { 107 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
107 return element; 108 return element;
108 } 109 }
109 } 110 }
110 } 111 }
111 112
112 return; 113 return;
113 } 114 }
115 $innerArrayFind = InnerArrayFind;
114 116
115 // ES6 draft 07-15-13, section 15.4.3.23 117 // ES6 draft 07-15-13, section 15.4.3.23
116 function ArrayFind(predicate, thisArg) { 118 function ArrayFind(predicate, thisArg) {
117 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); 119 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
118 120
119 var array = $toObject(this); 121 var array = $toObject(this);
120 var length = $toInteger(array.length); 122 var length = $toInteger(array.length);
121 123
122 return InnerArrayFind(predicate, thisArg, array, length); 124 return InnerArrayFind(predicate, thisArg, array, length);
123 } 125 }
(...skipping 15 matching lines...) Expand all
139 var element = array[i]; 141 var element = array[i];
140 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; 142 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg;
141 if (%_CallFunction(newThisArg, element, i, array, predicate)) { 143 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
142 return i; 144 return i;
143 } 145 }
144 } 146 }
145 } 147 }
146 148
147 return -1; 149 return -1;
148 } 150 }
151 $innerArrayFindIndex = InnerArrayFindIndex;
149 152
150 // ES6 draft 07-15-13, section 15.4.3.24 153 // ES6 draft 07-15-13, section 15.4.3.24
151 function ArrayFindIndex(predicate, thisArg) { 154 function ArrayFindIndex(predicate, thisArg) {
152 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); 155 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
153 156
154 var array = $toObject(this); 157 var array = $toObject(this);
155 var length = $toInteger(array.length); 158 var length = $toInteger(array.length);
156 159
157 return InnerArrayFindIndex(predicate, thisArg, array, length); 160 return InnerArrayFindIndex(predicate, thisArg, array, length);
158 } 161 }
(...skipping 10 matching lines...) Expand all
169 if (i > length) i = length; 172 if (i > length) i = length;
170 } 173 }
171 174
172 if (end < 0) { 175 if (end < 0) {
173 end += length; 176 end += length;
174 if (end < 0) end = 0; 177 if (end < 0) end = 0;
175 } else { 178 } else {
176 if (end > length) end = length; 179 if (end > length) end = length;
177 } 180 }
178 181
179 if ((end - i) > 0 && ObjectIsFrozen(array)) { 182 if ((end - i) > 0 && $objectIsFrozen(array)) {
180 throw MakeTypeError(kArrayFunctionsOnFrozen); 183 throw MakeTypeError(kArrayFunctionsOnFrozen);
181 } 184 }
182 185
183 for (; i < end; i++) 186 for (; i < end; i++)
184 array[i] = value; 187 array[i] = value;
185 return array; 188 return array;
186 } 189 }
190 $innerArrayFill = InnerArrayFill;
187 191
188 // ES6, draft 04-05-14, section 22.1.3.6 192 // ES6, draft 04-05-14, section 22.1.3.6
189 function ArrayFill(value, start, end) { 193 function ArrayFill(value, start, end) {
190 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); 194 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
191 195
192 var array = $toObject(this); 196 var array = $toObject(this);
193 var length = TO_UINT32(array.length); 197 var length = TO_UINT32(array.length);
194 198
195 return InnerArrayFill(value, start, end, array, length); 199 return InnerArrayFill(value, start, end, array, length);
196 } 200 }
197 201
198 // ES6, draft 10-14-14, section 22.1.2.1 202 // ES6, draft 10-14-14, section 22.1.2.1
199 function ArrayFrom(arrayLike, mapfn, receiver) { 203 function ArrayFrom(arrayLike, mapfn, receiver) {
200 var items = $toObject(arrayLike); 204 var items = $toObject(arrayLike);
201 var mapping = !IS_UNDEFINED(mapfn); 205 var mapping = !IS_UNDEFINED(mapfn);
202 206
203 if (mapping) { 207 if (mapping) {
204 if (!IS_SPEC_FUNCTION(mapfn)) { 208 if (!IS_SPEC_FUNCTION(mapfn)) {
205 throw MakeTypeError(kCalledNonCallable, mapfn); 209 throw MakeTypeError(kCalledNonCallable, mapfn);
206 } else if (%IsSloppyModeFunction(mapfn)) { 210 } else if (%IsSloppyModeFunction(mapfn)) {
207 if (IS_NULL(receiver)) { 211 if (IS_NULL(receiver)) {
208 receiver = UNDEFINED; 212 receiver = UNDEFINED;
209 } else if (!IS_UNDEFINED(receiver)) { 213 } else if (!IS_UNDEFINED(receiver)) {
210 receiver = TO_OBJECT_INLINE(receiver); 214 receiver = TO_OBJECT_INLINE(receiver);
211 } 215 }
212 } 216 }
213 } 217 }
214 218
215 var iterable = GetMethod(items, symbolIterator); 219 var iterable = $getMethod(items, symbolIterator);
216 var k; 220 var k;
217 var result; 221 var result;
218 var mappedValue; 222 var mappedValue;
219 var nextValue; 223 var nextValue;
220 224
221 if (!IS_UNDEFINED(iterable)) { 225 if (!IS_UNDEFINED(iterable)) {
222 result = %IsConstructor(this) ? new this() : []; 226 result = %IsConstructor(this) ? new this() : [];
223 227
224 var iterator = GetIterator(items, iterable); 228 var iterator = $getIterator(items, iterable);
225 229
226 k = 0; 230 k = 0;
227 while (true) { 231 while (true) {
228 var next = iterator.next(); 232 var next = iterator.next();
229 233
230 if (!IS_OBJECT(next)) { 234 if (!IS_OBJECT(next)) {
231 throw MakeTypeError(kIteratorResultNotAnObject, next); 235 throw MakeTypeError(kIteratorResultNotAnObject, next);
232 } 236 }
233 237
234 if (next.done) { 238 if (next.done) {
(...skipping 20 matching lines...) Expand all
255 } else { 259 } else {
256 mappedValue = nextValue; 260 mappedValue = nextValue;
257 } 261 }
258 %AddElement(result, k, mappedValue, NONE); 262 %AddElement(result, k, mappedValue, NONE);
259 } 263 }
260 264
261 result.length = k; 265 result.length = k;
262 return result; 266 return result;
263 } 267 }
264 } 268 }
269 $arrayFrom = ArrayFrom;
265 270
266 // ES6, draft 05-22-14, section 22.1.2.3 271 // ES6, draft 05-22-14, section 22.1.2.3
267 function ArrayOf() { 272 function ArrayOf() {
268 var length = %_ArgumentsLength(); 273 var length = %_ArgumentsLength();
269 var constructor = this; 274 var constructor = this;
270 // TODO: Implement IsConstructor (ES6 section 7.2.5) 275 // TODO: Implement IsConstructor (ES6 section 7.2.5)
271 var array = %IsConstructor(constructor) ? new constructor(length) : []; 276 var array = %IsConstructor(constructor) ? new constructor(length) : [];
272 for (var i = 0; i < length; i++) { 277 for (var i = 0; i < length; i++) {
273 %AddElement(array, i, %_Arguments(i), NONE); 278 %AddElement(array, i, %_Arguments(i), NONE);
274 } 279 }
275 array.length = length; 280 array.length = length;
276 return array; 281 return array;
277 } 282 }
278 283
279 // ------------------------------------------------------------------- 284 // -------------------------------------------------------------------
280 285
281 utils.InstallConstants(GlobalSymbol, [ 286 $installConstants(GlobalSymbol, [
282 // TODO(dslomov, caitp): Move to symbol.js when shipping 287 // TODO(dslomov, caitp): Move to symbol.js when shipping
283 "isConcatSpreadable", symbolIsConcatSpreadable 288 "isConcatSpreadable", symbolIsConcatSpreadable
284 ]); 289 ]);
285 290
286 %FunctionSetLength(ArrayCopyWithin, 2); 291 %FunctionSetLength(ArrayCopyWithin, 2);
287 %FunctionSetLength(ArrayFrom, 1); 292 %FunctionSetLength(ArrayFrom, 1);
288 %FunctionSetLength(ArrayFill, 1); 293 %FunctionSetLength(ArrayFill, 1);
289 %FunctionSetLength(ArrayFind, 1); 294 %FunctionSetLength(ArrayFind, 1);
290 %FunctionSetLength(ArrayFindIndex, 1); 295 %FunctionSetLength(ArrayFindIndex, 1);
291 296
292 // Set up non-enumerable functions on the Array object. 297 // Set up non-enumerable functions on the Array object.
293 utils.InstallFunctions(GlobalArray, DONT_ENUM, [ 298 $installFunctions(GlobalArray, DONT_ENUM, [
294 "from", ArrayFrom, 299 "from", ArrayFrom,
295 "of", ArrayOf 300 "of", ArrayOf
296 ]); 301 ]);
297 302
298 // Set up the non-enumerable functions on the Array prototype object. 303 // Set up the non-enumerable functions on the Array prototype object.
299 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ 304 $installFunctions(GlobalArray.prototype, DONT_ENUM, [
300 "copyWithin", ArrayCopyWithin, 305 "copyWithin", ArrayCopyWithin,
301 "find", ArrayFind, 306 "find", ArrayFind,
302 "findIndex", ArrayFindIndex, 307 "findIndex", ArrayFindIndex,
303 "fill", ArrayFill 308 "fill", ArrayFill
304 ]); 309 ]);
305 310
306 // -------------------------------------------------------------------
307 // Exports
308
309 utils.Export(function(to) {
310 to.ArrayFrom = ArrayFrom;
311 to.InnerArrayCopyWithin = InnerArrayCopyWithin;
312 to.InnerArrayFill = InnerArrayFill;
313 to.InnerArrayFind = InnerArrayFind;
314 to.InnerArrayFindIndex = InnerArrayFindIndex;
315 });
316
317 }) 311 })
OLDNEW
« no previous file with comments | « src/generator.js ('k') | src/harmony-array-includes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698