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

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

Issue 42339: Expose Cloning through API. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 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
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
===================================================================
--- test/cctest/test-api.cc (revision 1525)
+++ test/cctest/test-api.cc (working copy)
@@ -5803,3 +5803,38 @@
local_env->Exit();
}
+
+
+// Verify that we can clone an object
+TEST(ObjectClone) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ char* sample =
+ "var rv = {};" \
+ "rv.alpha = 'hello';" \
+ "rv.beta = 123;" \
+ "rv;";
+
+ // Create an object, verify basics.
+ Local<Value> val = CompileRun(sample);
+ CHECK(val->IsObject());
+ Local<v8::Object> obj = Local<v8::Object>::Cast(val);
+ obj->Set(v8_str("gamma"), v8_str("cloneme"));
+
+ CHECK_EQ(v8_str("hello"), obj->Get(v8_str("alpha")));
+ CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta")));
+ CHECK_EQ(v8_str("cloneme"), obj->Get(v8_str("gamma")));
+
+ // Clone it.
+ Local<v8::Object> clone = obj->Clone();
+ CHECK_EQ(v8_str("hello"), clone->Get(v8_str("alpha")));
+ CHECK_EQ(v8::Integer::New(123), clone->Get(v8_str("beta")));
+ CHECK_EQ(v8_str("cloneme"), clone->Get(v8_str("gamma")));
+
+ // Set a property on the clone, verify each object.
+ clone->Set(v8_str("beta"), v8::Integer::New(456));
+ CHECK_EQ(v8::Integer::New(123), obj->Get(v8_str("beta")));
+ CHECK_EQ(v8::Integer::New(456), clone->Get(v8_str("beta")));
+}
+
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698