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

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

Issue 1266013006: [stubs] Unify (and optimize) implementation of ToObject. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add missing support for %_ToObject in TurboFan and Crankshaft. Created 5 years, 4 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/full-codegen/x87/full-codegen-x87.cc ('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(global, utils) { 5 (function(global, utils) {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 count--; 76 count--;
77 } 77 }
78 78
79 return array; 79 return array;
80 } 80 }
81 81
82 // ES6 draft 03-17-15, section 22.1.3.3 82 // ES6 draft 03-17-15, section 22.1.3.3
83 function ArrayCopyWithin(target, start, end) { 83 function ArrayCopyWithin(target, start, end) {
84 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); 84 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin");
85 85
86 var array = TO_OBJECT_INLINE(this); 86 var array = TO_OBJECT(this);
87 var length = $toLength(array.length); 87 var length = $toLength(array.length);
88 88
89 return InnerArrayCopyWithin(target, start, end, array, length); 89 return InnerArrayCopyWithin(target, start, end, array, length);
90 } 90 }
91 91
92 function InnerArrayFind(predicate, thisArg, array, length) { 92 function InnerArrayFind(predicate, thisArg, array, length) {
93 if (!IS_SPEC_FUNCTION(predicate)) { 93 if (!IS_SPEC_FUNCTION(predicate)) {
94 throw MakeTypeError(kCalledNonCallable, predicate); 94 throw MakeTypeError(kCalledNonCallable, predicate);
95 } 95 }
96 96
97 var needs_wrapper = false; 97 var needs_wrapper = false;
98 if (IS_NULL(thisArg)) { 98 if (IS_NULL(thisArg)) {
99 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; 99 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
100 } else if (!IS_UNDEFINED(thisArg)) { 100 } else if (!IS_UNDEFINED(thisArg)) {
101 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); 101 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
102 } 102 }
103 103
104 for (var i = 0; i < length; i++) { 104 for (var i = 0; i < length; i++) {
105 var element = array[i]; 105 var element = array[i];
106 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; 106 var newThisArg = needs_wrapper ? TO_OBJECT(thisArg) : thisArg;
107 if (%_CallFunction(newThisArg, element, i, array, predicate)) { 107 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
108 return element; 108 return element;
109 } 109 }
110 } 110 }
111 111
112 return; 112 return;
113 } 113 }
114 114
115 // ES6 draft 07-15-13, section 15.4.3.23 115 // ES6 draft 07-15-13, section 15.4.3.23
116 function ArrayFind(predicate, thisArg) { 116 function ArrayFind(predicate, thisArg) {
117 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); 117 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
118 118
119 var array = $toObject(this); 119 var array = TO_OBJECT(this);
120 var length = $toInteger(array.length); 120 var length = $toInteger(array.length);
121 121
122 return InnerArrayFind(predicate, thisArg, array, length); 122 return InnerArrayFind(predicate, thisArg, array, length);
123 } 123 }
124 124
125 function InnerArrayFindIndex(predicate, thisArg, array, length) { 125 function InnerArrayFindIndex(predicate, thisArg, array, length) {
126 if (!IS_SPEC_FUNCTION(predicate)) { 126 if (!IS_SPEC_FUNCTION(predicate)) {
127 throw MakeTypeError(kCalledNonCallable, predicate); 127 throw MakeTypeError(kCalledNonCallable, predicate);
128 } 128 }
129 129
130 var needs_wrapper = false; 130 var needs_wrapper = false;
131 if (IS_NULL(thisArg)) { 131 if (IS_NULL(thisArg)) {
132 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; 132 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
133 } else if (!IS_UNDEFINED(thisArg)) { 133 } else if (!IS_UNDEFINED(thisArg)) {
134 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); 134 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
135 } 135 }
136 136
137 for (var i = 0; i < length; i++) { 137 for (var i = 0; i < length; i++) {
138 var element = array[i]; 138 var element = array[i];
139 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; 139 var newThisArg = needs_wrapper ? TO_OBJECT(thisArg) : thisArg;
140 if (%_CallFunction(newThisArg, element, i, array, predicate)) { 140 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
141 return i; 141 return i;
142 } 142 }
143 } 143 }
144 144
145 return -1; 145 return -1;
146 } 146 }
147 147
148 // ES6 draft 07-15-13, section 15.4.3.24 148 // ES6 draft 07-15-13, section 15.4.3.24
149 function ArrayFindIndex(predicate, thisArg) { 149 function ArrayFindIndex(predicate, thisArg) {
150 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); 150 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
151 151
152 var array = $toObject(this); 152 var array = TO_OBJECT(this);
153 var length = $toInteger(array.length); 153 var length = $toInteger(array.length);
154 154
155 return InnerArrayFindIndex(predicate, thisArg, array, length); 155 return InnerArrayFindIndex(predicate, thisArg, array, length);
156 } 156 }
157 157
158 // ES6, draft 04-05-14, section 22.1.3.6 158 // ES6, draft 04-05-14, section 22.1.3.6
159 function InnerArrayFill(value, start, end, array, length) { 159 function InnerArrayFill(value, start, end, array, length) {
160 var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start); 160 var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start);
161 var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); 161 var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
162 162
(...skipping 17 matching lines...) Expand all
180 180
181 for (; i < end; i++) 181 for (; i < end; i++)
182 array[i] = value; 182 array[i] = value;
183 return array; 183 return array;
184 } 184 }
185 185
186 // ES6, draft 04-05-14, section 22.1.3.6 186 // ES6, draft 04-05-14, section 22.1.3.6
187 function ArrayFill(value, start, end) { 187 function ArrayFill(value, start, end) {
188 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); 188 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
189 189
190 var array = $toObject(this); 190 var array = TO_OBJECT(this);
191 var length = TO_UINT32(array.length); 191 var length = TO_UINT32(array.length);
192 192
193 return InnerArrayFill(value, start, end, array, length); 193 return InnerArrayFill(value, start, end, array, length);
194 } 194 }
195 195
196 function AddArrayElement(constructor, array, i, value) { 196 function AddArrayElement(constructor, array, i, value) {
197 if (constructor === GlobalArray) { 197 if (constructor === GlobalArray) {
198 %AddElement(array, i, value); 198 %AddElement(array, i, value);
199 } else { 199 } else {
200 ObjectDefineProperty(array, i, { 200 ObjectDefineProperty(array, i, {
201 value: value, writable: true, configurable: true, enumerable: true 201 value: value, writable: true, configurable: true, enumerable: true
202 }); 202 });
203 } 203 }
204 } 204 }
205 205
206 // ES6, draft 10-14-14, section 22.1.2.1 206 // ES6, draft 10-14-14, section 22.1.2.1
207 function ArrayFrom(arrayLike, mapfn, receiver) { 207 function ArrayFrom(arrayLike, mapfn, receiver) {
208 var items = $toObject(arrayLike); 208 var items = TO_OBJECT(arrayLike);
209 var mapping = !IS_UNDEFINED(mapfn); 209 var mapping = !IS_UNDEFINED(mapfn);
210 210
211 if (mapping) { 211 if (mapping) {
212 if (!IS_SPEC_FUNCTION(mapfn)) { 212 if (!IS_SPEC_FUNCTION(mapfn)) {
213 throw MakeTypeError(kCalledNonCallable, mapfn); 213 throw MakeTypeError(kCalledNonCallable, mapfn);
214 } else if (%IsSloppyModeFunction(mapfn)) { 214 } else if (%IsSloppyModeFunction(mapfn)) {
215 if (IS_NULL(receiver)) { 215 if (IS_NULL(receiver)) {
216 receiver = UNDEFINED; 216 receiver = UNDEFINED;
217 } else if (!IS_UNDEFINED(receiver)) { 217 } else if (!IS_UNDEFINED(receiver)) {
218 receiver = TO_OBJECT_INLINE(receiver); 218 receiver = TO_OBJECT(receiver);
219 } 219 }
220 } 220 }
221 } 221 }
222 222
223 var iterable = GetMethod(items, symbolIterator); 223 var iterable = GetMethod(items, symbolIterator);
224 var k; 224 var k;
225 var result; 225 var result;
226 var mappedValue; 226 var mappedValue;
227 var nextValue; 227 var nextValue;
228 228
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 utils.Export(function(to) { 313 utils.Export(function(to) {
314 to.ArrayFrom = ArrayFrom; 314 to.ArrayFrom = ArrayFrom;
315 to.InnerArrayCopyWithin = InnerArrayCopyWithin; 315 to.InnerArrayCopyWithin = InnerArrayCopyWithin;
316 to.InnerArrayFill = InnerArrayFill; 316 to.InnerArrayFill = InnerArrayFill;
317 to.InnerArrayFind = InnerArrayFind; 317 to.InnerArrayFind = InnerArrayFind;
318 to.InnerArrayFindIndex = InnerArrayFindIndex; 318 to.InnerArrayFindIndex = InnerArrayFindIndex;
319 }); 319 });
320 320
321 }) 321 })
OLDNEW
« no previous file with comments | « src/full-codegen/x87/full-codegen-x87.cc ('k') | src/harmony-array-includes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698