| 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 | { |
no test coverage detected