Skip to content

Instantly share code, notes, and snippets.

@leobalter
Created June 3, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leobalter/79ea9288b32132018990feaf20be8c49 to your computer and use it in GitHub Desktop.
Save leobalter/79ea9288b32132018990feaf20be8c49 to your computer and use it in GitHub Desktop.
The WeakRef Constructor
https://tc39.github.io/proposal-weakrefs/#sec-weak-ref-constructor
- [ ] is the initial value of the WeakRef property of the global object.
- [ ] is designed to be subclassable. It may be used as the value in an extends clause of a class definition. Subclass constructors that intend to inherit the specified WeakRef behaviour must include a super call to the WeakRef constructor to create and initialize the subclass instance with the internal state necessary to support the WeakRef.prototype built-in methods.
WeakRef ( target )
https://tc39.github.io/proposal-weakrefs/#sec-weak-ref-target
1. [ ] If NewTarget is undefined, throw a TypeError exception.
2. [ ] If Type(target) is not Object, throw a TypeError exception.
3. [ ] Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »).
4. Perfom ! KeepDuringJob(target).
5. Set weakRef.[[Target]] to target.
6. [ ] Return weakRef.
Properties of the WeakRef Constructor
https://tc39.github.io/proposal-weakrefs/#sec-properties-of-the-weak-ref-constructor
- [ ] has a [[Prototype]] internal slot whose value is the intrinsic object %FunctionPrototype%.
WeakRef.prototype
https://tc39.github.io/proposal-weakrefs/#sec-weak-ref.prototype
- [ ] This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
Properties of the WeakRef Prototype Object
- [ ] has a [[Prototype]] internal slot whose value is the intrinsic object %ObjectPrototype%.
- [ ] does not have a [[Target]] internal slot.
WeakRef.prototype.deref ( )
https://tc39.github.io/proposal-weakrefs/#sec-weak-ref.prototype.deref
1. Let weakRef be the this value.
2. [ ] If Type(weakRef) is not Object, throw a TypeError exception.
3. [ ] If weakRef does not have a [[Target]] internal slot, throw a TypeError exception.
4. Let target be the value of weakRef.[[Target]].
5. [ ] If target is not empty,
a. Perform ! KeepDuringJob(target).
b. [ ] Return target.
6. [ ] Return undefined.
WeakRef.prototype [ @@toStringTag ]
https://tc39.github.io/proposal-weakrefs/#sec-weak-ref.prototype-@@tostringtag
- [ ] The initial value of the @@toStringTag property is the String value "WeakRef".
- [ ] This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
The FinalizationGroup Constructor
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group-constructor
- [ ] is the initial value of the FinalizationGroup property of the global object.
FinalizationGroup ( cleanupCallback )
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group-cleanup-callback
1. [ ] If NewTarget is undefined, throw a TypeError exception.
2. [ ] If IsCallable(cleanupCallback) is false, throw a TypeError exception.
3. [ ] Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
4. Let fn be the active function object.
5. Set finalizationGroup.[[Realm]] to fn.[[Realm]].
6. Set finalizationGroup.[[CleanupCallback]] to cleanupCallback.
7. Set finalizationGroup.[[Cells]] to be an empty List.
8. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to false.
9. [ ] Return finalizationGroup.
Properties of the FinalizationGroup Constructor
https://tc39.github.io/proposal-weakrefs/#sec-properties-of-the-finalization-group-constructor
- [ ] has a [[Prototype]] internal slot whose value is the intrinsic object %FunctionPrototype%.
FinalizationGroup.prototype
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group.prototype
- [ ] This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
Properties of the FinalizationGroup Prototype Object
https://tc39.github.io/proposal-weakrefs/#sec-properties-of-the-finalization-group-prototype-object
- [ ] has a [[Prototype]] internal slot whose value is the intrinsic object %ObjectPrototype%.
is an ordinary object.
- [ ] does not have a [[Target]] internal slot.
FinalizationGroup.prototype.constructor
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group.prototype.constructor
- [ ] The initial value of FinalizationGroup.prototype.constructor is the intrinsic object %FinalizationGroup%.
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group.prototype.register
1. Let finalizationGroup be the this value.
2. [ ] If Type(finalizationGroup) is not Object, throw a TypeError exception.
3. [ ] If Type(target) is not Object, throw a TypeError exception.
4. [ ] If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
5. If Type(unregisterToken) is not Object,
a. [ ] If unregisterToken is not undefined, throw a TypeError exception.
b. [ ] Set unregisterToken to empty.
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
7. Append cell to finalizationGroup.[[Cells]].
8. [ ] Return undefined.
FinalizationGroup.prototype.unregister ( unregisterToken )
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group.prototype.unregister
1. Let finalizationGroup be the this value.
2. [ ] If Type(finalizationGroup) is not Object, throw a TypeError exception.
3. [ ] If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
4. [ ] If Type(unregisterToken) is not Object, through a TypeError exception.
5. Let removed be false.
6. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationGroup.[[Cells]], do
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
i. Remove cell from finalizationGroup.[[Cells]].
ii. Set removed to true.
7. [ ] Return removed.
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group.prototype.cleanupSome
1. Let finalizationGroup be the this value.
2. [ ] If Type(finalizationGroup) is not Object, throw a TypeError exception.
3. [ ] If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
4. [ ] If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
6. [ ] Return undefined.
FinalizationGroup.prototype [ @@toStringTag ]
https://tc39.github.io/proposal-weakrefs/#sec-finalization-group.prototype-@@tostringtag
- [ ] The initial value of the @@toStringTag property is the String value "FinalizationGroup".
- [ ] This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
CreateFinalizationGroupCleanupIterator ( finalizationGroup )
https://tc39.github.io/proposal-weakrefs/#sec-createfinalizationgroupcleanupiterator
1. Let finalizationGroup be the this value.
2. [ ] If Type(finalizationGroup) is not Object, throw a TypeError exception.
3. [ ] If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
4. Assert: realm.[[Intrinsics]].[[%FinalizationGroupCleanupIteratorPrototype%]] exists and has been initialized.
5. Let prototype be finalizationGroup.[[Realm]].[[Intrinsics]].[[%FinalizationGroupCleanupIteratorPrototype%]].
6. Let iterator be ObjectCreate(prototype, « [[FinalizationGroup]] »).
7. Set iterator.[[FinalizationGroup]] to finalizationGroup.
8. [ ] Return iterator.
The %FinalizationGroupCleanupIteratorPrototype% Object
https://tc39.github.io/proposal-weakrefs/#sec-%finalizationgroupcleanupiterator%-object
- [ ] is an ordinary object.
- [ ] has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
%FinalizationGroupCleanupIteratorPrototype%.next ( )
https://tc39.github.io/proposal-weakrefs/#sec-%finalizationgroupcleanupiterator%.next
1. Let iterator be the this value.
2. [ ] If Type(iterator) is not Object, throw a TypeError exception.
3. [ ] If iterator does not have a [[FinalizationGroup]] internal slot, throw a TypeError exception.
4. Let finalizationGroup be iterator.[[FinalizationGroup]].
5. If finalizationGroup is undefined, then
a. [ ] Return CreateIterResultObject(undefined, true).
6. Assert: finalizationGroup has [[Cells]] and [[IsFinalizationGroupCleanupJobActive]] internal slot.
7. [ ] If finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] is false, throw a TypeError exception.
8. If finalizationGroup.[[Cells]] contains a Record cell such that cell.[[Target]] is empty,
a. Choose any such cell.
b. Remove cell from finalizationGroup.[[Cells]].
c. [ ] Return CreateIterResultObject(cell.[[Holdings]], false).
9. [ ] Otherwise, return CreateIterResultObject(undefined, true).
%FinalizationGroupCleanupIteratorPrototype% [ @@toStringTag ]
https://tc39.github.io/proposal-weakrefs/#sec-%finalizationgroupcleanupiteratorprototype%-@@tostringtag
- [ ] The initial value of the @@toStringTag property is the String value "FinalizationGroup Cleanup Iterator".
- [ ] This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment