Repository navigation
Conversation
…ate fields - initialize_instance_elements copies the constructor's private methods and fields instead of keeping it borrowed while their initializers run
lehni
added a commit
to lehni/scriptographer-vectorcraft
that referenced
this pull request
Nov 24, 2026
- Core 524a90a with Paper.js release/1.0's hosted build; projects take their host as `project.host` - Boa pinned to lehni/boa with the fixes for boa-dev/boa#5690 and storytold#5691, which 1.0's classes hit - Tests follow 1.0: new symbols keep their place, circles start at the right as in SVG
abdulhamid999
left a comment
There was a problem hiding this comment.
Reviewed against core/engine/src/object/operations.rs, core/engine/src/builtins/function/mod.rs, and core/engine/src/vm/opcode/environment/mod.rs (static inspection; not compiled locally).
Findings
- Root cause & fix: In
JsObject::initialize_instance_elements,define_fieldinvokesinitializer.call(...), so an instance field initializer mutating a static private field (++C.#count) reachesC.private_set->self.borrow_mut()whileconstructor_function(GcRef<'_, OrdinaryFunction>) was still alive, causing aBorrowMutErrorpanic. Cloning(methods, fields)in an inner block drops the borrow before either loop runs. - Why dropping before
methodstoo is safer:private_method_or_accessor_addcallscontext.host_hooks().ensure_can_add_private_element(self, context)?andself.is_extensible(context)?. If a derived constructor'ssuper()returns aProxywhoseisExtensibletrap accessesC.#staticField, releasing the borrow before themethodsloop prevents the same panic there as well. - Callers & fast path: Both call sites (
ClassConstructorpath incore/engine/src/builtins/function/mod.rswherefunctionis already dropped beforehand, andSuperCallincore/engine/src/vm/opcode/environment/mod.rswhich clonesactive_function) do not hold competing borrows onconstructor. Also, when a class has no private methods or instance fields,.to_vec()on empty slices does not allocate on the heap. - Test coverage:
class_field_initializer_sets_a_static_private_fielddirectly reproduces and guards the reported crash.
Clean and minimal fix!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This Pull Request fixes a panic when an instance field initializer sets a static private field of its own class:
initialize_instance_elementskept the class constructor borrowed (downcast_ref::<OrdinaryFunction>()) while it ran the field initializers.PrivateSeton the constructor then needed it mutably.It changes the following:
initialize_instance_elementscopies the constructor's private methods and fields first, so the borrow ends before any initializer runsclass_field_initializer_sets_a_static_private_field