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

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

Issue 139923003: Fixed a few lifetime/ownership issues in cctest/test-api. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 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 | « test/cctest/cctest.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 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 static uint16_t* AsciiToTwoByteString(const char* source) { 455 static uint16_t* AsciiToTwoByteString(const char* source) {
456 int array_length = i::StrLength(source) + 1; 456 int array_length = i::StrLength(source) + 1;
457 uint16_t* converted = i::NewArray<uint16_t>(array_length); 457 uint16_t* converted = i::NewArray<uint16_t>(array_length);
458 for (int i = 0; i < array_length; i++) converted[i] = source[i]; 458 for (int i = 0; i < array_length; i++) converted[i] = source[i];
459 return converted; 459 return converted;
460 } 460 }
461 461
462 462
463 class TestResource: public String::ExternalStringResource { 463 class TestResource: public String::ExternalStringResource {
464 public: 464 public:
465 explicit TestResource(uint16_t* data, int* counter = NULL) 465 TestResource(uint16_t* data, int* counter = NULL, bool owning_data = true)
466 : data_(data), length_(0), counter_(counter) { 466 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) {
467 while (data[length_]) ++length_; 467 while (data[length_]) ++length_;
468 } 468 }
469 469
470 ~TestResource() { 470 ~TestResource() {
471 i::DeleteArray(data_); 471 if (owning_data_) i::DeleteArray(data_);
472 if (counter_ != NULL) ++*counter_; 472 if (counter_ != NULL) ++*counter_;
473 } 473 }
474 474
475 const uint16_t* data() const { 475 const uint16_t* data() const {
476 return data_; 476 return data_;
477 } 477 }
478 478
479 size_t length() const { 479 size_t length() const {
480 return length_; 480 return length_;
481 } 481 }
482
482 private: 483 private:
483 uint16_t* data_; 484 uint16_t* data_;
484 size_t length_; 485 size_t length_;
485 int* counter_; 486 int* counter_;
487 bool owning_data_;
486 }; 488 };
487 489
488 490
489 class TestAsciiResource: public String::ExternalAsciiStringResource { 491 class TestAsciiResource: public String::ExternalAsciiStringResource {
490 public: 492 public:
491 TestAsciiResource(const char* data, int* counter = NULL, size_t offset = 0) 493 TestAsciiResource(const char* data, int* counter = NULL, size_t offset = 0)
492 : orig_data_(data), 494 : orig_data_(data),
493 data_(data + offset), 495 data_(data + offset),
494 length_(strlen(data) - offset), 496 length_(strlen(data) - offset),
495 counter_(counter) { } 497 counter_(counter) { }
(...skipping 14715 matching lines...) Expand 10 before | Expand all | Expand 10 after
15211 const char* ascii_sources[] = { 15213 const char* ascii_sources[] = {
15212 "0.5", 15214 "0.5",
15213 "-0.5", // This mainly testes PushBack in the Scanner. 15215 "-0.5", // This mainly testes PushBack in the Scanner.
15214 "--0.5", // This mainly testes PushBack in the Scanner. 15216 "--0.5", // This mainly testes PushBack in the Scanner.
15215 NULL 15217 NULL
15216 }; 15218 };
15217 15219
15218 // Compile the sources as external two byte strings. 15220 // Compile the sources as external two byte strings.
15219 for (int i = 0; ascii_sources[i] != NULL; i++) { 15221 for (int i = 0; ascii_sources[i] != NULL; i++) {
15220 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); 15222 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
15221 UC16VectorResource uc16_resource( 15223 TestResource* uc16_resource = new TestResource(two_byte_string);
15222 i::Vector<const uint16_t>(two_byte_string,
15223 i::StrLength(ascii_sources[i])));
15224 v8::Local<v8::String> source = 15224 v8::Local<v8::String> source =
15225 v8::String::NewExternal(context->GetIsolate(), &uc16_resource); 15225 v8::String::NewExternal(context->GetIsolate(), uc16_resource);
15226 v8::Script::Compile(source); 15226 v8::Script::Compile(source);
15227 i::DeleteArray(two_byte_string);
15228 } 15227 }
15229 } 15228 }
15230 15229
15231 15230
15232 #ifndef V8_INTERPRETED_REGEXP 15231 #ifndef V8_INTERPRETED_REGEXP
15233 15232
15234 struct RegExpInterruptionData { 15233 struct RegExpInterruptionData {
15235 int loop_count; 15234 int loop_count;
15236 UC16VectorResource* string_resource; 15235 UC16VectorResource* string_resource;
15237 v8::Persistent<v8::String> string; 15236 v8::Persistent<v8::String> string;
(...skipping 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after
17864 17863
17865 TEST(VisitExternalStrings) { 17864 TEST(VisitExternalStrings) {
17866 LocalContext env; 17865 LocalContext env;
17867 v8::HandleScope scope(env->GetIsolate()); 17866 v8::HandleScope scope(env->GetIsolate());
17868 const char* string = "Some string"; 17867 const char* string = "Some string";
17869 uint16_t* two_byte_string = AsciiToTwoByteString(string); 17868 uint16_t* two_byte_string = AsciiToTwoByteString(string);
17870 TestResource* resource[4]; 17869 TestResource* resource[4];
17871 resource[0] = new TestResource(two_byte_string); 17870 resource[0] = new TestResource(two_byte_string);
17872 v8::Local<v8::String> string0 = 17871 v8::Local<v8::String> string0 =
17873 v8::String::NewExternal(env->GetIsolate(), resource[0]); 17872 v8::String::NewExternal(env->GetIsolate(), resource[0]);
17874 resource[1] = new TestResource(two_byte_string); 17873 resource[1] = new TestResource(two_byte_string, NULL, false);
17875 v8::Local<v8::String> string1 = 17874 v8::Local<v8::String> string1 =
17876 v8::String::NewExternal(env->GetIsolate(), resource[1]); 17875 v8::String::NewExternal(env->GetIsolate(), resource[1]);
17877 17876
17878 // Externalized symbol. 17877 // Externalized symbol.
17879 resource[2] = new TestResource(two_byte_string); 17878 resource[2] = new TestResource(two_byte_string, NULL, false);
17880 v8::Local<v8::String> string2 = v8::String::NewFromUtf8( 17879 v8::Local<v8::String> string2 = v8::String::NewFromUtf8(
17881 env->GetIsolate(), string, v8::String::kInternalizedString); 17880 env->GetIsolate(), string, v8::String::kInternalizedString);
17882 CHECK(string2->MakeExternal(resource[2])); 17881 CHECK(string2->MakeExternal(resource[2]));
17883 17882
17884 // Symbolized External. 17883 // Symbolized External.
17885 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); 17884 resource[3] = new TestResource(AsciiToTwoByteString("Some other string"));
17886 v8::Local<v8::String> string3 = 17885 v8::Local<v8::String> string3 =
17887 v8::String::NewExternal(env->GetIsolate(), resource[3]); 17886 v8::String::NewExternal(env->GetIsolate(), resource[3]);
17888 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. 17887 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string.
17889 // Turn into a symbol. 17888 // Turn into a symbol.
(...skipping 4077 matching lines...) Expand 10 before | Expand all | Expand 10 after
21967 21966
21968 21967
21969 TEST(TestFunctionCallOptimization) { 21968 TEST(TestFunctionCallOptimization) {
21970 i::FLAG_allow_natives_syntax = true; 21969 i::FLAG_allow_natives_syntax = true;
21971 ApiCallOptimizationChecker checker; 21970 ApiCallOptimizationChecker checker;
21972 checker.Run(true, true); 21971 checker.Run(true, true);
21973 checker.Run(false, true); 21972 checker.Run(false, true);
21974 checker.Run(true, false); 21973 checker.Run(true, false);
21975 checker.Run(false, false); 21974 checker.Run(false, false);
21976 } 21975 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698