Chromium Code Reviews| Index: mojo/public/bindings/js/v8_wrapper.cc |
| diff --git a/mojo/public/bindings/js/v8_wrapper.cc b/mojo/public/bindings/js/v8_wrapper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f39f714380422cb7f0817887c812670a9de03ee2 |
| --- /dev/null |
| +++ b/mojo/public/bindings/js/v8_wrapper.cc |
| @@ -0,0 +1,50 @@ |
| +// 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. |
| + |
| +#include "mojo/public/bindings/js/v8_wrapper.h" |
| + |
| +namespace mojo { |
| +namespace js { |
| + |
| +WrapperInfo* WrapperInfo::From(v8::Handle<v8::Object> object) { |
| + if (object->InternalFieldCount() != kNumberOfInternalFields) |
| + return NULL; |
| + return static_cast<WrapperInfo*>( |
| + object->GetAlignedPointerFromInternalField(kWrapperInfoIndex)); |
| +} |
| + |
| +// Wrapper<int32_t> ----------------------------------------------------------- |
| + |
| +v8::Handle<v8::Value> Wrapper<int32_t>::ToObject(v8::Isolate* isolate, |
| + int32_t native) { |
| + return v8::Integer::New(native); |
| +} |
| + |
| +int32_t Wrapper<int32_t>::ToNative(v8::Handle<v8::Value> value) { |
| + return value->Int32Value(); |
|
Aaron Boodman
2013/11/09 08:26:02
You probably want some way for this method to indi
abarth-chromium
2013/11/09 08:52:37
As written, the conversion can't really fail. If
Aaron Boodman
2013/11/09 21:12:12
For number it can't fail, but for, e.g., mojo::Han
|
| +} |
| + |
| +// Wrapper<uint32_t> ---------------------------------------------------------- |
| + |
| +v8::Handle<v8::Value> Wrapper<uint32_t>::ToObject(v8::Isolate* isolate, |
| + uint32_t native) { |
| + return v8::Integer::NewFromUnsigned(native); |
| +} |
| + |
| +uint32_t Wrapper<uint32_t>::ToNative(v8::Handle<v8::Value> value) { |
| + return value->Uint32Value(); |
| +} |
| + |
| +// Wrapper<uint64_t> ---------------------------------------------------------- |
| + |
| +v8::Handle<v8::Value> Wrapper<uint64_t>::ToObject(v8::Isolate* isolate, |
| + uint64_t native) { |
| + return v8::Integer::NewFromUnsigned(native); |
| +} |
| + |
| +uint64_t Wrapper<uint64_t>::ToNative(v8::Handle<v8::Value> value) { |
| + return value->IntegerValue(); |
| +} |
| +} // namespace js |
| +} // mojo |