Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: test/cctest/test-api.cc

Issue 10918169: Refactored fast external string resource getter. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 LocalContext env; 397 LocalContext env;
398 TestResource* resource = new TestResource(two_byte_source, &dispose_count); 398 TestResource* resource = new TestResource(two_byte_source, &dispose_count);
399 Local<String> source = String::NewExternal(resource); 399 Local<String> source = String::NewExternal(resource);
400 Local<Script> script = Script::Compile(source); 400 Local<Script> script = Script::Compile(source);
401 Local<Value> value = script->Run(); 401 Local<Value> value = script->Run();
402 CHECK(value->IsNumber()); 402 CHECK(value->IsNumber());
403 CHECK_EQ(7, value->Int32Value()); 403 CHECK_EQ(7, value->Int32Value());
404 CHECK(source->IsExternal()); 404 CHECK(source->IsExternal());
405 CHECK_EQ(resource, 405 CHECK_EQ(resource,
406 static_cast<TestResource*>(source->GetExternalStringResource())); 406 static_cast<TestResource*>(source->GetExternalStringResource()));
407 String::ExternalStringResourceBase* pointer = NULL;
408 CHECK_EQ(String::kExternalTwoByteStringType,
409 source->GetExternalStringResourceBase(pointer));
410 CHECK_EQ(resource, static_cast<TestResource*>(pointer));
407 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 411 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
408 CHECK_EQ(0, dispose_count); 412 CHECK_EQ(0, dispose_count);
409 } 413 }
410 v8::internal::Isolate::Current()->compilation_cache()->Clear(); 414 v8::internal::Isolate::Current()->compilation_cache()->Clear();
411 HEAP->CollectAllAvailableGarbage(); 415 HEAP->CollectAllAvailableGarbage();
412 CHECK_EQ(1, dispose_count); 416 CHECK_EQ(1, dispose_count);
413 } 417 }
414 418
415 419
416 THREADED_TEST(ScriptUsingAsciiStringResource) { 420 THREADED_TEST(ScriptUsingAsciiStringResource) {
417 int dispose_count = 0; 421 int dispose_count = 0;
418 const char* c_source = "1 + 2 * 3"; 422 const char* c_source = "1 + 2 * 3";
419 { 423 {
420 v8::HandleScope scope; 424 v8::HandleScope scope;
421 LocalContext env; 425 LocalContext env;
422 Local<String> source = 426 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source),
423 String::NewExternal(new TestAsciiResource(i::StrDup(c_source), 427 &dispose_count);
424 &dispose_count)); 428 Local<String> source = String::NewExternal(resource);
429 CHECK(source->IsExternalAscii());
430 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
431 source->GetExternalAsciiStringResource());
432 String::ExternalStringResourceBase* pointer = NULL;
433 CHECK_EQ(String::kExternalAsciiStringType,
434 source->GetExternalStringResourceBase(pointer));
435 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
436 pointer);
425 Local<Script> script = Script::Compile(source); 437 Local<Script> script = Script::Compile(source);
426 Local<Value> value = script->Run(); 438 Local<Value> value = script->Run();
427 CHECK(value->IsNumber()); 439 CHECK(value->IsNumber());
428 CHECK_EQ(7, value->Int32Value()); 440 CHECK_EQ(7, value->Int32Value());
429 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 441 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
430 CHECK_EQ(0, dispose_count); 442 CHECK_EQ(0, dispose_count);
431 } 443 }
432 i::Isolate::Current()->compilation_cache()->Clear(); 444 i::Isolate::Current()->compilation_cache()->Clear();
433 HEAP->CollectAllAvailableGarbage(); 445 HEAP->CollectAllAvailableGarbage();
434 CHECK_EQ(1, dispose_count); 446 CHECK_EQ(1, dispose_count);
435 } 447 }
436 448
437 449
438 THREADED_TEST(ScriptMakingExternalString) { 450 THREADED_TEST(ScriptMakingExternalString) {
439 int dispose_count = 0; 451 int dispose_count = 0;
440 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 452 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
441 { 453 {
442 v8::HandleScope scope; 454 v8::HandleScope scope;
443 LocalContext env; 455 LocalContext env;
444 Local<String> source = String::New(two_byte_source); 456 Local<String> source = String::New(two_byte_source);
445 // Trigger GCs so that the newly allocated string moves to old gen. 457 // Trigger GCs so that the newly allocated string moves to old gen.
446 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 458 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
447 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 459 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
460 CHECK_EQ(source->IsExternal(), false);
461 CHECK_EQ(source->IsExternalAscii(), false);
462 String::ExternalStringResourceBase* pointer;
463 pointer = NULL;
464 CHECK_EQ(0, source->GetExternalStringResourceBase(pointer));
465 CHECK_EQ(pointer, NULL);
448 bool success = source->MakeExternal(new TestResource(two_byte_source, 466 bool success = source->MakeExternal(new TestResource(two_byte_source,
449 &dispose_count)); 467 &dispose_count));
450 CHECK(success); 468 CHECK(success);
451 Local<Script> script = Script::Compile(source); 469 Local<Script> script = Script::Compile(source);
452 Local<Value> value = script->Run(); 470 Local<Value> value = script->Run();
453 CHECK(value->IsNumber()); 471 CHECK(value->IsNumber());
454 CHECK_EQ(7, value->Int32Value()); 472 CHECK_EQ(7, value->Int32Value());
455 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 473 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
456 CHECK_EQ(0, dispose_count); 474 CHECK_EQ(0, dispose_count);
457 } 475 }
(...skipping 16986 matching lines...) Expand 10 before | Expand all | Expand 10 after
17444 17462
17445 i::Semaphore* sem_; 17463 i::Semaphore* sem_;
17446 volatile int sem_value_; 17464 volatile int sem_value_;
17447 }; 17465 };
17448 17466
17449 17467
17450 THREADED_TEST(SemaphoreInterruption) { 17468 THREADED_TEST(SemaphoreInterruption) {
17451 ThreadInterruptTest().RunTest(); 17469 ThreadInterruptTest().RunTest();
17452 } 17470 }
17453 #endif // WIN32 17471 #endif // WIN32
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698