| 565 | const Weak<SharedPtrRefCountable>& listenerOwner) { |
| 566 | std::lock_guard<Mutex> guard(_listenerMutex); |
| 567 | _listener = listener; |
| 568 | _listenerOwner = listenerOwner; |
| 569 | } |
| 570 | |
| 571 | JavaScriptRuntime::RetainedListener JavaScriptRuntime::getListener() const { |
| 572 | std::lock_guard<Mutex> guard(_listenerMutex); |
| 573 | if (_listener == nullptr) { |
| 574 | return {}; |
| 575 | } |
| 576 | auto owner = _listenerOwner.lock(); |
| 577 | if (owner == nullptr) { |
| 578 | return {}; |
| 579 | } |
| 580 | return {_listener, std::move(owner)}; |
| 581 | } |
| 582 | |
| 583 | void JavaScriptRuntime::bindRuntimeFunction(IJavaScriptContext& jsContext, |
| 584 | JSExceptionTracker& exceptionTracker, |
| 585 | const JSValueRef& jsObject, |
| 586 | const char* functionName, |
| 587 | JSValueRef (JavaScriptRuntime::*function)(JSFunctionNativeCallContext&)) { |
| 588 | auto functionNameStr = STRING_LITERAL(functionName); |
| 589 | auto objectName = STRING_LITERAL("runtime"); |
| 590 | auto callable = makeShared<JavaScriptRuntimeCallable>( |
| 591 | *this, |
| 592 | function, |
| 593 | ReferenceInfoBuilder().withObject(objectName).withProperty(functionNameStr).asFunction().build()); |
| 594 | |
| 595 | auto jsFunction = jsContext.newFunction(callable, exceptionTracker); |
| 596 | if (!exceptionTracker) { |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | jsContext.setObjectProperty( |
| 601 | jsObject.get(), functionNameStr.toStringView(), jsFunction.get(), true, exceptionTracker); |
| 602 | if (!exceptionTracker) { |
| 603 | return; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | Result<Void> JavaScriptRuntime::initializeContext() { |
| 608 | VALDI_TRACE("Valdi.createJsContext"); |
| 609 | Ref<ValdiRuntimeTweaks> runtimeTweaks; |
| 610 | if (auto listener = getListener()) { |
| 611 | runtimeTweaks = listener->getRuntimeTweaks(); |
| 612 | } |
| 613 | |
| 614 | if (runtimeTweaks != nullptr) { |
| 615 | Context::setDestroyedContextFixEnabled(runtimeTweaks->enableRenderRequestContextFix()); |
| 616 | MainThreadManager::setPreRasterFenceDisabled(runtimeTweaks->disablePreRasterFence()); |
| 617 | ValueFunctionWithJSValue::setDeadlineCircuitBreakerDisabled(runtimeTweaks->disableSyncDeadlineCircuitBreaker()); |
| 618 | } |
| 619 | |
| 620 | VALDI_INFO(*_logger, "Creating JSContext from engine '{}'", _javaScriptBridge.getName()); |
| 621 | |
| 622 | auto jsContext = _javaScriptBridge.createJsContext(this, *_logger); |
nothing calls this directly
no test coverage detected