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.

R=ulan@chromium.org

Review URL: https://codereview.chromium.org/139923003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18971 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 735a5073
......@@ -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;
}
......
......@@ -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_;
......
......@@ -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]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment