MCPcopy Create free account
hub / github.com/Tracktion/choc / registerFunction

Method registerFunction

choc/javascript/choc_javascript_V8.h:256–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254 }
255
256 void registerFunction (const std::string& name, Context::NativeFunction fn) override
257 {
258 v8::Isolate::Scope isolateScope (isolate);
259 v8::HandleScope handleScope (isolate);
260 auto localContext = context.Get (isolate);
261 v8::Context::Scope contextScope (localContext);
262
263 ++nextNativeFunctionHandle;
264 nativeFunctions[nextNativeFunctionHandle] = std::move (fn);
265
266 auto global = localContext->Global();
267 auto ft = v8::FunctionTemplate::New (isolate, staticCallback, v8::Int32::New (isolate, nextNativeFunctionHandle));
268 (void) global->Set (localContext, stringToV8 (name), ft->GetFunction (localContext).ToLocalChecked());
269 }
270
271 static void staticCallback (const v8::FunctionCallbackInfo<v8::Value>& info)
272 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected