LGTM.

On Wed, Mar 18, 2009 at 10:19 AM,  <[email protected]> wrote:
> Reviewers: Kasper Lund,
>
> Description:
> Expose Cloning through API.
>
>
>
> Please review this at http://codereview.chromium.org/42339
>
> SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
>
> Affected files:
>  M     include/v8.h
>  M     src/api.cc
>  M     test/cctest/test-api.cc
>
>
> 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")));
> +}
> +
> Index: include/v8.h
> ===================================================================
> --- include/v8.h        (revision 1525)
> +++ include/v8.h        (working copy)
> @@ -1076,6 +1076,12 @@
>    */
>   void TurnOnAccessCheck();
>
> +  /**
> +   * Clone this object with a fast but shallow copy.  Values will point
> +   * to the same values as the original object.
> +   */
> +  Local<Object> Clone();
> +
>   static Local<Object> New();
>   static Object* Cast(Value* obj);
>  private:
> Index: src/api.cc
> ===================================================================
> --- src/api.cc  (revision 1525)
> +++ src/api.cc  (working copy)
> @@ -1919,6 +1919,17 @@
>  }
>
>
> +Local<v8::Object> v8::Object::Clone() {
> +  ON_BAILOUT("v8::Object::Clone()", return Local<Object>());
> +  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
> +  EXCEPTION_PREAMBLE();
> +  i::Handle<i::JSObject> result = i::Copy(self);
> +  has_pending_exception = result.is_null();
> +  EXCEPTION_BAILOUT_CHECK(Local<Object>());
> +  return Utils::ToLocal(result);
> +}
> +
> +
>  Local<v8::Object> Function::NewInstance() const {
>   return NewInstance(0, NULL);
>  }
>
>
>

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to