| 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..c8f8cd9e6f39ec9b9eb31984fb4250d1a0214ead
|
| --- /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_
|
| +#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;
|
| +}
|
| +
|
| +} // namespace js
|
| +} // namespace mojo
|
| +
|
| +#endif // MOJO_PUBLIC_BINDINGS_JS_V8_CONVERSIONS_H_
|
|
|