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
408size_t QuickJSJavaScriptContext::associateWeakReference(const JSValue& value,
409 Valdi::JSExceptionTracker& exceptionTracker) {
410 auto guard = _threadAccessChecker.guard();
411 auto existingFinalizer =
412 checkCallAndGetValue(exceptionTracker, JS_GetProperty(_context, value, _objectFinalizerAtomKey));
413 if (!exceptionTracker) {
414 return 0;
415 }
416
417 auto weakReferenceId = weakReferenceIdFromJSWeakReferenceFinalizer(fromValdiJSValue(existingFinalizer.get()));
418 if (weakReferenceId != 0) {
419 return weakReferenceId;
420 }
421
422 // Create the finalizer
423 auto finalizerObject = checkCallAndGetValue(
424 exceptionTracker, JS_NewObjectProtoClass(_context, _objectPrototype, _weakReferenceFinalizerClassID));
425 if (!exceptionTracker) {
426 return 0;
427 }
428
429 weakReferenceId = ++_weakReferenceSequence;
430
431 setWeakReferenceIdToJSWeakReferenceFinalizer(fromValdiJSValue(finalizerObject.get()), weakReferenceId);
432 _weakReferences[weakReferenceId] = value;
433
434 if (!checkCall(
435 exceptionTracker,
436 JS_SetProperty(
437 _context, value, _objectFinalizerAtomKey, fromValdiJSValue(finalizerObject.unsafeReleaseValue())))) {
438 return 0;
439 }
440
441 return weakReferenceId;
442}
443
444Valdi::JSValueRef QuickJSJavaScriptContext::newWeakRef(const Valdi::JSValue& object,
445 Valdi::JSExceptionTracker& exceptionTracker) {

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