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