Author: [email protected]
Date: Wed Jun 24 04:52:52 2009
New Revision: 2260

Modified:
    branches/bleeding_edge/include/v8.h
    branches/bleeding_edge/src/api.cc

Log:
A helper function to speed up creation of V8 wrappers for DOM Nodes.

Review URL: http://codereview.chromium.org/141044

Modified: branches/bleeding_edge/include/v8.h
==============================================================================
--- branches/bleeding_edge/include/v8.h (original)
+++ branches/bleeding_edge/include/v8.h Wed Jun 24 04:52:52 2009
@@ -1176,6 +1176,12 @@
   public:
    uint32_t Length() const;

+  /**
+   * Clones an element at index |index|.  Returns an empty
+   * handle if cloning fails (for any reason).
+   */
+  Local<Object> CloneElementAt(uint32_t index);
+
    static Local<Array> New(int length = 0);
    static Array* Cast(Value* obj);
   private:

Modified: branches/bleeding_edge/src/api.cc
==============================================================================
--- branches/bleeding_edge/src/api.cc   (original)
+++ branches/bleeding_edge/src/api.cc   Wed Jun 24 04:52:52 2009
@@ -3012,6 +3012,26 @@
  }


+Local<Object> Array::CloneElementAt(uint32_t index) {
+  ON_BAILOUT("v8::Array::CloneElementAt()", return Local<Object>());
+  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
+  if (!self->HasFastElements()) {
+    return Local<Object>();
+  }
+  i::FixedArray* elms = self->elements();
+  i::Object* paragon = elms->get(index);
+  if (!paragon->IsJSObject()) {
+    return Local<Object>();
+  }
+  i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
+  EXCEPTION_PREAMBLE();
+  i::Handle<i::JSObject> result = i::Copy(paragon_handle);
+  has_pending_exception = result.is_null();
+  EXCEPTION_BAILOUT_CHECK(Local<Object>());
+  return Utils::ToLocal(result);
+}
+
+
  Local<String> v8::String::NewSymbol(const char* data, int length) {
    EnsureInitialized("v8::String::NewSymbol()");
    LOG_API("String::NewSymbol(char)");

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

Reply via email to