Index: test/cctest/test-api.cc |
=================================================================== |
--- test/cctest/test-api.cc (revision 4011) |
+++ test/cctest/test-api.cc (working copy) |
@@ -9911,3 +9911,47 @@ |
CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); |
} |
} |
+ |
+ |
+TEST(Bug618) { |
+ const char* source = "function C1() {" |
+ " this.x = 23;" |
+ "};" |
+ "C1.prototype = P;"; |
+ |
+ v8::HandleScope scope; |
+ LocalContext context; |
+ v8::Local<v8::Script> script; |
+ |
+ // Use a simple object as prototype. |
+ v8::Local<v8::Object> prototype = v8::Object::New(); |
+ prototype->Set(v8_str("y"), v8_num(42)); |
+ context->Global()->Set(v8_str("P"), prototype); |
+ |
+ // This compile will add the code to the compilation cache. |
+ CompileRun(source); |
+ |
+ script = v8::Script::Compile(v8_str("new C1();")); |
+ for (int i = 0; i < 10; i++) { |
+ v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
+ CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
+ CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
+ } |
+ |
+ // Use an API object with accessors as prototype. |
+ Local<ObjectTemplate> templ = ObjectTemplate::New(); |
+ templ->SetAccessor(v8_str("x"), |
+ GetterWhichReturns42, |
+ SetterWhichSetsYOnThisTo23); |
+ context->Global()->Set(v8_str("P"), templ->NewInstance()); |
+ |
+ // This compile will get the code from the compilation cache. |
+ CompileRun(source); |
+ |
+ script = v8::Script::Compile(v8_str("new C1();")); |
+ for (int i = 0; i < 10; i++) { |
+ v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
+ CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
+ CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
+ } |
+} |