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

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

Issue 10917211: Introduce new API to expose external string resource regardless of encoding. (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::Encoding encoding = String::UNKNOWN_ENCODING;
408 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
409 source->GetExternalStringResourceBase(&encoding));
410 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
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::Encoding encoding = String::UNKNOWN_ENCODING;
433 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
434 source->GetExternalStringResourceBase(&encoding));
435 CHECK_EQ(String::ASCII_ENCODING, encoding);
425 Local<Script> script = Script::Compile(source); 436 Local<Script> script = Script::Compile(source);
426 Local<Value> value = script->Run(); 437 Local<Value> value = script->Run();
427 CHECK(value->IsNumber()); 438 CHECK(value->IsNumber());
428 CHECK_EQ(7, value->Int32Value()); 439 CHECK_EQ(7, value->Int32Value());
429 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 440 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
430 CHECK_EQ(0, dispose_count); 441 CHECK_EQ(0, dispose_count);
431 } 442 }
432 i::Isolate::Current()->compilation_cache()->Clear(); 443 i::Isolate::Current()->compilation_cache()->Clear();
433 HEAP->CollectAllAvailableGarbage(); 444 HEAP->CollectAllAvailableGarbage();
434 CHECK_EQ(1, dispose_count); 445 CHECK_EQ(1, dispose_count);
435 } 446 }
436 447
437 448
438 THREADED_TEST(ScriptMakingExternalString) { 449 THREADED_TEST(ScriptMakingExternalString) {
439 int dispose_count = 0; 450 int dispose_count = 0;
440 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 451 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
441 { 452 {
442 v8::HandleScope scope; 453 v8::HandleScope scope;
443 LocalContext env; 454 LocalContext env;
444 Local<String> source = String::New(two_byte_source); 455 Local<String> source = String::New(two_byte_source);
445 // Trigger GCs so that the newly allocated string moves to old gen. 456 // Trigger GCs so that the newly allocated string moves to old gen.
446 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 457 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
447 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 458 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
459 CHECK_EQ(source->IsExternal(), false);
460 CHECK_EQ(source->IsExternalAscii(), false);
461 String::Encoding encoding = String::UNKNOWN_ENCODING;
462 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding));
463 CHECK_EQ(String::ASCII_ENCODING, encoding);
448 bool success = source->MakeExternal(new TestResource(two_byte_source, 464 bool success = source->MakeExternal(new TestResource(two_byte_source,
449 &dispose_count)); 465 &dispose_count));
450 CHECK(success); 466 CHECK(success);
451 Local<Script> script = Script::Compile(source); 467 Local<Script> script = Script::Compile(source);
452 Local<Value> value = script->Run(); 468 Local<Value> value = script->Run();
453 CHECK(value->IsNumber()); 469 CHECK(value->IsNumber());
454 CHECK_EQ(7, value->Int32Value()); 470 CHECK_EQ(7, value->Int32Value());
455 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 471 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
456 CHECK_EQ(0, dispose_count); 472 CHECK_EQ(0, dispose_count);
457 } 473 }
(...skipping 16998 matching lines...) Expand 10 before | Expand all | Expand 10 after
17456 17472
17457 i::Semaphore* sem_; 17473 i::Semaphore* sem_;
17458 volatile int sem_value_; 17474 volatile int sem_value_;
17459 }; 17475 };
17460 17476
17461 17477
17462 THREADED_TEST(SemaphoreInterruption) { 17478 THREADED_TEST(SemaphoreInterruption) {
17463 ThreadInterruptTest().RunTest(); 17479 ThreadInterruptTest().RunTest();
17464 } 17480 }
17465 #endif // WIN32 17481 #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