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

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

Issue 2735563002: Migrate %TypedArray%.prototype.fill to C++ (Closed)
Patch Set: minor change Created 3 years, 9 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 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
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 // array.js has to come before typedarray.js for this to work 14 // array.js has to come before typedarray.js for this to work
15 var ArrayToString = utils.ImportNow("ArrayToString"); 15 var ArrayToString = utils.ImportNow("ArrayToString");
16 var ArrayValues; 16 var ArrayValues;
17 var GetIterator; 17 var GetIterator;
18 var GetMethod; 18 var GetMethod;
19 var GlobalArray = global.Array; 19 var GlobalArray = global.Array;
20 var GlobalArrayBuffer = global.ArrayBuffer; 20 var GlobalArrayBuffer = global.ArrayBuffer;
21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype;
22 var GlobalObject = global.Object; 22 var GlobalObject = global.Object;
23 var InnerArrayEvery; 23 var InnerArrayEvery;
24 var InnerArrayFill;
25 var InnerArrayFilter; 24 var InnerArrayFilter;
26 var InnerArrayFind; 25 var InnerArrayFind;
27 var InnerArrayFindIndex; 26 var InnerArrayFindIndex;
28 var InnerArrayForEach; 27 var InnerArrayForEach;
29 var InnerArrayJoin; 28 var InnerArrayJoin;
30 var InnerArrayReduce; 29 var InnerArrayReduce;
31 var InnerArrayReduceRight; 30 var InnerArrayReduceRight;
32 var InnerArraySome; 31 var InnerArraySome;
33 var InnerArraySort; 32 var InnerArraySort;
34 var InnerArrayToLocaleString; 33 var InnerArrayToLocaleString;
(...skipping 26 matching lines...) Expand all
61 60
62 TYPED_ARRAYS(DECLARE_GLOBALS) 61 TYPED_ARRAYS(DECLARE_GLOBALS)
63 62
64 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); 63 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
65 64
66 utils.Import(function(from) { 65 utils.Import(function(from) {
67 ArrayValues = from.ArrayValues; 66 ArrayValues = from.ArrayValues;
68 GetIterator = from.GetIterator; 67 GetIterator = from.GetIterator;
69 GetMethod = from.GetMethod; 68 GetMethod = from.GetMethod;
70 InnerArrayEvery = from.InnerArrayEvery; 69 InnerArrayEvery = from.InnerArrayEvery;
71 InnerArrayFill = from.InnerArrayFill;
72 InnerArrayFilter = from.InnerArrayFilter; 70 InnerArrayFilter = from.InnerArrayFilter;
73 InnerArrayFind = from.InnerArrayFind; 71 InnerArrayFind = from.InnerArrayFind;
74 InnerArrayFindIndex = from.InnerArrayFindIndex; 72 InnerArrayFindIndex = from.InnerArrayFindIndex;
75 InnerArrayForEach = from.InnerArrayForEach; 73 InnerArrayForEach = from.InnerArrayForEach;
76 InnerArrayJoin = from.InnerArrayJoin; 74 InnerArrayJoin = from.InnerArrayJoin;
77 InnerArrayReduce = from.InnerArrayReduce; 75 InnerArrayReduce = from.InnerArrayReduce;
78 InnerArrayReduceRight = from.InnerArrayReduceRight; 76 InnerArrayReduceRight = from.InnerArrayReduceRight;
79 InnerArraySome = from.InnerArraySome; 77 InnerArraySome = from.InnerArraySome;
80 InnerArraySort = from.InnerArraySort; 78 InnerArraySort = from.InnerArraySort;
81 InnerArrayToLocaleString = from.InnerArrayToLocaleString; 79 InnerArrayToLocaleString = from.InnerArrayToLocaleString;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 function TypedArrayForEach(f, receiver) { 449 function TypedArrayForEach(f, receiver) {
452 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 450 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
453 451
454 var length = %_TypedArrayGetLength(this); 452 var length = %_TypedArrayGetLength(this);
455 453
456 InnerArrayForEach(f, receiver, this, length); 454 InnerArrayForEach(f, receiver, this, length);
457 } 455 }
458 %FunctionSetLength(TypedArrayForEach, 1); 456 %FunctionSetLength(TypedArrayForEach, 1);
459 457
460 458
461 // ES6 draft 04-05-14 section 22.2.3.8
462 function TypedArrayFill(value, start, end) {
463 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
464
465 var length = %_TypedArrayGetLength(this);
466
467 return InnerArrayFill(value, start, end, this, length);
468 }
469 %FunctionSetLength(TypedArrayFill, 1);
470
471
472 // ES6 draft 07-15-13, section 22.2.3.9 459 // ES6 draft 07-15-13, section 22.2.3.9
473 function TypedArrayFilter(f, thisArg) { 460 function TypedArrayFilter(f, thisArg) {
474 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 461 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
475 462
476 var length = %_TypedArrayGetLength(this); 463 var length = %_TypedArrayGetLength(this);
477 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 464 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
478 var result = new InternalArray(); 465 var result = new InternalArray();
479 InnerArrayFilter(f, thisArg, this, length, result); 466 InnerArrayFilter(f, thisArg, this, length, result);
480 var captured = result.length; 467 var captured = result.length;
481 var output = TypedArraySpeciesCreate(this, captured); 468 var output = TypedArraySpeciesCreate(this, captured);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 utils.InstallFunctions(GlobalTypedArray, DONT_ENUM, [ 807 utils.InstallFunctions(GlobalTypedArray, DONT_ENUM, [
821 "from", TypedArrayFrom, 808 "from", TypedArrayFrom,
822 "of", TypedArrayOf 809 "of", TypedArrayOf
823 ]); 810 ]);
824 utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol, 811 utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol,
825 TypedArrayGetToStringTag); 812 TypedArrayGetToStringTag);
826 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ 813 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [
827 "subarray", TypedArraySubArray, 814 "subarray", TypedArraySubArray,
828 "set", TypedArraySet, 815 "set", TypedArraySet,
829 "every", TypedArrayEvery, 816 "every", TypedArrayEvery,
830 "fill", TypedArrayFill,
831 "filter", TypedArrayFilter, 817 "filter", TypedArrayFilter,
832 "find", TypedArrayFind, 818 "find", TypedArrayFind,
833 "findIndex", TypedArrayFindIndex, 819 "findIndex", TypedArrayFindIndex,
834 "includes", TypedArrayIncludes, 820 "includes", TypedArrayIncludes,
835 "indexOf", TypedArrayIndexOf, 821 "indexOf", TypedArrayIndexOf,
836 "join", TypedArrayJoin, 822 "join", TypedArrayJoin,
837 "lastIndexOf", TypedArrayLastIndexOf, 823 "lastIndexOf", TypedArrayLastIndexOf,
838 "forEach", TypedArrayForEach, 824 "forEach", TypedArrayForEach,
839 "map", TypedArrayMap, 825 "map", TypedArrayMap,
840 "reduce", TypedArrayReduce, 826 "reduce", TypedArrayReduce,
(...skipping 21 matching lines...) Expand all
862 %AddNamedProperty(GlobalNAME.prototype, 848 %AddNamedProperty(GlobalNAME.prototype,
863 "constructor", global.NAME, DONT_ENUM); 849 "constructor", global.NAME, DONT_ENUM);
864 %AddNamedProperty(GlobalNAME.prototype, 850 %AddNamedProperty(GlobalNAME.prototype,
865 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 851 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
866 READ_ONLY | DONT_ENUM | DONT_DELETE); 852 READ_ONLY | DONT_ENUM | DONT_DELETE);
867 endmacro 853 endmacro
868 854
869 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 855 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
870 856
871 }) 857 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698