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

Unified Diff: test/cctest/test-api.cc

Issue 668055: Added tests for issue 618 (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 10 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 side-by-side diff with in-line comments
Download patch
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());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698