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

Side by Side Diff: src/runtime/runtime-array.cc

Issue 1160983004: [turbofan] First step towards sanitizing for-in and making it optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add some comments. Created 5 years, 6 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/runtime/runtime.h ('k') | src/runtime/runtime-forin.cc » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/messages.h" 8 #include "src/messages.h"
9 #include "src/runtime/runtime-utils.h" 9 #include "src/runtime/runtime-utils.h"
10 10
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 if (!current->HasDictionaryElements()) continue; 1295 if (!current->HasDictionaryElements()) continue;
1296 if (current->element_dictionary() 1296 if (current->element_dictionary()
1297 ->HasComplexElements<DictionaryEntryType::kObjects>()) { 1297 ->HasComplexElements<DictionaryEntryType::kObjects>()) {
1298 return isolate->heap()->true_value(); 1298 return isolate->heap()->true_value();
1299 } 1299 }
1300 } 1300 }
1301 return isolate->heap()->false_value(); 1301 return isolate->heap()->false_value();
1302 } 1302 }
1303 1303
1304 1304
1305 // TODO(dcarney): remove this function when TurboFan supports it.
1306 // Takes the object to be iterated over and the result of GetPropertyNamesFast
1307 // Returns pair (cache_array, cache_type).
1308 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ForInInit) {
1309 SealHandleScope scope(isolate);
1310 DCHECK(args.length() == 2);
1311 // This simulates CONVERT_ARG_HANDLE_CHECKED for calls returning pairs.
1312 // Not worth creating a macro atm as this function should be removed.
1313 if (!args[0]->IsJSReceiver() || !args[1]->IsObject()) {
1314 Object* error = isolate->ThrowIllegalOperation();
1315 return MakePair(error, isolate->heap()->undefined_value());
1316 }
1317 Handle<JSReceiver> object = args.at<JSReceiver>(0);
1318 Handle<Object> cache_type = args.at<Object>(1);
1319 if (cache_type->IsMap()) {
1320 // Enum cache case.
1321 return MakePair(Map::cast(*cache_type)->EnumLength() != 0
1322 ? object->map()->instance_descriptors()->GetEnumCache()
1323 : isolate->heap()->empty_fixed_array(),
1324 *cache_type);
1325 } else {
1326 // FixedArray case.
1327 Smi* new_cache_type = Smi::FromInt(object->IsJSProxy() ? 0 : 1);
1328 return MakePair(*Handle<FixedArray>::cast(cache_type), new_cache_type);
1329 }
1330 }
1331
1332
1333 // TODO(dcarney): remove this function when TurboFan supports it.
1334 RUNTIME_FUNCTION(Runtime_ForInCacheArrayLength) {
1335 SealHandleScope shs(isolate);
1336 DCHECK(args.length() == 2);
1337 CONVERT_ARG_HANDLE_CHECKED(Object, cache_type, 0);
1338 CONVERT_ARG_HANDLE_CHECKED(FixedArray, array, 1);
1339 int length = 0;
1340 if (cache_type->IsMap()) {
1341 length = Map::cast(*cache_type)->EnumLength();
1342 } else {
1343 DCHECK(cache_type->IsSmi());
1344 length = array->length();
1345 }
1346 return Smi::FromInt(length);
1347 }
1348
1349
1350 // TODO(dcarney): remove this function when TurboFan supports it.
1351 // Takes (the object to be iterated over,
1352 // cache_array from ForInInit,
1353 // cache_type from ForInInit,
1354 // the current index)
1355 // Returns pair (array[index], needs_filtering).
1356 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ForInNext) {
1357 SealHandleScope scope(isolate);
1358 DCHECK(args.length() == 4);
1359 int32_t index;
1360 // This simulates CONVERT_ARG_HANDLE_CHECKED for calls returning pairs.
1361 // Not worth creating a macro atm as this function should be removed.
1362 if (!args[0]->IsJSReceiver() || !args[1]->IsFixedArray() ||
1363 !args[2]->IsObject() || !args[3]->ToInt32(&index)) {
1364 Object* error = isolate->ThrowIllegalOperation();
1365 return MakePair(error, isolate->heap()->undefined_value());
1366 }
1367 Handle<JSReceiver> object = args.at<JSReceiver>(0);
1368 Handle<FixedArray> array = args.at<FixedArray>(1);
1369 Handle<Object> cache_type = args.at<Object>(2);
1370 // Figure out first if a slow check is needed for this object.
1371 bool slow_check_needed = false;
1372 if (cache_type->IsMap()) {
1373 if (object->map() != Map::cast(*cache_type)) {
1374 // Object transitioned. Need slow check.
1375 slow_check_needed = true;
1376 }
1377 } else {
1378 // No slow check needed for proxies.
1379 slow_check_needed = Smi::cast(*cache_type)->value() == 1;
1380 }
1381 return MakePair(array->get(index),
1382 isolate->heap()->ToBoolean(slow_check_needed));
1383 }
1384
1385
1386 RUNTIME_FUNCTION(Runtime_IsArray) { 1305 RUNTIME_FUNCTION(Runtime_IsArray) {
1387 SealHandleScope shs(isolate); 1306 SealHandleScope shs(isolate);
1388 DCHECK(args.length() == 1); 1307 DCHECK(args.length() == 1);
1389 CONVERT_ARG_CHECKED(Object, obj, 0); 1308 CONVERT_ARG_CHECKED(Object, obj, 0);
1390 return isolate->heap()->ToBoolean(obj->IsJSArray()); 1309 return isolate->heap()->ToBoolean(obj->IsJSArray());
1391 } 1310 }
1392 1311
1393 1312
1394 RUNTIME_FUNCTION(Runtime_HasCachedArrayIndex) { 1313 RUNTIME_FUNCTION(Runtime_HasCachedArrayIndex) {
1395 SealHandleScope shs(isolate); 1314 SealHandleScope shs(isolate);
(...skipping 12 matching lines...) Expand all
1408 1327
1409 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { 1328 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) {
1410 SealHandleScope shs(isolate); 1329 SealHandleScope shs(isolate);
1411 DCHECK(args.length() == 2); 1330 DCHECK(args.length() == 2);
1412 // Returning undefined means that this fast path fails and one has to resort 1331 // Returning undefined means that this fast path fails and one has to resort
1413 // to a slow path. 1332 // to a slow path.
1414 return isolate->heap()->undefined_value(); 1333 return isolate->heap()->undefined_value();
1415 } 1334 }
1416 } // namespace internal 1335 } // namespace internal
1417 } // namespace v8 1336 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-forin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698