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

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

Issue 851163007: Implement IsConstructor() abstract operation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: All raw pointers converted to handles Created 5 years, 11 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 | « no previous file | src/runtime/runtime.h » ('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 'use strict'; 5 'use strict';
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 } 143 }
144 144
145 var iterable = ToIterable(items); 145 var iterable = ToIterable(items);
146 var k; 146 var k;
147 var result; 147 var result;
148 var mappedValue; 148 var mappedValue;
149 var nextValue; 149 var nextValue;
150 150
151 if (!IS_UNDEFINED(iterable)) { 151 if (!IS_UNDEFINED(iterable)) {
152 result = IS_SPEC_FUNCTION(this) && this.prototype ? new this() : []; 152 result = %IsConstructor(this) ? new this() : [];
153 153
154 k = 0; 154 k = 0;
155 for (nextValue of items) { 155 for (nextValue of items) {
156 if (mapping) mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); 156 if (mapping) mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
157 else mappedValue = nextValue; 157 else mappedValue = nextValue;
158 %AddElement(result, k++, mappedValue, NONE); 158 %AddElement(result, k++, mappedValue, NONE);
159 } 159 }
160 160
161 result.length = k; 161 result.length = k;
162 return result; 162 return result;
163 } else { 163 } else {
164 var len = ToLength(items.length); 164 var len = ToLength(items.length);
165 result = IS_SPEC_FUNCTION(this) && this.prototype ? new this(len) : 165 result = %IsConstructor(this) ? new this(len) : new $Array(len);
166 new $Array(len);
167 166
168 for (k = 0; k < len; ++k) { 167 for (k = 0; k < len; ++k) {
169 nextValue = items[k]; 168 nextValue = items[k];
170 if (mapping) mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); 169 if (mapping) mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
171 else mappedValue = nextValue; 170 else mappedValue = nextValue;
172 %AddElement(result, k, mappedValue, NONE); 171 %AddElement(result, k, mappedValue, NONE);
173 } 172 }
174 173
175 result.length = k; 174 result.length = k;
176 return result; 175 return result;
177 } 176 }
178 } 177 }
179 178
180 // ES6, draft 05-22-14, section 22.1.2.3 179 // ES6, draft 05-22-14, section 22.1.2.3
181 function ArrayOf() { 180 function ArrayOf() {
182 var length = %_ArgumentsLength(); 181 var length = %_ArgumentsLength();
183 var constructor = this; 182 var constructor = this;
184 // TODO: Implement IsConstructor (ES6 section 7.2.5) 183 // TODO: Implement IsConstructor (ES6 section 7.2.5)
185 var array = IS_SPEC_FUNCTION(constructor) ? new constructor(length) : []; 184 var array = %IsConstructor(constructor) ? new constructor(length) : [];
186 for (var i = 0; i < length; i++) { 185 for (var i = 0; i < length; i++) {
187 %AddElement(array, i, %_Arguments(i), NONE); 186 %AddElement(array, i, %_Arguments(i), NONE);
188 } 187 }
189 array.length = length; 188 array.length = length;
190 return array; 189 return array;
191 } 190 }
192 191
193 // ------------------------------------------------------------------- 192 // -------------------------------------------------------------------
194 193
195 function HarmonyArrayExtendSymbolPrototype() { 194 function HarmonyArrayExtendSymbolPrototype() {
(...skipping 20 matching lines...) Expand all
216 215
217 // Set up the non-enumerable functions on the Array prototype object. 216 // Set up the non-enumerable functions on the Array prototype object.
218 InstallFunctions($Array.prototype, DONT_ENUM, $Array( 217 InstallFunctions($Array.prototype, DONT_ENUM, $Array(
219 "find", ArrayFind, 218 "find", ArrayFind,
220 "findIndex", ArrayFindIndex, 219 "findIndex", ArrayFindIndex,
221 "fill", ArrayFill 220 "fill", ArrayFill
222 )); 221 ));
223 } 222 }
224 223
225 HarmonyArrayExtendArrayPrototype(); 224 HarmonyArrayExtendArrayPrototype();
OLDNEW
« no previous file with comments | « no previous file | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698