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

Unified Diff: mojo/public/bindings/js/v8_conversions.h

Issue 59153005: Begin implementing V8 bindings for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: spelling Created 7 years, 1 month 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: mojo/public/bindings/js/v8_conversions.h
diff --git a/mojo/public/bindings/js/v8_conversions.h b/mojo/public/bindings/js/v8_conversions.h
new file mode 100644
index 0000000000000000000000000000000000000000..232fdddc66dcbbc17e49d41bdf170dc4739d7962
--- /dev/null
+++ b/mojo/public/bindings/js/v8_conversions.h
@@ -0,0 +1,45 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_BINDINGS_JS_V8_CONVERSIONS_H_
Aaron Boodman 2013/11/09 08:26:02 I don't understand why this isn't just another Wra
abarth-chromium 2013/11/09 08:52:37 I'll take a closer look.
+#define MOJO_PUBLIC_BINDINGS_JS_V8_CONVERSIONS_H_
+
+#include <vector>
+
+#include "v8/include/v8.h"
+
+namespace mojo {
+namespace js {
+
+template<typename T>
+bool ToNativeArray(v8::Handle<v8::Array> array, std::vector<T>* result) {
+ uint32_t length = array->Length();
+ result->reserve(length);
+ for (uint32_t i = 0; i < length; ++i) {
+ v8::Handle<v8::Value> value = array->Get(i);
+ if (!value->IsObject())
+ return false;
+ v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
+ if (!Wrapper<T>::HasInstance(object))
+ return false;
+ result->push_back(Wrapper<T>::ToNative(object));
+ }
+ return true;
+}
+
+template<typename T>
+v8::Handle<v8::Array> ToObjectArray(v8::Isolate* isolate,
+ const std::vector<T>& native) {
+ uint32_t length = native.size();
+ v8::Handle<v8::Array> result = v8::Array::New(length);
+ for (uint32_t i = 0; i < length; ++i) {
+ result->Set(i, Wrapper<T>::ToObject(isolate, native[i]));
+ }
+ return result;
+}
+
+} // js
+} // mojo
+
+#endif // MOJO_PUBLIC_BINDINGS_JS_V8_CONVERSIONS_H_

Powered by Google App Engine
This is Rietveld 408576698