OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 17324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17335 CHECK_EQ(0, destroyed); | 17335 CHECK_EQ(0, destroyed); |
17336 USE(ring); | 17336 USE(ring); |
17337 } | 17337 } |
17338 | 17338 |
17339 isolate->Dispose(); | 17339 isolate->Dispose(); |
17340 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. | 17340 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
17341 CHECK_EQ(1, destroyed); | 17341 CHECK_EQ(1, destroyed); |
17342 } | 17342 } |
17343 | 17343 |
17344 | 17344 |
| 17345 TEST(ExternalInternalizedStringCollectedAtTearDown) { |
| 17346 int destroyed = 0; |
| 17347 v8::Isolate* isolate = v8::Isolate::New(); |
| 17348 { v8::Isolate::Scope isolate_scope(isolate); |
| 17349 LocalContext env(isolate); |
| 17350 v8::HandleScope handle_scope(isolate); |
| 17351 CompileRun("var ring = 'One string to test them all';"); |
| 17352 const char* s = "One string to test them all"; |
| 17353 TestAsciiResource* inscription = |
| 17354 new TestAsciiResource(i::StrDup(s), &destroyed); |
| 17355 v8::Local<v8::String> ring = CompileRun("ring")->ToString(); |
| 17356 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); |
| 17357 ring->MakeExternal(inscription); |
| 17358 // Ring is still alive. Orcs are roaming freely across our lands. |
| 17359 CHECK_EQ(0, destroyed); |
| 17360 USE(ring); |
| 17361 } |
| 17362 |
| 17363 isolate->Dispose(); |
| 17364 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
| 17365 CHECK_EQ(1, destroyed); |
| 17366 } |
| 17367 |
| 17368 |
| 17369 TEST(ExternalInternalizedStringCollectedAtGC) { |
| 17370 int destroyed = 0; |
| 17371 { LocalContext env; |
| 17372 v8::HandleScope handle_scope(env->GetIsolate()); |
| 17373 CompileRun("var ring = 'One string to test them all';"); |
| 17374 const char* s = "One string to test them all"; |
| 17375 TestAsciiResource* inscription = |
| 17376 new TestAsciiResource(i::StrDup(s), &destroyed); |
| 17377 v8::Local<v8::String> ring = CompileRun("ring")->ToString(); |
| 17378 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); |
| 17379 ring->MakeExternal(inscription); |
| 17380 // Ring is still alive. Orcs are roaming freely across our lands. |
| 17381 CHECK_EQ(0, destroyed); |
| 17382 USE(ring); |
| 17383 } |
| 17384 |
| 17385 // Garbage collector deals swift blows to evil. |
| 17386 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 17387 CcTest::heap()->CollectAllAvailableGarbage(); |
| 17388 |
| 17389 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
| 17390 CHECK_EQ(1, destroyed); |
| 17391 } |
| 17392 |
| 17393 |
17345 static double DoubleFromBits(uint64_t value) { | 17394 static double DoubleFromBits(uint64_t value) { |
17346 double target; | 17395 double target; |
17347 i::OS::MemCopy(&target, &value, sizeof(target)); | 17396 i::OS::MemCopy(&target, &value, sizeof(target)); |
17348 return target; | 17397 return target; |
17349 } | 17398 } |
17350 | 17399 |
17351 | 17400 |
17352 static uint64_t DoubleToBits(double value) { | 17401 static uint64_t DoubleToBits(double value) { |
17353 uint64_t target; | 17402 uint64_t target; |
17354 i::OS::MemCopy(&target, &value, sizeof(target)); | 17403 i::OS::MemCopy(&target, &value, sizeof(target)); |
(...skipping 3519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20874 } | 20923 } |
20875 for (int i = 0; i < runs; i++) { | 20924 for (int i = 0; i < runs; i++) { |
20876 Local<String> expected; | 20925 Local<String> expected; |
20877 if (i != 0) { | 20926 if (i != 0) { |
20878 CHECK_EQ(v8_str("escape value"), values[i]); | 20927 CHECK_EQ(v8_str("escape value"), values[i]); |
20879 } else { | 20928 } else { |
20880 CHECK(values[i].IsEmpty()); | 20929 CHECK(values[i].IsEmpty()); |
20881 } | 20930 } |
20882 } | 20931 } |
20883 } | 20932 } |
OLD | NEW |