Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index cc20b6f1036c5df70e1e21b8867c2a4f3166c39a..49df4c1b8be6212b94cb1dc519934a03547abbbe 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -13536,6 +13536,59 @@ THREADED_TEST(GetHeapStatistics) { |
} |
+class VisitorImpl : public v8::ExternalResourceVisitor { |
+ public: |
+ VisitorImpl(TestResource* r1, TestResource* r2) |
+ : resource1_(r1), |
+ resource2_(r2), |
+ found_resource1_(false), |
+ found_resource2_(false) {} |
+ virtual ~VisitorImpl() {} |
+ virtual void VisitExternalString(v8::Handle<v8::String> string) { |
+ if (!string->IsExternal()) { |
+ CHECK(string->IsExternalAscii()); |
+ return; |
+ } |
+ v8::String::ExternalStringResource* resource = |
+ string->GetExternalStringResource(); |
+ CHECK(resource); |
+ if (resource1_ == resource) { |
+ CHECK(!found_resource1_); |
+ found_resource1_ = true; |
+ } |
+ if (resource2_ == resource) { |
+ CHECK(!found_resource2_); |
+ found_resource2_ = true; |
+ } |
+ } |
+ void CheckVisitedResources() { |
+ CHECK(found_resource1_); |
+ CHECK(found_resource2_); |
+ } |
+ |
+ private: |
+ v8::String::ExternalStringResource* resource1_; |
+ v8::String::ExternalStringResource* resource2_; |
+ bool found_resource1_; |
+ bool found_resource2_; |
+}; |
+ |
+TEST(VisitExternalStrings) { |
+ v8::HandleScope scope; |
+ LocalContext env; |
+ const char* string = "Some string"; |
+ uint16_t* two_byte_string = AsciiToTwoByteString(string); |
+ TestResource* resource1 = new TestResource(two_byte_string); |
+ v8::Local<v8::String> string1 = v8::String::NewExternal(resource1); |
+ TestResource* resource2 = new TestResource(two_byte_string); |
+ v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); |
+ |
+ VisitorImpl visitor(resource1, resource2); |
+ v8::V8::VisitExternalResources(&visitor); |
+ visitor.CheckVisitedResources(); |
+} |
+ |
+ |
static double DoubleFromBits(uint64_t value) { |
double target; |
memcpy(&target, &value, sizeof(target)); |
@@ -13797,6 +13850,17 @@ THREADED_TEST(ScriptOrigin) { |
CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); |
} |
+THREADED_TEST(FunctionGetInferredName) { |
+ v8::HandleScope scope; |
+ LocalContext env; |
+ v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
+ v8::Handle<v8::String> script = v8::String::New( |
+ "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); |
+ v8::Script::Compile(script, &origin)->Run(); |
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
+ env->Global()->Get(v8::String::New("f"))); |
+ CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName())); |
+} |
THREADED_TEST(ScriptLineNumber) { |
v8::HandleScope scope; |