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

Method buildContext

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

Source from the content-addressed store, hash-verified

2219JSValueRef JavaScriptRuntime::queueMicrotask(JSFunctionNativeCallContext& callContext) {
2220 callContext.getContext().enqueueMicrotask(callContext.getParameter(0), callContext.getExceptionTracker());
2221 return callContext.getContext().newUndefined();
2222}
2223
2224JSValueRef JavaScriptRuntime::performanceNow(JSFunctionNativeCallContext& callContext) {
2225 return callContext.getContext().newNumber(_upTime.elapsed().milliseconds());
2226}
2227
2228template<typename T>
2229Ref<T> thisFromCallContext(JSFunctionNativeCallContext& callContext) {
2230 auto val =
2231 callContext.getContext().valueToWrappedObject(callContext.getThisValue(), callContext.getExceptionTracker());
2232 return castOrNull<T>(val);
2233}
2234
2235// worker.onmessage = func
2236JSValueRef JavaScriptRuntime::workerSetOnMessage(JSFunctionNativeCallContext& callContext) {
2237 auto worker = thisFromCallContext<JavaScriptWorker>(callContext);
2238 if (worker != nullptr) {
2239 worker->setHostOnMessage(callContext.getParameterAsFunction(0));
2240 CHECK_CALL_CONTEXT(callContext);
2241 }
2242 return callContext.getContext().newUndefined();
2243}
2244
2245// worker.postMessage(any)
2246JSValueRef JavaScriptRuntime::workerPostMessage(JSFunctionNativeCallContext& callContext) {
2247 auto worker = thisFromCallContext<JavaScriptWorker>(callContext);
2248 if (worker != nullptr) {
2249 worker->postMessage(callContext.getParameterAsValue(0));
2250 CHECK_CALL_CONTEXT(callContext);
2251 }
2252 return callContext.getContext().newUndefined();
2253}
2254
2255// worker.terminate()
2256JSValueRef JavaScriptRuntime::workerTerminate(JSFunctionNativeCallContext& callContext) {
2257 auto worker = thisFromCallContext<JavaScriptWorker>(callContext);
2258 if (worker != nullptr) {
2259 worker->close();
2260 }
2261 return callContext.getContext().newUndefined();
2262}
2263
2264constexpr static std::string_view getBuildType() {
2265 if (snap::kIsDevBuild) {
2266 return "dev";
2267 }
2268
2269 if (snap::kIsGoldBuild) {
2270 return "gold";
2271 }
2272
2273 if (snap::kIsAlphaBuild) {
2274 return "alpha";
2275 }
2276
2277 if (snap::kIsAppstoreBuild) {
2278 return "prod";

Callers

nothing calls this directly

Calls 15

shouldEnableJsHeapDumpFunction · 0.85
valueToJSValueFunction · 0.85
newNumberMethod · 0.80
disableJsLoggingMethod · 0.80
useTopDownMoveOrderMethod · 0.80
getTimeMethod · 0.80
withObjectMethod · 0.80
getBuildTypeFunction · 0.70
setListenerMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected