[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef GIN_CONVERTER_H_ |
| 6 | #define GIN_CONVERTER_H_ |
| 7 | |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 10 | #include <string> |
Jeremy Roman | eb8a2f17 | 2018-01-29 17:33:40 | [diff] [blame] | 11 | #include <type_traits> |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 14 | #include "base/logging.h" |
Shimi Zhang | 15708bfc | 2019-08-13 19:24:48 | [diff] [blame^] | 15 | #include "base/strings/string16.h" |
[email protected] | b520e13 | 2013-11-29 03:21:48 | [diff] [blame] | 16 | #include "base/strings/string_piece.h" |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 17 | #include "gin/gin_export.h" |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 18 | #include "v8/include/v8.h" |
| 19 | |
| 20 | namespace gin { |
| 21 | |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 22 | template<typename KeyType> |
| 23 | bool SetProperty(v8::Isolate* isolate, |
| 24 | v8::Local<v8::Object> object, |
| 25 | KeyType key, |
| 26 | v8::Local<v8::Value> value) { |
rdevlin.cronin | 415b73b | 2015-11-13 01:14:47 | [diff] [blame] | 27 | auto maybe = |
| 28 | object->DefineOwnProperty(isolate->GetCurrentContext(), key, value); |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 29 | return !maybe.IsNothing() && maybe.FromJust(); |
| 30 | } |
| 31 | |
Ken Rockot | 2b0f0765 | 2017-04-12 19:10:49 | [diff] [blame] | 32 | template <typename T, typename Enable = void> |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 33 | struct ToV8ReturnsMaybe { |
| 34 | static const bool value = false; |
| 35 | }; |
| 36 | |
[email protected] | cf76c84a | 2013-12-06 14:07:07 | [diff] [blame] | 37 | template<typename T, typename Enable = void> |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 38 | struct Converter {}; |
| 39 | |
| 40 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 41 | struct GIN_EXPORT Converter<bool> { |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 42 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 43 | bool val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 44 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 45 | v8::Local<v8::Value> val, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 46 | bool* out); |
| 47 | }; |
| 48 | |
| 49 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 50 | struct GIN_EXPORT Converter<int32_t> { |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 51 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 52 | int32_t val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 53 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 54 | v8::Local<v8::Value> val, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 55 | int32_t* out); |
| 56 | }; |
| 57 | |
| 58 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 59 | struct GIN_EXPORT Converter<uint32_t> { |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 60 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 61 | uint32_t val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 62 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 63 | v8::Local<v8::Value> val, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 64 | uint32_t* out); |
| 65 | }; |
| 66 | |
| 67 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 68 | struct GIN_EXPORT Converter<int64_t> { |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 69 | // Warning: JavaScript cannot represent 64 integers precisely. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 70 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 71 | int64_t val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 72 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 73 | v8::Local<v8::Value> val, |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 74 | int64_t* out); |
| 75 | }; |
| 76 | |
| 77 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 78 | struct GIN_EXPORT Converter<uint64_t> { |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 79 | // Warning: JavaScript cannot represent 64 integers precisely. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 80 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 81 | uint64_t val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 82 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 83 | v8::Local<v8::Value> val, |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 84 | uint64_t* out); |
| 85 | }; |
| 86 | |
| 87 | template<> |
[email protected] | d73341d1 | 2013-12-21 00:48:46 | [diff] [blame] | 88 | struct GIN_EXPORT Converter<float> { |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 89 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | d73341d1 | 2013-12-21 00:48:46 | [diff] [blame] | 90 | float val); |
| 91 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 92 | v8::Local<v8::Value> val, |
[email protected] | d73341d1 | 2013-12-21 00:48:46 | [diff] [blame] | 93 | float* out); |
| 94 | }; |
| 95 | |
| 96 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 97 | struct GIN_EXPORT Converter<double> { |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 98 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 99 | double val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 100 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 101 | v8::Local<v8::Value> val, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 102 | double* out); |
| 103 | }; |
| 104 | |
| 105 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 106 | struct GIN_EXPORT Converter<base::StringPiece> { |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 107 | // This crashes when val.size() > v8::String::kMaxLength. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 108 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | b520e13 | 2013-11-29 03:21:48 | [diff] [blame] | 109 | const base::StringPiece& val); |
| 110 | // No conversion out is possible because StringPiece does not contain storage. |
| 111 | }; |
| 112 | |
| 113 | template<> |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 114 | struct GIN_EXPORT Converter<std::string> { |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 115 | // This crashes when val.size() > v8::String::kMaxLength. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 116 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 117 | const std::string& val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 118 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 119 | v8::Local<v8::Value> val, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 120 | std::string* out); |
| 121 | }; |
| 122 | |
Shimi Zhang | 15708bfc | 2019-08-13 19:24:48 | [diff] [blame^] | 123 | template <> |
| 124 | struct GIN_EXPORT Converter<base::string16> { |
| 125 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 126 | const base::string16& val); |
| 127 | static bool FromV8(v8::Isolate* isolate, |
| 128 | v8::Local<v8::Value> val, |
| 129 | base::string16* out); |
| 130 | }; |
| 131 | |
| 132 | template <> |
| 133 | struct GIN_EXPORT Converter<v8::Local<v8::Function>> { |
Nitish Sakhawalkar | f7bbaa52 | 2019-02-11 16:19:09 | [diff] [blame] | 134 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 135 | v8::Local<v8::Function> val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 136 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 137 | v8::Local<v8::Value> val, |
| 138 | v8::Local<v8::Function>* out); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | template<> |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 142 | struct GIN_EXPORT Converter<v8::Local<v8::Object> > { |
| 143 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 144 | v8::Local<v8::Object> val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 145 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 146 | v8::Local<v8::Value> val, |
| 147 | v8::Local<v8::Object>* out); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 148 | }; |
| 149 | |
Scott Graham | d2f4ed4b | 2018-10-17 01:57:27 | [diff] [blame] | 150 | template <> |
| 151 | struct GIN_EXPORT Converter<v8::Local<v8::Promise>> { |
| 152 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 153 | v8::Local<v8::Promise> val); |
| 154 | static bool FromV8(v8::Isolate* isolate, |
| 155 | v8::Local<v8::Value> val, |
| 156 | v8::Local<v8::Promise>* out); |
| 157 | }; |
| 158 | |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 159 | template<> |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 160 | struct GIN_EXPORT Converter<v8::Local<v8::ArrayBuffer> > { |
| 161 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 162 | v8::Local<v8::ArrayBuffer> val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 163 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 164 | v8::Local<v8::Value> val, |
| 165 | v8::Local<v8::ArrayBuffer>* out); |
[email protected] | ec95fdf | 2013-11-24 19:10:11 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | template<> |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 169 | struct GIN_EXPORT Converter<v8::Local<v8::External> > { |
| 170 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 171 | v8::Local<v8::External> val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 172 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 173 | v8::Local<v8::Value> val, |
| 174 | v8::Local<v8::External>* out); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | template<> |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 178 | struct GIN_EXPORT Converter<v8::Local<v8::Value> > { |
| 179 | static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 180 | v8::Local<v8::Value> val); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 181 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 182 | v8::Local<v8::Value> val, |
| 183 | v8::Local<v8::Value>* out); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 184 | }; |
| 185 | |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 186 | template<typename T> |
| 187 | struct Converter<std::vector<T> > { |
Jeremy Roman | eb8a2f17 | 2018-01-29 17:33:40 | [diff] [blame] | 188 | static std::conditional_t<ToV8ReturnsMaybe<T>::value, |
| 189 | v8::MaybeLocal<v8::Value>, |
| 190 | v8::Local<v8::Value>> |
| 191 | ToV8(v8::Isolate* isolate, const std::vector<T>& val) { |
| 192 | v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 193 | v8::Local<v8::Array> result( |
[email protected] | 91cd4fe | 2013-11-28 09:31:58 | [diff] [blame] | 194 | v8::Array::New(isolate, static_cast<int>(val.size()))); |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 195 | for (uint32_t i = 0; i < val.size(); ++i) { |
Jeremy Roman | eb8a2f17 | 2018-01-29 17:33:40 | [diff] [blame] | 196 | v8::MaybeLocal<v8::Value> maybe = Converter<T>::ToV8(isolate, val[i]); |
| 197 | v8::Local<v8::Value> element; |
| 198 | if (!maybe.ToLocal(&element)) |
| 199 | return {}; |
| 200 | bool property_created; |
| 201 | if (!result->CreateDataProperty(context, i, element) |
| 202 | .To(&property_created) || |
| 203 | !property_created) { |
| 204 | NOTREACHED() << "CreateDataProperty should always succeed here."; |
| 205 | } |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 206 | } |
| 207 | return result; |
| 208 | } |
| 209 | |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 210 | static bool FromV8(v8::Isolate* isolate, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 211 | v8::Local<v8::Value> val, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 212 | std::vector<T>* out) { |
| 213 | if (!val->IsArray()) |
| 214 | return false; |
| 215 | |
| 216 | std::vector<T> result; |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 217 | v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val)); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 218 | uint32_t length = array->Length(); |
| 219 | for (uint32_t i = 0; i < length; ++i) { |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 220 | v8::Local<v8::Value> v8_item; |
| 221 | if (!array->Get(isolate->GetCurrentContext(), i).ToLocal(&v8_item)) |
| 222 | return false; |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 223 | T item; |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 224 | if (!Converter<T>::FromV8(isolate, v8_item, &item)) |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 225 | return false; |
| 226 | result.push_back(item); |
| 227 | } |
| 228 | |
| 229 | out->swap(result); |
| 230 | return true; |
| 231 | } |
| 232 | }; |
| 233 | |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 234 | template<typename T> |
| 235 | struct ToV8ReturnsMaybe<std::vector<T>> { |
Jeremy Roman | eb8a2f17 | 2018-01-29 17:33:40 | [diff] [blame] | 236 | static const bool value = ToV8ReturnsMaybe<T>::value; |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 237 | }; |
| 238 | |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 239 | // Convenience functions that deduce T. |
Jeremy Roman | eb8a2f17 | 2018-01-29 17:33:40 | [diff] [blame] | 240 | template <typename T> |
| 241 | std::conditional_t<ToV8ReturnsMaybe<T>::value, |
| 242 | v8::MaybeLocal<v8::Value>, |
| 243 | v8::Local<v8::Value>> |
Jeremy Apthorp | 6a348029 | 2018-04-26 18:53:59 | [diff] [blame] | 244 | ConvertToV8(v8::Isolate* isolate, const T& input) { |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 245 | return Converter<T>::ToV8(isolate, input); |
| 246 | } |
| 247 | |
Jeremy Roman | 44bda444b | 2018-03-16 17:33:45 | [diff] [blame] | 248 | template <typename T> |
Jeremy Apthorp | 6a348029 | 2018-04-26 18:53:59 | [diff] [blame] | 249 | std::enable_if_t<ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8( |
| 250 | v8::Isolate* isolate, |
| 251 | const T& input, |
| 252 | v8::Local<v8::Value>* output) { |
Jeremy Roman | 44bda444b | 2018-03-16 17:33:45 | [diff] [blame] | 253 | return ConvertToV8(isolate, input).ToLocal(output); |
| 254 | } |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 255 | |
| 256 | template <typename T> |
Jeremy Apthorp | 6a348029 | 2018-04-26 18:53:59 | [diff] [blame] | 257 | std::enable_if_t<!ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8( |
| 258 | v8::Isolate* isolate, |
| 259 | const T& input, |
| 260 | v8::Local<v8::Value>* output) { |
Jeremy Roman | 44bda444b | 2018-03-16 17:33:45 | [diff] [blame] | 261 | *output = ConvertToV8(isolate, input); |
| 262 | return true; |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | // This crashes when input.size() > v8::String::kMaxLength. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 266 | GIN_EXPORT inline v8::Local<v8::String> StringToV8( |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 267 | v8::Isolate* isolate, |
| 268 | const base::StringPiece& input) { |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 269 | return ConvertToV8(isolate, input).As<v8::String>(); |
| 270 | } |
| 271 | |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 272 | // This crashes when input.size() > v8::String::kMaxLength. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 273 | GIN_EXPORT v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate, |
[email protected] | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 274 | const base::StringPiece& val); |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 275 | |
Shimi Zhang | 15708bfc | 2019-08-13 19:24:48 | [diff] [blame^] | 276 | // This crashes when input.size() > v8::String::kMaxLength. |
| 277 | GIN_EXPORT v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate, |
| 278 | const base::StringPiece16& val); |
| 279 | |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 280 | template<typename T> |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 281 | bool ConvertFromV8(v8::Isolate* isolate, v8::Local<v8::Value> input, |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 282 | T* result) { |
Dan Elphick | 712beaa | 2018-07-24 17:37:24 | [diff] [blame] | 283 | DCHECK(isolate); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 284 | return Converter<T>::FromV8(isolate, input, result); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 285 | } |
| 286 | |
Dan Elphick | 38a50805 | 2018-07-23 22:19:53 | [diff] [blame] | 287 | GIN_EXPORT std::string V8ToString(v8::Isolate* isolate, |
| 288 | v8::Local<v8::Value> value); |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 289 | |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 290 | } // namespace gin |
| 291 | |
| 292 | #endif // GIN_CONVERTER_H_ |