OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 | 1419 |
1420 // Check reading and writing unaligned pointers. | 1420 // Check reading and writing unaligned pointers. |
1421 obj->SetPointerInInternalField(0, unaligned); | 1421 obj->SetPointerInInternalField(0, unaligned); |
1422 i::Heap::CollectAllGarbage(false); | 1422 i::Heap::CollectAllGarbage(false); |
1423 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); | 1423 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); |
1424 | 1424 |
1425 delete[] data; | 1425 delete[] data; |
1426 } | 1426 } |
1427 | 1427 |
1428 | 1428 |
| 1429 THREADED_TEST(InternalFieldsNativePointersAndExternal) { |
| 1430 v8::HandleScope scope; |
| 1431 LocalContext env; |
| 1432 |
| 1433 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
| 1434 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 1435 instance_templ->SetInternalFieldCount(1); |
| 1436 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 1437 CHECK_EQ(1, obj->InternalFieldCount()); |
| 1438 CHECK(obj->GetPointerFromInternalField(0) == NULL); |
| 1439 |
| 1440 char* data = new char[100]; |
| 1441 |
| 1442 void* aligned = data; |
| 1443 CHECK_EQ(0, reinterpret_cast<uintptr_t>(aligned) & 0x1); |
| 1444 void* unaligned = data + 1; |
| 1445 CHECK_EQ(1, reinterpret_cast<uintptr_t>(unaligned) & 0x1); |
| 1446 |
| 1447 obj->SetPointerInInternalField(0, aligned); |
| 1448 i::Heap::CollectAllGarbage(false); |
| 1449 CHECK_EQ(aligned, v8::External::Unwrap(obj->GetInternalField(0))); |
| 1450 |
| 1451 obj->SetPointerInInternalField(0, unaligned); |
| 1452 i::Heap::CollectAllGarbage(false); |
| 1453 CHECK_EQ(unaligned, v8::External::Unwrap(obj->GetInternalField(0))); |
| 1454 |
| 1455 obj->SetInternalField(0, v8::External::Wrap(aligned)); |
| 1456 i::Heap::CollectAllGarbage(false); |
| 1457 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); |
| 1458 |
| 1459 obj->SetInternalField(0, v8::External::Wrap(unaligned)); |
| 1460 i::Heap::CollectAllGarbage(false); |
| 1461 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); |
| 1462 |
| 1463 delete[] data; |
| 1464 } |
| 1465 |
| 1466 |
1429 THREADED_TEST(IdentityHash) { | 1467 THREADED_TEST(IdentityHash) { |
1430 v8::HandleScope scope; | 1468 v8::HandleScope scope; |
1431 LocalContext env; | 1469 LocalContext env; |
1432 | 1470 |
1433 // Ensure that the test starts with an fresh heap to test whether the hash | 1471 // Ensure that the test starts with an fresh heap to test whether the hash |
1434 // code is based on the address. | 1472 // code is based on the address. |
1435 i::Heap::CollectAllGarbage(false); | 1473 i::Heap::CollectAllGarbage(false); |
1436 Local<v8::Object> obj = v8::Object::New(); | 1474 Local<v8::Object> obj = v8::Object::New(); |
1437 int hash = obj->GetIdentityHash(); | 1475 int hash = obj->GetIdentityHash(); |
1438 int hash1 = obj->GetIdentityHash(); | 1476 int hash1 = obj->GetIdentityHash(); |
(...skipping 6631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8070 env->Global()->Set(v8_str("get_stack_limit"), fun); | 8108 env->Global()->Set(v8_str("get_stack_limit"), fun); |
8071 CompileRun("get_stack_limit();"); | 8109 CompileRun("get_stack_limit();"); |
8072 | 8110 |
8073 CHECK(stack_limit == set_limit); | 8111 CHECK(stack_limit == set_limit); |
8074 } | 8112 } |
8075 { | 8113 { |
8076 v8::Locker locker; | 8114 v8::Locker locker; |
8077 CHECK(stack_limit == set_limit); | 8115 CHECK(stack_limit == set_limit); |
8078 } | 8116 } |
8079 } | 8117 } |
OLD | NEW |