MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / Delete

Method Delete

source/script_object.cpp:399–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397//
398
399bool Object::Delete()
400{
401 if (mBase)
402 {
403 if (FindField(_T("__Class")))
404 // This object appears to be a class definition, so it would probably be
405 // undesirable to call the super-class' __Delete() meta-function for this.
406 return ObjectBase::Delete();
407
408 // L33: Privatize the last recursion layer's deref buffer in case it is in use by our caller.
409 // It's done here rather than in Var::FreeAndRestoreFunctionVars (even though the below might
410 // not actually call any script functions) because this function is probably executed much
411 // less often in most cases.
412 PRIVATIZE_S_DEREF_BUF;
413
414 Line *curr_line = g_script.mCurrLine;
415
416 // If an exception has been thrown, temporarily clear it for execution of __Delete.
417 ResultToken *exc = g->ThrownToken;
418 g->ThrownToken = NULL;
419
420 // This prevents an erroneous "The current thread will exit" message when an error occurs,
421 // by causing LineError() to throw an exception:
422 int outer_excptmode = g->ExcptMode;
423 g->ExcptMode |= EXCPTMODE_DELETE;
424
425 {
426 FuncResult rt;
427 CallMeta(_T("__Delete"), rt, ExprTokenType(this), nullptr, 0);
428 rt.Free();
429 }
430
431 g->ExcptMode = outer_excptmode;
432
433 // Exceptions thrown by __Delete are reported immediately because they would not be handled
434 // consistently by the caller (they would typically be "thrown" by the next function call),
435 // and because the caller must be allowed to make additional __Delete calls.
436 if (g->ThrownToken)
437 g_script.FreeExceptionToken(g->ThrownToken);
438
439 // If an exception has been thrown by our caller, it's likely that it can and should be handled
440 // reliably by our caller, so restore it.
441 if (exc)
442 g->ThrownToken = exc;
443
444 g_script.mCurrLine = curr_line; // Prevent misleading error reports/Exception() stack trace.
445
446 DEPRIVATIZE_S_DEREF_BUF; // L33: See above.
447
448 // Above may pass the script a reference to this object to allow cleanup routines to free any
449 // associated resources. Deleting it is only safe if the script no longer holds any references
450 // to it. Since cleanup routines may (intentionally or unintentionally) copy this reference,
451 // ensure this object really has no more references before proceeding with deletion:
452 if (mRefCount > 1)
453 return false;
454 }
455 return ObjectBase::Delete();
456}

Callers

nothing calls this directly

Calls 8

DeleteFunction · 0.85
ExprTokenTypeClass · 0.85
index_tEnum · 0.85
FreeExceptionTokenMethod · 0.80
ReturnMoveMethod · 0.80
FullyReleasedMethod · 0.80
FreeMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected