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

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

Issue 9139018: Provide a way for iterating through all external strings referenced from the JS heap (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 11 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/heap.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 13657 matching lines...) Expand 10 before | Expand all | Expand 10 after
13668 LocalContext c1; 13668 LocalContext c1;
13669 v8::HeapStatistics heap_statistics; 13669 v8::HeapStatistics heap_statistics;
13670 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); 13670 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
13671 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); 13671 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0);
13672 v8::V8::GetHeapStatistics(&heap_statistics); 13672 v8::V8::GetHeapStatistics(&heap_statistics);
13673 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); 13673 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
13674 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); 13674 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
13675 } 13675 }
13676 13676
13677 13677
13678 class VisitorImpl : public v8::ExternalResourceVisitor {
13679 public:
13680 VisitorImpl(TestResource* r1, TestResource* r2)
13681 : resource1_(r1),
13682 resource2_(r2),
13683 found_resource1_(false),
13684 found_resource2_(false) {}
13685 virtual ~VisitorImpl() {}
13686 virtual void VisitExternalString(v8::Handle<v8::String> string) {
13687 if (!string->IsExternal()) {
13688 CHECK(string->IsExternalAscii());
13689 return;
13690 }
13691 v8::String::ExternalStringResource* resource =
13692 string->GetExternalStringResource();
13693 CHECK(resource);
13694 if (resource1_ == resource) {
13695 CHECK(!found_resource1_);
13696 found_resource1_ = true;
13697 }
13698 if (resource2_ == resource) {
13699 CHECK(!found_resource2_);
13700 found_resource2_ = true;
13701 }
13702 }
13703 void CheckVisitedResources() {
13704 CHECK(found_resource1_);
13705 CHECK(found_resource2_);
13706 }
13707
13708 private:
13709 v8::String::ExternalStringResource* resource1_;
13710 v8::String::ExternalStringResource* resource2_;
13711 bool found_resource1_;
13712 bool found_resource2_;
13713 };
13714
13715 TEST(VisitExternalStrings) {
13716 v8::HandleScope scope;
13717 LocalContext env;
13718 const char* string = "Some string";
13719 uint16_t* two_byte_string = AsciiToTwoByteString(string);
13720 TestResource* resource1 = new TestResource(two_byte_string);
13721 v8::Local<v8::String> string1 = v8::String::NewExternal(resource1);
13722 TestResource* resource2 = new TestResource(two_byte_string);
13723 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2);
Tobias Burnus 2012/01/13 20:57:01 The assignment to string1 and string2 breaks the b
yurys 2012/01/14 13:52:44 I can add an artificial usages of string1 and stri
13724
13725 VisitorImpl visitor(resource1, resource2);
13726 v8::V8::VisitExternalResources(&visitor);
13727 visitor.CheckVisitedResources();
13728 }
13729
13730
13678 static double DoubleFromBits(uint64_t value) { 13731 static double DoubleFromBits(uint64_t value) {
13679 double target; 13732 double target;
13680 memcpy(&target, &value, sizeof(target)); 13733 memcpy(&target, &value, sizeof(target));
13681 return target; 13734 return target;
13682 } 13735 }
13683 13736
13684 13737
13685 static uint64_t DoubleToBits(double value) { 13738 static uint64_t DoubleToBits(double value) {
13686 uint64_t target; 13739 uint64_t target;
13687 memcpy(&target, &value, sizeof(target)); 13740 memcpy(&target, &value, sizeof(target));
(...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after
15824 CompileRun("throw 'exception';"); 15877 CompileRun("throw 'exception';");
15825 } 15878 }
15826 15879
15827 15880
15828 TEST(CallCompletedCallbackTwoExceptions) { 15881 TEST(CallCompletedCallbackTwoExceptions) {
15829 v8::HandleScope scope; 15882 v8::HandleScope scope;
15830 LocalContext env; 15883 LocalContext env;
15831 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 15884 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
15832 CompileRun("throw 'first exception';"); 15885 CompileRun("throw 'first exception';");
15833 } 15886 }
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698