| 274 | } |
| 275 | |
| 276 | void callback (const v8::FunctionCallbackInfo<v8::Value>& info) |
| 277 | { |
| 278 | v8::HandleScope handleScope (isolate); |
| 279 | auto localContext = context.Get (isolate); |
| 280 | v8::Context::Scope contextScope (localContext); |
| 281 | auto data = info.Data()->Int32Value (localContext); |
| 282 | |
| 283 | if (data.IsJust()) |
| 284 | { |
| 285 | if (auto fn = nativeFunctions.find (data.ToChecked()); fn != nativeFunctions.end()) |
| 286 | { |
| 287 | auto numArgs = info.Length(); |
| 288 | std::vector<choc::value::Value> args; |
| 289 | args.reserve (static_cast<size_t> (numArgs)); |
| 290 | |
| 291 | for (int i = 0; i < numArgs; ++i) |
| 292 | args.emplace_back (v8ToChoc (localContext, info[i])); |
| 293 | |
| 294 | auto result = fn->second (ArgumentList { args.data(), args.size() }); |
| 295 | |
| 296 | if (! result.isVoid()) |
| 297 | info.GetReturnValue().Set (chocToV8 (localContext, result)); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | choc::value::Value v8ToChoc (v8::Local<v8::Context> c, const v8::Local<v8::Value>& value) |
| 303 | { |