OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gin/wrappable.h" | 5 #include "gin/wrappable.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "gin/per_isolate_data.h" | 8 #include "gin/per_isolate_data.h" |
9 | 9 |
10 namespace gin { | 10 namespace gin { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return wrapper; | 44 return wrapper; |
45 } | 45 } |
46 | 46 |
47 v8::Handle<v8::Value> Converter<Wrappable*>::ToV8(v8::Isolate* isolate, | 47 v8::Handle<v8::Value> Converter<Wrappable*>::ToV8(v8::Isolate* isolate, |
48 Wrappable* val) { | 48 Wrappable* val) { |
49 if (val->wrapper_.IsEmpty()) | 49 if (val->wrapper_.IsEmpty()) |
50 return val->CreateWrapper(isolate); | 50 return val->CreateWrapper(isolate); |
51 return v8::Local<v8::Object>::New(isolate, val->wrapper_); | 51 return v8::Local<v8::Object>::New(isolate, val->wrapper_); |
52 } | 52 } |
53 | 53 |
54 bool Converter<Wrappable*>::FromV8(v8::Handle<v8::Value> val, | 54 bool Converter<Wrappable*>::FromV8(v8::Isolate* isolate, |
55 Wrappable** out) { | 55 v8::Handle<v8::Value> val, Wrappable** out) { |
56 if (!val->IsObject()) | 56 if (!val->IsObject()) |
57 return false; | 57 return false; |
58 v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(val); | 58 v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(val); |
59 WrapperInfo* info = WrapperInfo::From(obj); | 59 WrapperInfo* info = WrapperInfo::From(obj); |
60 if (!info) | 60 if (!info) |
61 return false; | 61 return false; |
62 void* pointer = obj->GetAlignedPointerFromInternalField(kEncodedValueIndex); | 62 void* pointer = obj->GetAlignedPointerFromInternalField(kEncodedValueIndex); |
63 Wrappable* wrappable = static_cast<Wrappable*>(pointer); | 63 Wrappable* wrappable = static_cast<Wrappable*>(pointer); |
64 CHECK(wrappable->GetWrapperInfo() == info); // Security check for cast above. | 64 CHECK(wrappable->GetWrapperInfo() == info); // Security check for cast above. |
65 *out = wrappable; | 65 *out = wrappable; |
66 return true; | 66 return true; |
67 } | 67 } |
68 | 68 |
69 } // namespace gin | 69 } // namespace gin |
OLD | NEW |