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

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