OLD | NEW |
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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/debug/debug-evaluate.h" | 9 #include "src/debug/debug-evaluate.h" |
10 #include "src/debug/debug-frames.h" | 10 #include "src/debug/debug-frames.h" |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 } | 1343 } |
1344 | 1344 |
1345 // Return result as a JS array. | 1345 // Return result as a JS array. |
1346 Handle<JSObject> result = | 1346 Handle<JSObject> result = |
1347 isolate->factory()->NewJSObject(isolate->array_function()); | 1347 isolate->factory()->NewJSObject(isolate->array_function()); |
1348 JSArray::SetContent(Handle<JSArray>::cast(result), instances); | 1348 JSArray::SetContent(Handle<JSArray>::cast(result), instances); |
1349 return *result; | 1349 return *result; |
1350 } | 1350 } |
1351 | 1351 |
1352 | 1352 |
| 1353 static bool HasInPrototypeChainIgnoringProxies(Isolate* isolate, Object* object, |
| 1354 Object* proto) { |
| 1355 PrototypeIterator iter(isolate, object, PrototypeIterator::START_AT_RECEIVER); |
| 1356 while (true) { |
| 1357 iter.AdvanceIgnoringProxies(); |
| 1358 if (iter.IsAtEnd()) return false; |
| 1359 if (iter.IsAtEnd(proto)) return true; |
| 1360 } |
| 1361 } |
| 1362 |
| 1363 |
1353 // Scan the heap for objects with direct references to an object | 1364 // Scan the heap for objects with direct references to an object |
1354 // args[0]: the object to find references to | 1365 // args[0]: the object to find references to |
1355 // args[1]: constructor function for instances to exclude (Mirror) | 1366 // args[1]: constructor function for instances to exclude (Mirror) |
1356 // args[2]: the the maximum number of objects to return | 1367 // args[2]: the the maximum number of objects to return |
1357 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { | 1368 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { |
1358 HandleScope scope(isolate); | 1369 HandleScope scope(isolate); |
1359 DCHECK(args.length() == 3); | 1370 DCHECK(args.length() == 3); |
1360 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); | 1371 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); |
1361 CONVERT_ARG_HANDLE_CHECKED(Object, filter, 1); | 1372 CONVERT_ARG_HANDLE_CHECKED(Object, filter, 1); |
1362 RUNTIME_ASSERT(filter->IsUndefined() || filter->IsJSObject()); | 1373 RUNTIME_ASSERT(filter->IsUndefined() || filter->IsJSObject()); |
1363 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 1374 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
1364 RUNTIME_ASSERT(max_references >= 0); | 1375 RUNTIME_ASSERT(max_references >= 0); |
1365 | 1376 |
1366 List<Handle<JSObject> > instances; | 1377 List<Handle<JSObject> > instances; |
1367 Heap* heap = isolate->heap(); | 1378 Heap* heap = isolate->heap(); |
1368 { | 1379 { |
1369 HeapIterator iterator(heap, HeapIterator::kFilterUnreachable); | 1380 HeapIterator iterator(heap, HeapIterator::kFilterUnreachable); |
1370 // Get the constructor function for context extension and arguments array. | 1381 // Get the constructor function for context extension and arguments array. |
1371 Object* arguments_fun = isolate->sloppy_arguments_map()->GetConstructor(); | 1382 Object* arguments_fun = isolate->sloppy_arguments_map()->GetConstructor(); |
1372 HeapObject* heap_obj; | 1383 HeapObject* heap_obj; |
1373 while ((heap_obj = iterator.next())) { | 1384 while ((heap_obj = iterator.next())) { |
1374 if (!heap_obj->IsJSObject()) continue; | 1385 if (!heap_obj->IsJSObject()) continue; |
1375 JSObject* obj = JSObject::cast(heap_obj); | 1386 JSObject* obj = JSObject::cast(heap_obj); |
1376 if (obj->IsJSContextExtensionObject()) continue; | 1387 if (obj->IsJSContextExtensionObject()) continue; |
1377 if (obj->map()->GetConstructor() == arguments_fun) continue; | 1388 if (obj->map()->GetConstructor() == arguments_fun) continue; |
1378 if (!obj->ReferencesObject(*target)) continue; | 1389 if (!obj->ReferencesObject(*target)) continue; |
1379 // Check filter if supplied. This is normally used to avoid | 1390 // Check filter if supplied. This is normally used to avoid |
1380 // references from mirror objects. | 1391 // references from mirror objects. |
1381 if (!filter->IsUndefined() && | 1392 if (!filter->IsUndefined() && |
1382 obj->HasInPrototypeChain(isolate, *filter)) { | 1393 HasInPrototypeChainIgnoringProxies(isolate, obj, *filter)) { |
1383 continue; | 1394 continue; |
1384 } | 1395 } |
1385 if (obj->IsJSGlobalObject()) { | 1396 if (obj->IsJSGlobalObject()) { |
1386 obj = JSGlobalObject::cast(obj)->global_proxy(); | 1397 obj = JSGlobalObject::cast(obj)->global_proxy(); |
1387 } | 1398 } |
1388 instances.Add(Handle<JSObject>(obj)); | 1399 instances.Add(Handle<JSObject>(obj)); |
1389 if (instances.length() == max_references) break; | 1400 if (instances.length() == max_references) break; |
1390 } | 1401 } |
1391 // Iterate the rest of the heap to satisfy HeapIterator constraints. | 1402 // Iterate the rest of the heap to satisfy HeapIterator constraints. |
1392 while (iterator.next()) { | 1403 while (iterator.next()) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 return Smi::FromInt(isolate->debug()->is_active()); | 1701 return Smi::FromInt(isolate->debug()->is_active()); |
1691 } | 1702 } |
1692 | 1703 |
1693 | 1704 |
1694 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1705 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1695 UNIMPLEMENTED(); | 1706 UNIMPLEMENTED(); |
1696 return NULL; | 1707 return NULL; |
1697 } | 1708 } |
1698 } // namespace internal | 1709 } // namespace internal |
1699 } // namespace v8 | 1710 } // namespace v8 |
OLD | NEW |