MCPcopy Create free account
hub / github.com/Snapchat/Valdi / runtimePostMessage

Method runtimePostMessage

valdi/src/valdi/runtime/JavaScript/JavaScriptRuntime.cpp:567–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565 const Weak<SharedPtrRefCountable>& listenerOwner) {
566 std::lock_guard<Mutex> guard(_listenerMutex);
567 _listener = listener;
568 _listenerOwner = listenerOwner;
569}
570
571JavaScriptRuntime::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
583void 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
607Result<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);

Callers

nothing calls this directly

Calls 15

getParameterAsContextIdFunction · 0.85
dispatchOnMainThreadFunction · 0.85
valueTypeToStringFunction · 0.85
getParameterAsValueMethod · 0.80
getArrayRefMethod · 0.80
newUndefinedMethod · 0.80
getMapMethod · 0.65
throwErrorMethod · 0.65
endMethod · 0.65
ErrorInterface · 0.50
getParameterAsStringMethod · 0.45

Tested by

no test coverage detected