| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests for heap profiler | 3 // Tests for heap profiler |
| 4 | 4 |
| 5 #include <ctype.h> | 5 #include <ctype.h> |
| 6 | 6 |
| 7 #include "v8.h" | 7 #include "v8.h" |
| 8 | 8 |
| 9 #include "cctest.h" | 9 #include "cctest.h" |
| 10 #include "hashmap.h" | 10 #include "hashmap.h" |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 NULL, | 1247 NULL, |
| 1248 &name_resolver); | 1248 &name_resolver); |
| 1249 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1249 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1250 CHECK_NE(NULL, global); | 1250 CHECK_NE(NULL, global); |
| 1251 CHECK_EQ("Object / Global object name" , | 1251 CHECK_EQ("Object / Global object name" , |
| 1252 const_cast<i::HeapEntry*>( | 1252 const_cast<i::HeapEntry*>( |
| 1253 reinterpret_cast<const i::HeapEntry*>(global))->name()); | 1253 reinterpret_cast<const i::HeapEntry*>(global))->name()); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 | 1256 |
| 1257 TEST(DocumentURL) { | |
| 1258 v8::HandleScope scope; | |
| 1259 LocalContext env; | |
| 1260 | |
| 1261 CompileRun("document = { URL:\"abcdefgh\" };"); | |
| 1262 | |
| 1263 const v8::HeapSnapshot* snapshot = | |
| 1264 v8::HeapProfiler::TakeSnapshot(v8_str("document")); | |
| 1265 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | |
| 1266 CHECK_NE(NULL, global); | |
| 1267 CHECK_EQ("Object / abcdefgh", | |
| 1268 const_cast<i::HeapEntry*>( | |
| 1269 reinterpret_cast<const i::HeapEntry*>(global))->name()); | |
| 1270 } | |
| 1271 | |
| 1272 | |
| 1273 TEST(DocumentWithException) { | |
| 1274 v8::HandleScope scope; | |
| 1275 LocalContext env; | |
| 1276 | |
| 1277 CompileRun( | |
| 1278 "this.__defineGetter__(\"document\", function() { throw new Error(); })"); | |
| 1279 const v8::HeapSnapshot* snapshot = | |
| 1280 v8::HeapProfiler::TakeSnapshot(v8_str("document")); | |
| 1281 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | |
| 1282 CHECK_NE(NULL, global); | |
| 1283 CHECK_EQ("Object", | |
| 1284 const_cast<i::HeapEntry*>( | |
| 1285 reinterpret_cast<const i::HeapEntry*>(global))->name()); | |
| 1286 } | |
| 1287 | |
| 1288 | |
| 1289 TEST(DocumentURLWithException) { | |
| 1290 v8::HandleScope scope; | |
| 1291 LocalContext env; | |
| 1292 | |
| 1293 CompileRun( | |
| 1294 "function URLWithException() {}\n" | |
| 1295 "URLWithException.prototype = { get URL() { throw new Error(); } };\n" | |
| 1296 "document = { URL: new URLWithException() };"); | |
| 1297 const v8::HeapSnapshot* snapshot = | |
| 1298 v8::HeapProfiler::TakeSnapshot(v8_str("document")); | |
| 1299 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | |
| 1300 CHECK_NE(NULL, global); | |
| 1301 CHECK_EQ("Object", | |
| 1302 const_cast<i::HeapEntry*>( | |
| 1303 reinterpret_cast<const i::HeapEntry*>(global))->name()); | |
| 1304 } | |
| 1305 | |
| 1306 | |
| 1307 TEST(NoHandleLeaks) { | 1257 TEST(NoHandleLeaks) { |
| 1308 v8::HandleScope scope; | 1258 v8::HandleScope scope; |
| 1309 LocalContext env; | 1259 LocalContext env; |
| 1310 | 1260 |
| 1311 CompileRun("document = { URL:\"abcdefgh\" };"); | 1261 CompileRun("document = { URL:\"abcdefgh\" };"); |
| 1312 | 1262 |
| 1313 v8::Handle<v8::String> name(v8_str("leakz")); | 1263 v8::Handle<v8::String> name(v8_str("leakz")); |
| 1314 int count_before = i::HandleScope::NumberOfHandles(); | 1264 int count_before = i::HandleScope::NumberOfHandles(); |
| 1315 v8::HeapProfiler::TakeSnapshot(name); | 1265 v8::HeapProfiler::TakeSnapshot(name); |
| 1316 int count_after = i::HandleScope::NumberOfHandles(); | 1266 int count_after = i::HandleScope::NumberOfHandles(); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1700 const v8::HeapGraphNode* map = | 1650 const v8::HeapGraphNode* map = |
| 1701 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); | 1651 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); |
| 1702 CHECK_NE(NULL, map); | 1652 CHECK_NE(NULL, map); |
| 1703 const v8::HeapGraphNode* own_descriptors = GetProperty( | 1653 const v8::HeapGraphNode* own_descriptors = GetProperty( |
| 1704 map, v8::HeapGraphEdge::kInternal, "descriptors"); | 1654 map, v8::HeapGraphEdge::kInternal, "descriptors"); |
| 1705 CHECK_NE(NULL, own_descriptors); | 1655 CHECK_NE(NULL, own_descriptors); |
| 1706 const v8::HeapGraphNode* own_transitions = GetProperty( | 1656 const v8::HeapGraphNode* own_transitions = GetProperty( |
| 1707 map, v8::HeapGraphEdge::kInternal, "transitions"); | 1657 map, v8::HeapGraphEdge::kInternal, "transitions"); |
| 1708 CHECK_EQ(NULL, own_transitions); | 1658 CHECK_EQ(NULL, own_transitions); |
| 1709 } | 1659 } |
| OLD | NEW |