MCPcopy Create free account
hub / github.com/Tencent/puerts / CreateJSFunction

Method CreateJSFunction

unity/native_src/Src/JSEngine.cpp:380–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378 }
379
380 JSFunction* JSEngine::CreateJSFunction(v8::Isolate* InIsolate, v8::Local<v8::Context> InContext, v8::Local<v8::Function> InFunction)
381 {
382 std::lock_guard<std::mutex> guard(JSFunctionsMutex);
383 auto maybeId = InFunction->Get(InContext, FV8Utils::V8String(InIsolate, FUNCTION_INDEX_KEY));
384 if (!maybeId.IsEmpty()) {
385 auto id = maybeId.ToLocalChecked();
386 if (id->IsNumber()) {
387 int32_t index = id->Int32Value(InContext).ToChecked();
388 return JSFunctions[index];
389 }
390 }
391 JSFunction* Function = nullptr;
392 for (int i = 0; i < JSFunctions.size(); i++) {
393 if (!JSFunctions[i]) {
394 Function = new JSFunction(InIsolate, InContext, InFunction, i);
395 JSFunctions[i] = Function;
396 break;
397 }
398 }
399 if (!Function) {
400 Function = new JSFunction(InIsolate, InContext, InFunction, static_cast<int32_t>(JSFunctions.size()));
401 JSFunctions.push_back(Function);
402 }
403 InFunction->Set(InContext, FV8Utils::V8String(InIsolate, FUNCTION_INDEX_KEY), v8::Integer::New(InIsolate, Function->Index));
404 return Function;
405 }
406
407 void JSEngine::ReleaseJSFunction(JSFunction* InFunction)
408 {

Callers 2

GetFunctionFromValueFunction · 0.80
GetFunctionFromResultFunction · 0.80

Calls 9

NewFunction · 0.85
IsNumberMethod · 0.80
GetMethod · 0.45
IsEmptyMethod · 0.45
ToLocalCheckedMethod · 0.45
ToCheckedMethod · 0.45
Int32ValueMethod · 0.45
sizeMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected