diff --git a/std/assembly/runtime.ts b/std/assembly/runtime.ts index c0d78cf6..5a3dd1fb 100644 --- a/std/assembly/runtime.ts +++ b/std/assembly/runtime.ts @@ -141,7 +141,7 @@ function doRegister(ref: usize, classId: u32): usize { return ref; } -/** Links a registered object with the (registered) object now referencing it. */ +/** Links a registered object with an object that is now referencing it. */ // @ts-ignore: decorator @unsafe @inline export function LINK(ref: T, parentRef: TParent): T { @@ -160,6 +160,24 @@ function doLink(ref: usize, parentRef: usize): void { if (GC_IMPLEMENTED) __gc_link(changetype(ref), changetype(parentRef)); } +/** Unlinks a registered object from an object that was referencing it. */ +// @ts-ignore: decorator +@unsafe @inline +export function UNLINK(ref: T, parentRef: TParent): void { + if (!isManaged()) ERROR("managed reference expected"); + if (!isManaged()) ERROR("managed reference expected"); + doUnlink(changetype(ref), changetype(parentRef)); +} + +function doUnlink(ref: usize, parentRef: usize): void { + if (!ASC_NO_ASSERT) { + assertRegistered(ref); + assertRegistered(parentRef); + } + // @ts-ignore: stub + if (GC_IMPLEMENTED) __gc_unlink(changetype(ref), changetype(parentRef)); +} + /** Discards an unregistered object that turned out to be unnecessary. */ // @ts-ignore: decorator @unsafe @inline