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

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

Issue 1126213002: Wrap runtime.js in a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix 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/debug-debugger.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 (function() { 5 (function() {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 var GlobalArray = global.Array; 11 var GlobalArray = global.Array;
12 var GlobalSymbol = global.Symbol; 12 var GlobalSymbol = global.Symbol;
13 13
14 // ------------------------------------------------------------------- 14 // -------------------------------------------------------------------
15 15
16 // ES6 draft 03-17-15, section 22.1.3.3 16 // ES6 draft 03-17-15, section 22.1.3.3
17 function ArrayCopyWithin(target, start, end) { 17 function ArrayCopyWithin(target, start, end) {
18 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); 18 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin");
19 19
20 var array = TO_OBJECT_INLINE(this); 20 var array = TO_OBJECT_INLINE(this);
21 var length = ToLength(array.length); 21 var length = $toLength(array.length);
22 22
23 target = TO_INTEGER(target); 23 target = TO_INTEGER(target);
24 var to; 24 var to;
25 if (target < 0) { 25 if (target < 0) {
26 to = $max(length + target, 0); 26 to = $max(length + target, 0);
27 } else { 27 } else {
28 to = $min(target, length); 28 to = $min(target, length);
29 } 29 }
30 30
31 start = TO_INTEGER(start); 31 start = TO_INTEGER(start);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 count--; 63 count--;
64 } 64 }
65 65
66 return array; 66 return array;
67 } 67 }
68 68
69 // ES6 draft 07-15-13, section 15.4.3.23 69 // ES6 draft 07-15-13, section 15.4.3.23
70 function ArrayFind(predicate /* thisArg */) { // length == 1 70 function ArrayFind(predicate /* thisArg */) { // length == 1
71 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); 71 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
72 72
73 var array = ToObject(this); 73 var array = $toObject(this);
74 var length = ToInteger(array.length); 74 var length = $toInteger(array.length);
75 75
76 if (!IS_SPEC_FUNCTION(predicate)) { 76 if (!IS_SPEC_FUNCTION(predicate)) {
77 throw MakeTypeError(kCalledNonCallable, predicate); 77 throw MakeTypeError(kCalledNonCallable, predicate);
78 } 78 }
79 79
80 var thisArg; 80 var thisArg;
81 if (%_ArgumentsLength() > 1) { 81 if (%_ArgumentsLength() > 1) {
82 thisArg = %_Arguments(1); 82 thisArg = %_Arguments(1);
83 } 83 }
84 84
85 var needs_wrapper = false; 85 var needs_wrapper = false;
86 if (IS_NULL(thisArg)) { 86 if (IS_NULL(thisArg)) {
87 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; 87 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
88 } else if (!IS_UNDEFINED(thisArg)) { 88 } else if (!IS_UNDEFINED(thisArg)) {
89 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); 89 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
90 } 90 }
91 91
92 for (var i = 0; i < length; i++) { 92 for (var i = 0; i < length; i++) {
93 if (i in array) { 93 if (i in array) {
94 var element = array[i]; 94 var element = array[i];
95 var newThisArg = needs_wrapper ? ToObject(thisArg) : thisArg; 95 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg;
96 if (%_CallFunction(newThisArg, element, i, array, predicate)) { 96 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
97 return element; 97 return element;
98 } 98 }
99 } 99 }
100 } 100 }
101 101
102 return; 102 return;
103 } 103 }
104 104
105 105
106 // ES6 draft 07-15-13, section 15.4.3.24 106 // ES6 draft 07-15-13, section 15.4.3.24
107 function ArrayFindIndex(predicate /* thisArg */) { // length == 1 107 function ArrayFindIndex(predicate /* thisArg */) { // length == 1
108 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); 108 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
109 109
110 var array = ToObject(this); 110 var array = $toObject(this);
111 var length = ToInteger(array.length); 111 var length = $toInteger(array.length);
112 112
113 if (!IS_SPEC_FUNCTION(predicate)) { 113 if (!IS_SPEC_FUNCTION(predicate)) {
114 throw MakeTypeError(kCalledNonCallable, predicate); 114 throw MakeTypeError(kCalledNonCallable, predicate);
115 } 115 }
116 116
117 var thisArg; 117 var thisArg;
118 if (%_ArgumentsLength() > 1) { 118 if (%_ArgumentsLength() > 1) {
119 thisArg = %_Arguments(1); 119 thisArg = %_Arguments(1);
120 } 120 }
121 121
122 var needs_wrapper = false; 122 var needs_wrapper = false;
123 if (IS_NULL(thisArg)) { 123 if (IS_NULL(thisArg)) {
124 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; 124 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
125 } else if (!IS_UNDEFINED(thisArg)) { 125 } else if (!IS_UNDEFINED(thisArg)) {
126 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); 126 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
127 } 127 }
128 128
129 for (var i = 0; i < length; i++) { 129 for (var i = 0; i < length; i++) {
130 if (i in array) { 130 if (i in array) {
131 var element = array[i]; 131 var element = array[i];
132 var newThisArg = needs_wrapper ? ToObject(thisArg) : thisArg; 132 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg;
133 if (%_CallFunction(newThisArg, element, i, array, predicate)) { 133 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
134 return i; 134 return i;
135 } 135 }
136 } 136 }
137 } 137 }
138 138
139 return -1; 139 return -1;
140 } 140 }
141 141
142 142
143 // ES6, draft 04-05-14, section 22.1.3.6 143 // ES6, draft 04-05-14, section 22.1.3.6
144 function ArrayFill(value /* [, start [, end ] ] */) { // length == 1 144 function ArrayFill(value /* [, start [, end ] ] */) { // length == 1
145 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); 145 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
146 146
147 var array = ToObject(this); 147 var array = $toObject(this);
148 var length = TO_UINT32(array.length); 148 var length = TO_UINT32(array.length);
149 149
150 var i = 0; 150 var i = 0;
151 var end = length; 151 var end = length;
152 152
153 if (%_ArgumentsLength() > 1) { 153 if (%_ArgumentsLength() > 1) {
154 i = %_Arguments(1); 154 i = %_Arguments(1);
155 i = IS_UNDEFINED(i) ? 0 : TO_INTEGER(i); 155 i = IS_UNDEFINED(i) ? 0 : TO_INTEGER(i);
156 if (%_ArgumentsLength() > 2) { 156 if (%_ArgumentsLength() > 2) {
157 end = %_Arguments(2); 157 end = %_Arguments(2);
(...skipping 19 matching lines...) Expand all
177 throw MakeTypeError(kArrayFunctionsOnFrozen); 177 throw MakeTypeError(kArrayFunctionsOnFrozen);
178 } 178 }
179 179
180 for (; i < end; i++) 180 for (; i < end; i++)
181 array[i] = value; 181 array[i] = value;
182 return array; 182 return array;
183 } 183 }
184 184
185 // ES6, draft 10-14-14, section 22.1.2.1 185 // ES6, draft 10-14-14, section 22.1.2.1
186 function ArrayFrom(arrayLike, mapfn, receiver) { 186 function ArrayFrom(arrayLike, mapfn, receiver) {
187 var items = ToObject(arrayLike); 187 var items = $toObject(arrayLike);
188 var mapping = !IS_UNDEFINED(mapfn); 188 var mapping = !IS_UNDEFINED(mapfn);
189 189
190 if (mapping) { 190 if (mapping) {
191 if (!IS_SPEC_FUNCTION(mapfn)) { 191 if (!IS_SPEC_FUNCTION(mapfn)) {
192 throw MakeTypeError(kCalledNonCallable, mapfn); 192 throw MakeTypeError(kCalledNonCallable, mapfn);
193 } else if (%IsSloppyModeFunction(mapfn)) { 193 } else if (%IsSloppyModeFunction(mapfn)) {
194 if (IS_NULL(receiver)) { 194 if (IS_NULL(receiver)) {
195 receiver = UNDEFINED; 195 receiver = UNDEFINED;
196 } else if (!IS_UNDEFINED(receiver)) { 196 } else if (!IS_UNDEFINED(receiver)) {
197 receiver = TO_OBJECT_INLINE(receiver); 197 receiver = TO_OBJECT_INLINE(receiver);
(...skipping 27 matching lines...) Expand all
225 225
226 nextValue = next.value; 226 nextValue = next.value;
227 if (mapping) { 227 if (mapping) {
228 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); 228 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
229 } else { 229 } else {
230 mappedValue = nextValue; 230 mappedValue = nextValue;
231 } 231 }
232 %AddElement(result, k++, mappedValue, NONE); 232 %AddElement(result, k++, mappedValue, NONE);
233 } 233 }
234 } else { 234 } else {
235 var len = ToLength(items.length); 235 var len = $toLength(items.length);
236 result = %IsConstructor(this) ? new this(len) : new $Array(len); 236 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len);
237 237
238 for (k = 0; k < len; ++k) { 238 for (k = 0; k < len; ++k) {
239 nextValue = items[k]; 239 nextValue = items[k];
240 if (mapping) { 240 if (mapping) {
241 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); 241 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
242 } else { 242 } else {
243 mappedValue = nextValue; 243 mappedValue = nextValue;
244 } 244 }
245 %AddElement(result, k, mappedValue, NONE); 245 %AddElement(result, k, mappedValue, NONE);
246 } 246 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 281
282 // Set up the non-enumerable functions on the Array prototype object. 282 // Set up the non-enumerable functions on the Array prototype object.
283 $installFunctions(GlobalArray.prototype, DONT_ENUM, [ 283 $installFunctions(GlobalArray.prototype, DONT_ENUM, [
284 "copyWithin", ArrayCopyWithin, 284 "copyWithin", ArrayCopyWithin,
285 "find", ArrayFind, 285 "find", ArrayFind,
286 "findIndex", ArrayFindIndex, 286 "findIndex", ArrayFindIndex,
287 "fill", ArrayFill 287 "fill", ArrayFill
288 ]); 288 ]);
289 289
290 })(); 290 })();
OLDNEW
« no previous file with comments | « src/debug-debugger.js ('k') | src/harmony-array-includes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698