| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 LocalContext env; | 455 LocalContext env; |
| 456 TestResource* resource = new TestResource(two_byte_source); | 456 TestResource* resource = new TestResource(two_byte_source); |
| 457 Local<String> source = String::NewExternal(resource); | 457 Local<String> source = String::NewExternal(resource); |
| 458 Local<Script> script = Script::Compile(source); | 458 Local<Script> script = Script::Compile(source); |
| 459 Local<Value> value = script->Run(); | 459 Local<Value> value = script->Run(); |
| 460 CHECK(value->IsNumber()); | 460 CHECK(value->IsNumber()); |
| 461 CHECK_EQ(7, value->Int32Value()); | 461 CHECK_EQ(7, value->Int32Value()); |
| 462 CHECK(source->IsExternal()); | 462 CHECK(source->IsExternal()); |
| 463 CHECK_EQ(resource, | 463 CHECK_EQ(resource, |
| 464 static_cast<TestResource*>(source->GetExternalStringResource())); | 464 static_cast<TestResource*>(source->GetExternalStringResource())); |
| 465 v8::internal::Heap::CollectAllGarbage(); | 465 v8::internal::Heap::CollectAllGarbage(false); |
| 466 CHECK_EQ(0, TestResource::dispose_count); | 466 CHECK_EQ(0, TestResource::dispose_count); |
| 467 } | 467 } |
| 468 v8::internal::CompilationCache::Clear(); | 468 v8::internal::CompilationCache::Clear(); |
| 469 v8::internal::Heap::CollectAllGarbage(); | 469 v8::internal::Heap::CollectAllGarbage(false); |
| 470 CHECK_EQ(1, TestResource::dispose_count); | 470 CHECK_EQ(1, TestResource::dispose_count); |
| 471 } | 471 } |
| 472 | 472 |
| 473 | 473 |
| 474 THREADED_TEST(ScriptUsingAsciiStringResource) { | 474 THREADED_TEST(ScriptUsingAsciiStringResource) { |
| 475 TestAsciiResource::dispose_count = 0; | 475 TestAsciiResource::dispose_count = 0; |
| 476 const char* c_source = "1 + 2 * 3"; | 476 const char* c_source = "1 + 2 * 3"; |
| 477 { | 477 { |
| 478 v8::HandleScope scope; | 478 v8::HandleScope scope; |
| 479 LocalContext env; | 479 LocalContext env; |
| 480 Local<String> source = | 480 Local<String> source = |
| 481 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); | 481 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); |
| 482 Local<Script> script = Script::Compile(source); | 482 Local<Script> script = Script::Compile(source); |
| 483 Local<Value> value = script->Run(); | 483 Local<Value> value = script->Run(); |
| 484 CHECK(value->IsNumber()); | 484 CHECK(value->IsNumber()); |
| 485 CHECK_EQ(7, value->Int32Value()); | 485 CHECK_EQ(7, value->Int32Value()); |
| 486 v8::internal::Heap::CollectAllGarbage(); | 486 v8::internal::Heap::CollectAllGarbage(false); |
| 487 CHECK_EQ(0, TestAsciiResource::dispose_count); | 487 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 488 } | 488 } |
| 489 v8::internal::CompilationCache::Clear(); | 489 v8::internal::CompilationCache::Clear(); |
| 490 v8::internal::Heap::CollectAllGarbage(); | 490 v8::internal::Heap::CollectAllGarbage(false); |
| 491 CHECK_EQ(1, TestAsciiResource::dispose_count); | 491 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 492 } | 492 } |
| 493 | 493 |
| 494 | 494 |
| 495 THREADED_TEST(ScriptMakingExternalString) { | 495 THREADED_TEST(ScriptMakingExternalString) { |
| 496 TestResource::dispose_count = 0; | 496 TestResource::dispose_count = 0; |
| 497 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 497 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
| 498 { | 498 { |
| 499 v8::HandleScope scope; | 499 v8::HandleScope scope; |
| 500 LocalContext env; | 500 LocalContext env; |
| 501 Local<String> source = String::New(two_byte_source); | 501 Local<String> source = String::New(two_byte_source); |
| 502 bool success = source->MakeExternal(new TestResource(two_byte_source)); | 502 bool success = source->MakeExternal(new TestResource(two_byte_source)); |
| 503 CHECK(success); | 503 CHECK(success); |
| 504 Local<Script> script = Script::Compile(source); | 504 Local<Script> script = Script::Compile(source); |
| 505 Local<Value> value = script->Run(); | 505 Local<Value> value = script->Run(); |
| 506 CHECK(value->IsNumber()); | 506 CHECK(value->IsNumber()); |
| 507 CHECK_EQ(7, value->Int32Value()); | 507 CHECK_EQ(7, value->Int32Value()); |
| 508 v8::internal::Heap::CollectAllGarbage(); | 508 v8::internal::Heap::CollectAllGarbage(false); |
| 509 CHECK_EQ(0, TestResource::dispose_count); | 509 CHECK_EQ(0, TestResource::dispose_count); |
| 510 } | 510 } |
| 511 v8::internal::CompilationCache::Clear(); | 511 v8::internal::CompilationCache::Clear(); |
| 512 v8::internal::Heap::CollectAllGarbage(); | 512 v8::internal::Heap::CollectAllGarbage(false); |
| 513 CHECK_EQ(1, TestResource::dispose_count); | 513 CHECK_EQ(1, TestResource::dispose_count); |
| 514 } | 514 } |
| 515 | 515 |
| 516 | 516 |
| 517 THREADED_TEST(ScriptMakingExternalAsciiString) { | 517 THREADED_TEST(ScriptMakingExternalAsciiString) { |
| 518 TestAsciiResource::dispose_count = 0; | 518 TestAsciiResource::dispose_count = 0; |
| 519 const char* c_source = "1 + 2 * 3"; | 519 const char* c_source = "1 + 2 * 3"; |
| 520 { | 520 { |
| 521 v8::HandleScope scope; | 521 v8::HandleScope scope; |
| 522 LocalContext env; | 522 LocalContext env; |
| 523 Local<String> source = v8_str(c_source); | 523 Local<String> source = v8_str(c_source); |
| 524 bool success = source->MakeExternal( | 524 bool success = source->MakeExternal( |
| 525 new TestAsciiResource(i::StrDup(c_source))); | 525 new TestAsciiResource(i::StrDup(c_source))); |
| 526 CHECK(success); | 526 CHECK(success); |
| 527 Local<Script> script = Script::Compile(source); | 527 Local<Script> script = Script::Compile(source); |
| 528 Local<Value> value = script->Run(); | 528 Local<Value> value = script->Run(); |
| 529 CHECK(value->IsNumber()); | 529 CHECK(value->IsNumber()); |
| 530 CHECK_EQ(7, value->Int32Value()); | 530 CHECK_EQ(7, value->Int32Value()); |
| 531 v8::internal::Heap::CollectAllGarbage(); | 531 v8::internal::Heap::CollectAllGarbage(false); |
| 532 CHECK_EQ(0, TestAsciiResource::dispose_count); | 532 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 533 } | 533 } |
| 534 v8::internal::CompilationCache::Clear(); | 534 v8::internal::CompilationCache::Clear(); |
| 535 v8::internal::Heap::CollectAllGarbage(); | 535 v8::internal::Heap::CollectAllGarbage(false); |
| 536 CHECK_EQ(1, TestAsciiResource::dispose_count); | 536 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 537 } | 537 } |
| 538 | 538 |
| 539 | 539 |
| 540 THREADED_TEST(UsingExternalString) { | 540 THREADED_TEST(UsingExternalString) { |
| 541 { | 541 { |
| 542 v8::HandleScope scope; | 542 v8::HandleScope scope; |
| 543 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 543 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
| 544 Local<String> string = | 544 Local<String> string = |
| 545 String::NewExternal(new TestResource(two_byte_string)); | 545 String::NewExternal(new TestResource(two_byte_string)); |
| 546 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 546 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| 547 // Trigger GCs so that the newly allocated string moves to old gen. | 547 // Trigger GCs so that the newly allocated string moves to old gen. |
| 548 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | 548 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
| 549 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | 549 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
| 550 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); | 550 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); |
| 551 CHECK(isymbol->IsSymbol()); | 551 CHECK(isymbol->IsSymbol()); |
| 552 } | 552 } |
| 553 i::Heap::CollectAllGarbage(); | 553 i::Heap::CollectAllGarbage(false); |
| 554 i::Heap::CollectAllGarbage(); | 554 i::Heap::CollectAllGarbage(false); |
| 555 } | 555 } |
| 556 | 556 |
| 557 | 557 |
| 558 THREADED_TEST(UsingExternalAsciiString) { | 558 THREADED_TEST(UsingExternalAsciiString) { |
| 559 { | 559 { |
| 560 v8::HandleScope scope; | 560 v8::HandleScope scope; |
| 561 const char* one_byte_string = "test string"; | 561 const char* one_byte_string = "test string"; |
| 562 Local<String> string = String::NewExternal( | 562 Local<String> string = String::NewExternal( |
| 563 new TestAsciiResource(i::StrDup(one_byte_string))); | 563 new TestAsciiResource(i::StrDup(one_byte_string))); |
| 564 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 564 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| 565 // Trigger GCs so that the newly allocated string moves to old gen. | 565 // Trigger GCs so that the newly allocated string moves to old gen. |
| 566 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | 566 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
| 567 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | 567 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
| 568 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); | 568 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); |
| 569 CHECK(isymbol->IsSymbol()); | 569 CHECK(isymbol->IsSymbol()); |
| 570 } | 570 } |
| 571 i::Heap::CollectAllGarbage(); | 571 i::Heap::CollectAllGarbage(false); |
| 572 i::Heap::CollectAllGarbage(); | 572 i::Heap::CollectAllGarbage(false); |
| 573 } | 573 } |
| 574 | 574 |
| 575 | 575 |
| 576 THREADED_TEST(GlobalProperties) { | 576 THREADED_TEST(GlobalProperties) { |
| 577 v8::HandleScope scope; | 577 v8::HandleScope scope; |
| 578 LocalContext env; | 578 LocalContext env; |
| 579 v8::Handle<v8::Object> global = env->Global(); | 579 v8::Handle<v8::Object> global = env->Global(); |
| 580 global->Set(v8_str("pi"), v8_num(3.1415926)); | 580 global->Set(v8_str("pi"), v8_num(3.1415926)); |
| 581 Local<Value> pi = global->Get(v8_str("pi")); | 581 Local<Value> pi = global->Get(v8_str("pi")); |
| 582 CHECK_EQ(3.1415926, pi->NumberValue()); | 582 CHECK_EQ(3.1415926, pi->NumberValue()); |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 | 1326 |
| 1327 char* data = new char[100]; | 1327 char* data = new char[100]; |
| 1328 | 1328 |
| 1329 void* aligned = data; | 1329 void* aligned = data; |
| 1330 CHECK_EQ(0, reinterpret_cast<uintptr_t>(aligned) & 0x1); | 1330 CHECK_EQ(0, reinterpret_cast<uintptr_t>(aligned) & 0x1); |
| 1331 void* unaligned = data + 1; | 1331 void* unaligned = data + 1; |
| 1332 CHECK_EQ(1, reinterpret_cast<uintptr_t>(unaligned) & 0x1); | 1332 CHECK_EQ(1, reinterpret_cast<uintptr_t>(unaligned) & 0x1); |
| 1333 | 1333 |
| 1334 // Check reading and writing aligned pointers. | 1334 // Check reading and writing aligned pointers. |
| 1335 obj->SetPointerInInternalField(0, aligned); | 1335 obj->SetPointerInInternalField(0, aligned); |
| 1336 i::Heap::CollectAllGarbage(); | 1336 i::Heap::CollectAllGarbage(false); |
| 1337 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); | 1337 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); |
| 1338 | 1338 |
| 1339 // Check reading and writing unaligned pointers. | 1339 // Check reading and writing unaligned pointers. |
| 1340 obj->SetPointerInInternalField(0, unaligned); | 1340 obj->SetPointerInInternalField(0, unaligned); |
| 1341 i::Heap::CollectAllGarbage(); | 1341 i::Heap::CollectAllGarbage(false); |
| 1342 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); | 1342 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); |
| 1343 | 1343 |
| 1344 delete[] data; | 1344 delete[] data; |
| 1345 } | 1345 } |
| 1346 | 1346 |
| 1347 | 1347 |
| 1348 THREADED_TEST(IdentityHash) { | 1348 THREADED_TEST(IdentityHash) { |
| 1349 v8::HandleScope scope; | 1349 v8::HandleScope scope; |
| 1350 LocalContext env; | 1350 LocalContext env; |
| 1351 | 1351 |
| 1352 // Ensure that the test starts with an fresh heap to test whether the hash | 1352 // Ensure that the test starts with an fresh heap to test whether the hash |
| 1353 // code is based on the address. | 1353 // code is based on the address. |
| 1354 i::Heap::CollectAllGarbage(); | 1354 i::Heap::CollectAllGarbage(false); |
| 1355 Local<v8::Object> obj = v8::Object::New(); | 1355 Local<v8::Object> obj = v8::Object::New(); |
| 1356 int hash = obj->GetIdentityHash(); | 1356 int hash = obj->GetIdentityHash(); |
| 1357 int hash1 = obj->GetIdentityHash(); | 1357 int hash1 = obj->GetIdentityHash(); |
| 1358 CHECK_EQ(hash, hash1); | 1358 CHECK_EQ(hash, hash1); |
| 1359 int hash2 = v8::Object::New()->GetIdentityHash(); | 1359 int hash2 = v8::Object::New()->GetIdentityHash(); |
| 1360 // Since the identity hash is essentially a random number two consecutive | 1360 // Since the identity hash is essentially a random number two consecutive |
| 1361 // objects should not be assigned the same hash code. If the test below fails | 1361 // objects should not be assigned the same hash code. If the test below fails |
| 1362 // the random number generator should be evaluated. | 1362 // the random number generator should be evaluated. |
| 1363 CHECK_NE(hash, hash2); | 1363 CHECK_NE(hash, hash2); |
| 1364 i::Heap::CollectAllGarbage(); | 1364 i::Heap::CollectAllGarbage(false); |
| 1365 int hash3 = v8::Object::New()->GetIdentityHash(); | 1365 int hash3 = v8::Object::New()->GetIdentityHash(); |
| 1366 // Make sure that the identity hash is not based on the initial address of | 1366 // Make sure that the identity hash is not based on the initial address of |
| 1367 // the object alone. If the test below fails the random number generator | 1367 // the object alone. If the test below fails the random number generator |
| 1368 // should be evaluated. | 1368 // should be evaluated. |
| 1369 CHECK_NE(hash, hash3); | 1369 CHECK_NE(hash, hash3); |
| 1370 int hash4 = obj->GetIdentityHash(); | 1370 int hash4 = obj->GetIdentityHash(); |
| 1371 CHECK_EQ(hash, hash4); | 1371 CHECK_EQ(hash, hash4); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 | 1374 |
| 1375 THREADED_TEST(HiddenProperties) { | 1375 THREADED_TEST(HiddenProperties) { |
| 1376 v8::HandleScope scope; | 1376 v8::HandleScope scope; |
| 1377 LocalContext env; | 1377 LocalContext env; |
| 1378 | 1378 |
| 1379 v8::Local<v8::Object> obj = v8::Object::New(); | 1379 v8::Local<v8::Object> obj = v8::Object::New(); |
| 1380 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 1380 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| 1381 v8::Local<v8::String> empty = v8_str(""); | 1381 v8::Local<v8::String> empty = v8_str(""); |
| 1382 v8::Local<v8::String> prop_name = v8_str("prop_name"); | 1382 v8::Local<v8::String> prop_name = v8_str("prop_name"); |
| 1383 | 1383 |
| 1384 i::Heap::CollectAllGarbage(); | 1384 i::Heap::CollectAllGarbage(false); |
| 1385 | 1385 |
| 1386 // Make sure delete of a non-existent hidden value works | 1386 // Make sure delete of a non-existent hidden value works |
| 1387 CHECK(obj->DeleteHiddenValue(key)); | 1387 CHECK(obj->DeleteHiddenValue(key)); |
| 1388 | 1388 |
| 1389 CHECK(obj->SetHiddenValue(key, v8::Integer::New(1503))); | 1389 CHECK(obj->SetHiddenValue(key, v8::Integer::New(1503))); |
| 1390 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); | 1390 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); |
| 1391 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); | 1391 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); |
| 1392 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1392 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1393 | 1393 |
| 1394 i::Heap::CollectAllGarbage(); | 1394 i::Heap::CollectAllGarbage(false); |
| 1395 | 1395 |
| 1396 // Make sure we do not find the hidden property. | 1396 // Make sure we do not find the hidden property. |
| 1397 CHECK(!obj->Has(empty)); | 1397 CHECK(!obj->Has(empty)); |
| 1398 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1398 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1399 CHECK(obj->Get(empty)->IsUndefined()); | 1399 CHECK(obj->Get(empty)->IsUndefined()); |
| 1400 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1400 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1401 CHECK(obj->Set(empty, v8::Integer::New(2003))); | 1401 CHECK(obj->Set(empty, v8::Integer::New(2003))); |
| 1402 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1402 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1403 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); | 1403 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); |
| 1404 | 1404 |
| 1405 i::Heap::CollectAllGarbage(); | 1405 i::Heap::CollectAllGarbage(false); |
| 1406 | 1406 |
| 1407 // Add another property and delete it afterwards to force the object in | 1407 // Add another property and delete it afterwards to force the object in |
| 1408 // slow case. | 1408 // slow case. |
| 1409 CHECK(obj->Set(prop_name, v8::Integer::New(2008))); | 1409 CHECK(obj->Set(prop_name, v8::Integer::New(2008))); |
| 1410 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1410 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1411 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); | 1411 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); |
| 1412 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1412 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1413 CHECK(obj->Delete(prop_name)); | 1413 CHECK(obj->Delete(prop_name)); |
| 1414 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1414 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1415 | 1415 |
| 1416 i::Heap::CollectAllGarbage(); | 1416 i::Heap::CollectAllGarbage(false); |
| 1417 | 1417 |
| 1418 CHECK(obj->DeleteHiddenValue(key)); | 1418 CHECK(obj->DeleteHiddenValue(key)); |
| 1419 CHECK(obj->GetHiddenValue(key).IsEmpty()); | 1419 CHECK(obj->GetHiddenValue(key).IsEmpty()); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 | 1422 |
| 1423 static v8::Handle<Value> InterceptorForHiddenProperties( | 1423 static v8::Handle<Value> InterceptorForHiddenProperties( |
| 1424 Local<String> name, const AccessorInfo& info) { | 1424 Local<String> name, const AccessorInfo& info) { |
| 1425 // Make sure objects move. | 1425 // Make sure objects move. |
| 1426 bool saved_always_compact = i::FLAG_always_compact; | 1426 bool saved_always_compact = i::FLAG_always_compact; |
| 1427 if (!i::FLAG_never_compact) { | 1427 if (!i::FLAG_never_compact) { |
| 1428 i::FLAG_always_compact = true; | 1428 i::FLAG_always_compact = true; |
| 1429 } | 1429 } |
| 1430 // The whole goal of this interceptor is to cause a GC during local property | 1430 // The whole goal of this interceptor is to cause a GC during local property |
| 1431 // lookup. | 1431 // lookup. |
| 1432 i::Heap::CollectAllGarbage(); | 1432 i::Heap::CollectAllGarbage(false); |
| 1433 i::FLAG_always_compact = saved_always_compact; | 1433 i::FLAG_always_compact = saved_always_compact; |
| 1434 return v8::Handle<Value>(); | 1434 return v8::Handle<Value>(); |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 | 1437 |
| 1438 THREADED_TEST(HiddenPropertiesWithInterceptors) { | 1438 THREADED_TEST(HiddenPropertiesWithInterceptors) { |
| 1439 v8::HandleScope scope; | 1439 v8::HandleScope scope; |
| 1440 LocalContext context; | 1440 LocalContext context; |
| 1441 | 1441 |
| 1442 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 1442 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| (...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2975 | 2975 |
| 2976 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { | 2976 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { |
| 2977 ApiTestFuzzer::Fuzz(); | 2977 ApiTestFuzzer::Fuzz(); |
| 2978 CHECK_EQ(args_fun, args.Callee()); | 2978 CHECK_EQ(args_fun, args.Callee()); |
| 2979 CHECK_EQ(3, args.Length()); | 2979 CHECK_EQ(3, args.Length()); |
| 2980 CHECK_EQ(v8::Integer::New(1), args[0]); | 2980 CHECK_EQ(v8::Integer::New(1), args[0]); |
| 2981 CHECK_EQ(v8::Integer::New(2), args[1]); | 2981 CHECK_EQ(v8::Integer::New(2), args[1]); |
| 2982 CHECK_EQ(v8::Integer::New(3), args[2]); | 2982 CHECK_EQ(v8::Integer::New(3), args[2]); |
| 2983 CHECK_EQ(v8::Undefined(), args[3]); | 2983 CHECK_EQ(v8::Undefined(), args[3]); |
| 2984 v8::HandleScope scope; | 2984 v8::HandleScope scope; |
| 2985 i::Heap::CollectAllGarbage(); | 2985 i::Heap::CollectAllGarbage(false); |
| 2986 return v8::Undefined(); | 2986 return v8::Undefined(); |
| 2987 } | 2987 } |
| 2988 | 2988 |
| 2989 | 2989 |
| 2990 THREADED_TEST(Arguments) { | 2990 THREADED_TEST(Arguments) { |
| 2991 v8::HandleScope scope; | 2991 v8::HandleScope scope; |
| 2992 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 2992 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
| 2993 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); | 2993 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); |
| 2994 LocalContext context(NULL, global); | 2994 LocalContext context(NULL, global); |
| 2995 args_fun = v8::Handle<Function>::Cast(context->Global()->Get(v8_str("f"))); | 2995 args_fun = v8::Handle<Function>::Cast(context->Global()->Get(v8_str("f"))); |
| (...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4953 "var p = new constructor();" | 4953 "var p = new constructor();" |
| 4954 "p.hasOwnProperty('ostehaps');"); | 4954 "p.hasOwnProperty('ostehaps');"); |
| 4955 CHECK_EQ(false, value->BooleanValue()); | 4955 CHECK_EQ(false, value->BooleanValue()); |
| 4956 } | 4956 } |
| 4957 | 4957 |
| 4958 | 4958 |
| 4959 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC( | 4959 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC( |
| 4960 Local<String> name, | 4960 Local<String> name, |
| 4961 const AccessorInfo& info) { | 4961 const AccessorInfo& info) { |
| 4962 ApiTestFuzzer::Fuzz(); | 4962 ApiTestFuzzer::Fuzz(); |
| 4963 i::Heap::CollectAllGarbage(); | 4963 i::Heap::CollectAllGarbage(false); |
| 4964 return v8::Handle<Value>(); | 4964 return v8::Handle<Value>(); |
| 4965 } | 4965 } |
| 4966 | 4966 |
| 4967 | 4967 |
| 4968 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { | 4968 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { |
| 4969 v8::HandleScope scope; | 4969 v8::HandleScope scope; |
| 4970 LocalContext context; | 4970 LocalContext context; |
| 4971 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 4971 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 4972 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 4972 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
| 4973 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); | 4973 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); |
| (...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6158 } | 6158 } |
| 6159 | 6159 |
| 6160 | 6160 |
| 6161 static int GetSurvivingGlobalObjectsCount() { | 6161 static int GetSurvivingGlobalObjectsCount() { |
| 6162 int count = 0; | 6162 int count = 0; |
| 6163 // We need to collect all garbage twice to be sure that everything | 6163 // We need to collect all garbage twice to be sure that everything |
| 6164 // has been collected. This is because inline caches are cleared in | 6164 // has been collected. This is because inline caches are cleared in |
| 6165 // the first garbage collection but some of the maps have already | 6165 // the first garbage collection but some of the maps have already |
| 6166 // been marked at that point. Therefore some of the maps are not | 6166 // been marked at that point. Therefore some of the maps are not |
| 6167 // collected until the second garbage collection. | 6167 // collected until the second garbage collection. |
| 6168 v8::internal::Heap::CollectAllGarbage(); | 6168 v8::internal::Heap::CollectAllGarbage(false); |
| 6169 v8::internal::Heap::CollectAllGarbage(); | 6169 v8::internal::Heap::CollectAllGarbage(false); |
| 6170 v8::internal::HeapIterator it; | 6170 v8::internal::HeapIterator it; |
| 6171 while (it.has_next()) { | 6171 while (it.has_next()) { |
| 6172 v8::internal::HeapObject* object = it.next(); | 6172 v8::internal::HeapObject* object = it.next(); |
| 6173 if (object->IsJSGlobalObject()) { | 6173 if (object->IsJSGlobalObject()) { |
| 6174 count++; | 6174 count++; |
| 6175 } | 6175 } |
| 6176 } | 6176 } |
| 6177 #ifdef DEBUG | 6177 #ifdef DEBUG |
| 6178 if (count > 0) v8::internal::Heap::TracePathToGlobal(); | 6178 if (count > 0) v8::internal::Heap::TracePathToGlobal(); |
| 6179 #endif | 6179 #endif |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6235 some_object = v8::Persistent<v8::Object>::New(v8::Object::New()); | 6235 some_object = v8::Persistent<v8::Object>::New(v8::Object::New()); |
| 6236 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); | 6236 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); |
| 6237 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); | 6237 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); |
| 6238 } | 6238 } |
| 6239 // Note: order is implementation dependent alas: currently | 6239 // Note: order is implementation dependent alas: currently |
| 6240 // global handle nodes are processed by PostGarbageCollectionProcessing | 6240 // global handle nodes are processed by PostGarbageCollectionProcessing |
| 6241 // in reverse allocation order, so if second allocated handle is deleted, | 6241 // in reverse allocation order, so if second allocated handle is deleted, |
| 6242 // weak callback of the first handle would be able to 'reallocate' it. | 6242 // weak callback of the first handle would be able to 'reallocate' it. |
| 6243 handle1.MakeWeak(NULL, NewPersistentHandleCallback); | 6243 handle1.MakeWeak(NULL, NewPersistentHandleCallback); |
| 6244 handle2.Dispose(); | 6244 handle2.Dispose(); |
| 6245 i::Heap::CollectAllGarbage(); | 6245 i::Heap::CollectAllGarbage(false); |
| 6246 } | 6246 } |
| 6247 | 6247 |
| 6248 | 6248 |
| 6249 v8::Persistent<v8::Object> to_be_disposed; | 6249 v8::Persistent<v8::Object> to_be_disposed; |
| 6250 | 6250 |
| 6251 void DisposeAndForceGcCallback(v8::Persistent<v8::Value> handle, void*) { | 6251 void DisposeAndForceGcCallback(v8::Persistent<v8::Value> handle, void*) { |
| 6252 to_be_disposed.Dispose(); | 6252 to_be_disposed.Dispose(); |
| 6253 i::Heap::CollectAllGarbage(); | 6253 i::Heap::CollectAllGarbage(false); |
| 6254 } | 6254 } |
| 6255 | 6255 |
| 6256 | 6256 |
| 6257 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { | 6257 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { |
| 6258 LocalContext context; | 6258 LocalContext context; |
| 6259 | 6259 |
| 6260 v8::Persistent<v8::Object> handle1, handle2; | 6260 v8::Persistent<v8::Object> handle1, handle2; |
| 6261 { | 6261 { |
| 6262 v8::HandleScope scope; | 6262 v8::HandleScope scope; |
| 6263 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); | 6263 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); |
| 6264 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); | 6264 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); |
| 6265 } | 6265 } |
| 6266 handle1.MakeWeak(NULL, DisposeAndForceGcCallback); | 6266 handle1.MakeWeak(NULL, DisposeAndForceGcCallback); |
| 6267 to_be_disposed = handle2; | 6267 to_be_disposed = handle2; |
| 6268 i::Heap::CollectAllGarbage(); | 6268 i::Heap::CollectAllGarbage(false); |
| 6269 } | 6269 } |
| 6270 | 6270 |
| 6271 | 6271 |
| 6272 THREADED_TEST(CheckForCrossContextObjectLiterals) { | 6272 THREADED_TEST(CheckForCrossContextObjectLiterals) { |
| 6273 v8::V8::Initialize(); | 6273 v8::V8::Initialize(); |
| 6274 | 6274 |
| 6275 const int nof = 2; | 6275 const int nof = 2; |
| 6276 const char* sources[nof] = { | 6276 const char* sources[nof] = { |
| 6277 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", | 6277 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", |
| 6278 "Object()" | 6278 "Object()" |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6835 private: | 6835 private: |
| 6836 RegExpInterruptTest* test_; | 6836 RegExpInterruptTest* test_; |
| 6837 }; | 6837 }; |
| 6838 | 6838 |
| 6839 void CollectGarbage() { | 6839 void CollectGarbage() { |
| 6840 block_->Wait(); | 6840 block_->Wait(); |
| 6841 while (gc_during_regexp_ < kRequiredGCs) { | 6841 while (gc_during_regexp_ < kRequiredGCs) { |
| 6842 { | 6842 { |
| 6843 v8::Locker lock; | 6843 v8::Locker lock; |
| 6844 // TODO(lrn): Perhaps create some garbage before collecting. | 6844 // TODO(lrn): Perhaps create some garbage before collecting. |
| 6845 i::Heap::CollectAllGarbage(); | 6845 i::Heap::CollectAllGarbage(false); |
| 6846 gc_count_++; | 6846 gc_count_++; |
| 6847 } | 6847 } |
| 6848 i::OS::Sleep(1); | 6848 i::OS::Sleep(1); |
| 6849 } | 6849 } |
| 6850 gc_success_ = true; | 6850 gc_success_ = true; |
| 6851 } | 6851 } |
| 6852 | 6852 |
| 6853 void LongRunningRegExp() { | 6853 void LongRunningRegExp() { |
| 6854 block_->Signal(); // Enable garbage collection thread on next preemption. | 6854 block_->Signal(); // Enable garbage collection thread on next preemption. |
| 6855 int rounds = 0; | 6855 int rounds = 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6956 } | 6956 } |
| 6957 private: | 6957 private: |
| 6958 ApplyInterruptTest* test_; | 6958 ApplyInterruptTest* test_; |
| 6959 }; | 6959 }; |
| 6960 | 6960 |
| 6961 void CollectGarbage() { | 6961 void CollectGarbage() { |
| 6962 block_->Wait(); | 6962 block_->Wait(); |
| 6963 while (gc_during_apply_ < kRequiredGCs) { | 6963 while (gc_during_apply_ < kRequiredGCs) { |
| 6964 { | 6964 { |
| 6965 v8::Locker lock; | 6965 v8::Locker lock; |
| 6966 i::Heap::CollectAllGarbage(); | 6966 i::Heap::CollectAllGarbage(false); |
| 6967 gc_count_++; | 6967 gc_count_++; |
| 6968 } | 6968 } |
| 6969 i::OS::Sleep(1); | 6969 i::OS::Sleep(1); |
| 6970 } | 6970 } |
| 6971 gc_success_ = true; | 6971 gc_success_ = true; |
| 6972 } | 6972 } |
| 6973 | 6973 |
| 6974 void LongRunningApply() { | 6974 void LongRunningApply() { |
| 6975 block_->Signal(); | 6975 block_->Signal(); |
| 6976 int rounds = 0; | 6976 int rounds = 0; |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7673 } | 7673 } |
| 7674 | 7674 |
| 7675 | 7675 |
| 7676 THREADED_TEST(PixelArray) { | 7676 THREADED_TEST(PixelArray) { |
| 7677 v8::HandleScope scope; | 7677 v8::HandleScope scope; |
| 7678 LocalContext context; | 7678 LocalContext context; |
| 7679 const int kElementCount = 40; | 7679 const int kElementCount = 40; |
| 7680 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); | 7680 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
| 7681 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, | 7681 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, |
| 7682 pixel_data); | 7682 pixel_data); |
| 7683 i::Heap::CollectAllGarbage(); // Force GC to trigger verification. | 7683 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
| 7684 for (int i = 0; i < kElementCount; i++) { | 7684 for (int i = 0; i < kElementCount; i++) { |
| 7685 pixels->set(i, i); | 7685 pixels->set(i, i); |
| 7686 } | 7686 } |
| 7687 i::Heap::CollectAllGarbage(); // Force GC to trigger verification. | 7687 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
| 7688 for (int i = 0; i < kElementCount; i++) { | 7688 for (int i = 0; i < kElementCount; i++) { |
| 7689 CHECK_EQ(i, pixels->get(i)); | 7689 CHECK_EQ(i, pixels->get(i)); |
| 7690 CHECK_EQ(i, pixel_data[i]); | 7690 CHECK_EQ(i, pixel_data[i]); |
| 7691 } | 7691 } |
| 7692 | 7692 |
| 7693 v8::Handle<v8::Object> obj = v8::Object::New(); | 7693 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 7694 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 7694 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 7695 // Set the elements to be the pixels. | 7695 // Set the elements to be the pixels. |
| 7696 // jsobj->set_elements(*pixels); | 7696 // jsobj->set_elements(*pixels); |
| 7697 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 7697 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7835 LocalContext context; | 7835 LocalContext context; |
| 7836 v8::TryCatch try_catch; | 7836 v8::TryCatch try_catch; |
| 7837 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 7837 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
| 7838 v8::Handle<v8::String> src = v8::String::New(source); | 7838 v8::Handle<v8::String> src = v8::String::New(source); |
| 7839 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); | 7839 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); |
| 7840 v8::Script::New(src, origin)->Run(); | 7840 v8::Script::New(src, origin)->Run(); |
| 7841 CHECK(try_catch.HasCaught()); | 7841 CHECK(try_catch.HasCaught()); |
| 7842 v8::String::Utf8Value stack(try_catch.StackTrace()); | 7842 v8::String::Utf8Value stack(try_catch.StackTrace()); |
| 7843 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 7843 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
| 7844 } | 7844 } |
| OLD | NEW |