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/converter.h" | 5 #include "gin/converter.h" |
6 | 6 |
7 #include "v8/include/v8.h" | 7 #include "v8/include/v8.h" |
8 | 8 |
9 using v8::Boolean; | 9 using v8::Boolean; |
| 10 using v8::External; |
10 using v8::Function; | 11 using v8::Function; |
11 using v8::Handle; | 12 using v8::Handle; |
12 using v8::Integer; | 13 using v8::Integer; |
13 using v8::Isolate; | 14 using v8::Isolate; |
14 using v8::Number; | 15 using v8::Number; |
15 using v8::Object; | 16 using v8::Object; |
16 using v8::String; | 17 using v8::String; |
17 using v8::Value; | 18 using v8::Value; |
18 | 19 |
19 namespace gin { | 20 namespace gin { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 118 } |
118 | 119 |
119 bool Converter<Handle<Object> >::FromV8(Handle<Value> val, | 120 bool Converter<Handle<Object> >::FromV8(Handle<Value> val, |
120 Handle<Object>* out) { | 121 Handle<Object>* out) { |
121 if (!val->IsObject()) | 122 if (!val->IsObject()) |
122 return false; | 123 return false; |
123 *out = Handle<Object>::Cast(val); | 124 *out = Handle<Object>::Cast(val); |
124 return true; | 125 return true; |
125 } | 126 } |
126 | 127 |
| 128 Handle<Value> Converter<Handle<External> >::ToV8(v8::Isolate* isolate, |
| 129 Handle<External> val) { |
| 130 return val.As<Value>(); |
| 131 } |
| 132 |
| 133 bool Converter<Handle<External> >::FromV8(Handle<Value> val, |
| 134 Handle<External>* out) { |
| 135 if (!val->IsExternal()) |
| 136 return false; |
| 137 *out = Handle<External>::Cast(val); |
| 138 return true; |
| 139 } |
| 140 |
| 141 Handle<Value> Converter<Handle<Value> >::ToV8(v8::Isolate* isolate, |
| 142 Handle<Value> val) { |
| 143 return val; |
| 144 } |
| 145 |
| 146 bool Converter<Handle<Value> >::FromV8(Handle<Value> val, |
| 147 Handle<Value>* out) { |
| 148 *out = val; |
| 149 return true; |
| 150 } |
| 151 |
127 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, | 152 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, |
128 const std::string& val) { | 153 const std::string& val) { |
129 return String::NewFromUtf8(isolate, | 154 return String::NewFromUtf8(isolate, |
130 val.data(), | 155 val.data(), |
131 String::kInternalizedString, | 156 String::kInternalizedString, |
132 static_cast<uint32_t>(val.length())); | 157 static_cast<uint32_t>(val.length())); |
133 } | 158 } |
134 | 159 |
135 | 160 |
136 } // namespace gin | 161 } // namespace gin |
OLD | NEW |