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

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

Issue 1939: Fix issue 65 by making sure not to leak any of the cache... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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/compilation-cache.cc ('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 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 438 }
439 private: 439 private:
440 char* data_; 440 char* data_;
441 size_t length_; 441 size_t length_;
442 }; 442 };
443 443
444 444
445 int TestAsciiResource::dispose_count = 0; 445 int TestAsciiResource::dispose_count = 0;
446 446
447 447
448 TEST(ScriptUsingStringResource) { 448 THREADED_TEST(ScriptUsingStringResource) {
449 TestResource::dispose_count = 0; 449 TestResource::dispose_count = 0;
450 const char* c_source = "1 + 2 * 3"; 450 const char* c_source = "1 + 2 * 3";
451 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); 451 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
452 { 452 {
453 v8::HandleScope scope; 453 v8::HandleScope scope;
454 LocalContext env; 454 LocalContext env;
455 TestResource* resource = new TestResource(two_byte_source); 455 TestResource* resource = new TestResource(two_byte_source);
456 Local<String> source = String::NewExternal(resource); 456 Local<String> source = String::NewExternal(resource);
457 Local<Script> script = Script::Compile(source); 457 Local<Script> script = Script::Compile(source);
458 Local<Value> value = script->Run(); 458 Local<Value> value = script->Run();
459 CHECK(value->IsNumber()); 459 CHECK(value->IsNumber());
460 CHECK_EQ(7, value->Int32Value()); 460 CHECK_EQ(7, value->Int32Value());
461 CHECK(source->IsExternal()); 461 CHECK(source->IsExternal());
462 CHECK_EQ(resource, 462 CHECK_EQ(resource,
463 static_cast<TestResource*>(source->GetExternalStringResource())); 463 static_cast<TestResource*>(source->GetExternalStringResource()));
464 v8::internal::Heap::CollectAllGarbage(); 464 v8::internal::Heap::CollectAllGarbage();
465 CHECK_EQ(0, TestResource::dispose_count); 465 CHECK_EQ(0, TestResource::dispose_count);
466 } 466 }
467 v8::internal::Heap::CollectAllGarbage(); 467 v8::internal::Heap::CollectAllGarbage();
468 CHECK_EQ(1, TestResource::dispose_count); 468 CHECK_EQ(1, TestResource::dispose_count);
469 } 469 }
470 470
471 471
472 TEST(ScriptUsingAsciiStringResource) { 472 THREADED_TEST(ScriptUsingAsciiStringResource) {
473 TestAsciiResource::dispose_count = 0; 473 TestAsciiResource::dispose_count = 0;
474 const char* c_source = "1 + 2 * 3"; 474 const char* c_source = "1 + 2 * 3";
475 { 475 {
476 v8::HandleScope scope; 476 v8::HandleScope scope;
477 LocalContext env; 477 LocalContext env;
478 Local<String> source = 478 Local<String> source =
479 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); 479 String::NewExternal(new TestAsciiResource(i::StrDup(c_source)));
480 Local<Script> script = Script::Compile(source); 480 Local<Script> script = Script::Compile(source);
481 Local<Value> value = script->Run(); 481 Local<Value> value = script->Run();
482 CHECK(value->IsNumber()); 482 CHECK(value->IsNumber());
(...skipping 4424 matching lines...) Expand 10 before | Expand all | Expand 10 after
4907 v8::Handle<v8::Script> script0 = 4907 v8::Handle<v8::Script> script0 =
4908 v8::Script::Compile(source0, v8::String::New("test.js")); 4908 v8::Script::Compile(source0, v8::String::New("test.js"));
4909 v8::Handle<v8::Script> script1 = 4909 v8::Handle<v8::Script> script1 =
4910 v8::Script::Compile(source1, v8::String::New("test.js")); 4910 v8::Script::Compile(source1, v8::String::New("test.js"));
4911 v8::Handle<v8::Script> script2 = 4911 v8::Handle<v8::Script> script2 =
4912 v8::Script::Compile(source0); // different origin 4912 v8::Script::Compile(source0); // different origin
4913 CHECK_EQ(1234, script0->Run()->Int32Value()); 4913 CHECK_EQ(1234, script0->Run()->Int32Value());
4914 CHECK_EQ(1234, script1->Run()->Int32Value()); 4914 CHECK_EQ(1234, script1->Run()->Int32Value());
4915 CHECK_EQ(1234, script2->Run()->Int32Value()); 4915 CHECK_EQ(1234, script2->Run()->Int32Value());
4916 } 4916 }
OLDNEW
« no previous file with comments | « src/compilation-cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698