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

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

Issue 364853009: Implement ES6 Array.of() (Closed) Base URL: https://github.com/v8/v8@master
Patch Set: Added comment 'TODO: Implement IsConstructor' Created 6 years, 5 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 '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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 if ((end - i) > 0 && ObjectIsFrozen(array)) { 116 if ((end - i) > 0 && ObjectIsFrozen(array)) {
117 throw MakeTypeError("array_functions_on_frozen", 117 throw MakeTypeError("array_functions_on_frozen",
118 ["Array.prototype.fill"]); 118 ["Array.prototype.fill"]);
119 } 119 }
120 120
121 for (; i < end; i++) 121 for (; i < end; i++)
122 array[i] = value; 122 array[i] = value;
123 return array; 123 return array;
124 } 124 }
125 125
126 // ES6, draft 05-22-14, section 22.1.2.3
127 function ArrayOf() {
128 var len = %_ArgumentsLength();
129 var C = this;
130 // TODO: Implement IsConstructor (ES6 section 7.2.5)
131 if (IS_SPEC_FUNCTION(C)) {
132 var A = new C(len);
rossberg 2014/07/21 16:07:07 Please don't make use of var scoping like that. Pr
133 } else {
134 var A = [];
135 }
136 for (var k = 0; k < len; k++) {
137 %AddProperty(A, k, %_Arguments(k));
rossberg 2014/07/21 16:07:07 Unfortunately, this runtime function has recently
138 }
139 A.length = len;
140 return A;
141 }
142
126 // ------------------------------------------------------------------- 143 // -------------------------------------------------------------------
127 144
128 function HarmonyArrayExtendArrayPrototype() { 145 function HarmonyArrayExtendArrayPrototype() {
129 %CheckIsBootstrapping(); 146 %CheckIsBootstrapping();
130 147
148 // Set up non-enumerable functions on the Array object.
149 InstallFunctions($Array, DONT_ENUM, $Array(
150 "of", ArrayOf
151 ));
152
131 // Set up the non-enumerable functions on the Array prototype object. 153 // Set up the non-enumerable functions on the Array prototype object.
132 InstallFunctions($Array.prototype, DONT_ENUM, $Array( 154 InstallFunctions($Array.prototype, DONT_ENUM, $Array(
133 "find", ArrayFind, 155 "find", ArrayFind,
134 "findIndex", ArrayFindIndex, 156 "findIndex", ArrayFindIndex,
135 "fill", ArrayFill 157 "fill", ArrayFill
136 )); 158 ));
137 } 159 }
138 160
139 HarmonyArrayExtendArrayPrototype(); 161 HarmonyArrayExtendArrayPrototype();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/array-of-1.js » ('j') | test/mjsunit/es6/array-of-length-setter-2.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698