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"))); |
+} |
+ |