Reviewers: ulan,

Description:
Fixed a few lifetime/ownership issues in cctest/test-api.

   * Fixed CompileExternalTwoByteSource: Registered resources should
     better still be alive when they are accessed.

   * Fixed ownership in cctest/test-api/VisitExternalStrings.

Please review this at https://codereview.chromium.org/139923003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+15, -10 lines):
  M test/cctest/cctest.h
  M test/cctest/cctest.cc
  M test/cctest/test-api.cc


Index: test/cctest/cctest.cc
diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc
index 865bc6d22a27504c42f8ec7c2ca46f9e54119238..b1cf5abb4e62284c2d9ea75942b2f2d0e6f253ef 100644
--- a/test/cctest/cctest.cc
+++ b/test/cctest/cctest.cc
@@ -199,6 +199,7 @@ int main(int argc, char* argv[]) {
   }
   if (print_run_count && tests_run != 1)
     printf("Ran %i tests.\n", tests_run);
+  CcTest::TearDown();
   if (!disable_automatic_dispose_) v8::V8::Dispose();
   return 0;
 }
Index: test/cctest/cctest.h
diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h
index 6d2c552ac6ca5ef8786b7a11234343cdfc35d3b8..6c67dd52ec4094d7e6805266879e1d92b3f20cfb 100644
--- a/test/cctest/cctest.h
+++ b/test/cctest/cctest.h
@@ -130,6 +130,11 @@ class CcTest {
       CcTestExtensionFlags extensions,
       v8::Isolate* isolate = CcTest::isolate());

+  static void TearDown() {
+    // TODO(svenpanne) Enable this when our cctests are fixed.
+    // if (isolate_ != NULL) isolate_->Dispose();
+  }
+
  private:
   friend int main(int argc, char** argv);
   TestFunction* callback_;
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 561fd4e397dfeeadebe2f77e87ea7fec05db89b0..48730001ae4684417daae5a847e6cc0d1f65ef15 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -462,13 +462,13 @@ static uint16_t* AsciiToTwoByteString(const char* source) {

 class TestResource: public String::ExternalStringResource {
  public:
-  explicit TestResource(uint16_t* data, int* counter = NULL)
-    : data_(data), length_(0), counter_(counter) {
+ TestResource(uint16_t* data, int* counter = NULL, bool owning_data = true) + : data_(data), length_(0), counter_(counter), owning_data_(owning_data) {
     while (data[length_]) ++length_;
   }

   ~TestResource() {
-    i::DeleteArray(data_);
+    if (owning_data_) i::DeleteArray(data_);
     if (counter_ != NULL) ++*counter_;
   }

@@ -479,10 +479,12 @@ class TestResource: public String::ExternalStringResource {
   size_t length() const {
     return length_;
   }
+
  private:
   uint16_t* data_;
   size_t length_;
   int* counter_;
+  bool owning_data_;
 };


@@ -15218,13 +15220,10 @@ TEST(CompileExternalTwoByteSource) {
   // Compile the sources as external two byte strings.
   for (int i = 0; ascii_sources[i] != NULL; i++) {
     uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
-    UC16VectorResource uc16_resource(
-        i::Vector<const uint16_t>(two_byte_string,
-                                  i::StrLength(ascii_sources[i])));
+    TestResource* uc16_resource = new TestResource(two_byte_string);
     v8::Local<v8::String> source =
-        v8::String::NewExternal(context->GetIsolate(), &uc16_resource);
+        v8::String::NewExternal(context->GetIsolate(), uc16_resource);
     v8::Script::Compile(source);
-    i::DeleteArray(two_byte_string);
   }
 }

@@ -17871,12 +17870,12 @@ TEST(VisitExternalStrings) {
   resource[0] = new TestResource(two_byte_string);
   v8::Local<v8::String> string0 =
       v8::String::NewExternal(env->GetIsolate(), resource[0]);
-  resource[1] = new TestResource(two_byte_string);
+  resource[1] = new TestResource(two_byte_string, NULL, false);
   v8::Local<v8::String> string1 =
       v8::String::NewExternal(env->GetIsolate(), resource[1]);

   // Externalized symbol.
-  resource[2] = new TestResource(two_byte_string);
+  resource[2] = new TestResource(two_byte_string, NULL, false);
   v8::Local<v8::String> string2 = v8::String::NewFromUtf8(
       env->GetIsolate(), string, v8::String::kInternalizedString);
   CHECK(string2->MakeExternal(resource[2]));


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to