Create constructor function .prototype property on-demand #1873
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(At this point just some quick testing, not sure if this approach will be merged.)
All constructable functions have a
.prototype
property. It points, by default, to an object whose.constructor
property points back to the function, creating a reference loop. This reference loop prevents most function objects, especially inline callbacks, from being refcount freed. There are several approaches to allow refcount collection of such function objects.One of them is to postpone creation of the
.prototype
property until it is actually observed somehow and we must commit to the property's existence. Relevant situations include:.prototype
is writable but not configurable, the new value can be written without creating the object prior to the (over)write.prototype in MyConstructor
must return true; does not require creation of the object..prototype
is non-configurable so delete must fail; does not require creation of the object.This approach allows refcount collection of a few basic cases, in particular anonymous functions which are not captured by an outer scope, e.g.:
Unfortunately if the function is given a name, this currently creates another kind of reference loop (scope object containing the function name binding points to the function, and the function points to the scope) so this doesn't get refcount collected:
This case could be allowed to work by reworking the function name binding scope handling. But other cases will still remain.
Tasks:
Future work: