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

Method associateWeakReference

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:408–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406 }
407
408 setObjectCallable(fromValdiJSValue(functionObject.get()), callable);
409
410 if (!callable->getReferenceInfo().getName().isEmpty()) {
411 auto value = newStringUTF8(callable->getReferenceInfo().getName().toStringView(), exceptionTracker);
412 if (!exceptionTracker) {
413 return Valdi::JSValueRef();
414 }
415
416 // JS_DefinePropertyValueStr() automatically releases the given value.
417 auto retainedName = JS_DupValue(_context, fromValdiJSValue(value.get()));
418
419 checkCall(exceptionTracker,
420 JS_DefinePropertyValueStr(_context, fromValdiJSValue(functionObject.get()), "name", retainedName, 0));
421
422 if (!exceptionTracker) {
423 return Valdi::JSValueRef();
424 }
425 }
426
427 return functionObject;
428}
429
430size_t QuickJSJavaScriptContext::associateWeakReference(const JSValue& value,
431 Valdi::JSExceptionTracker& exceptionTracker) {
432 auto guard = _threadAccessChecker.guard();
433 auto existingFinalizer =
434 checkCallAndGetValue(exceptionTracker, JS_GetProperty(_context, value, _objectFinalizerAtomKey));
435 if (!exceptionTracker) {
436 return 0;
437 }
438
439 auto weakReferenceId = weakReferenceIdFromJSWeakReferenceFinalizer(fromValdiJSValue(existingFinalizer.get()));
440 if (weakReferenceId != 0) {
441 return weakReferenceId;
442 }
443
444 // Create the finalizer
445 auto finalizerObject = checkCallAndGetValue(

Callers

nothing calls this directly

Calls 8

JS_GetPropertyFunction · 0.85
JS_SetPropertyFunction · 0.85
guardMethod · 0.80
unsafeReleaseValueMethod · 0.80
fromValdiJSValueFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected