Repository navigation
fix(object): validate defineProperty descriptors, invariants, and Object.create - #3376
Merged
Merged
Conversation
added 3 commits
May 30, 2026 17:16
…erty-2817-2843-2816
…(keep object_ops.rs under 2000-line cap)
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.
Closes #2817
Closes #2843
Closes #2816
Implementation
#2817 — defineProperty / defineProperties descriptor validation
js_object_define_propertynow runs the ES descriptor-validation path before any mutation, throwing Node's exactTypeErrors:Object.defineProperty called on non-objectProperty description must be an object: <desc>get/set) and data (value/writable) fields ->Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>get->Getter must be a function: <v>; likewise forset->Setter must be a function: <v>js_object_define_propertiesnow throwsObject.defineProperties called on non-objectfor primitive targets andCannot convert undefined or null to objectfor a nullish properties bag; per-key non-object descriptors flow through the same validation (Property description must be an object: 1).#2843 — frozen / sealed / non-extensible invariants
js_object_define_propertyenforces mutation invariants before touching the object:Cannot define property <k>, object is not extensibleCannot redefine property: <k>#2816 — Object.create descriptor-form + prototype validation
Expr::ObjectCreatenow carries an optional second operand (the properties bag); lowering, walkers, collectors, stable-hash and both codegen backends updated.js_object_create_with_props(proto, props)validates the prototype (Object prototype may only be an Object or nullfor primitives/undefined;nulland objects accepted) and applies the descriptor bag viajs_object_define_properties. Codegen routes allObject.createcalls through it. A#[used]keepalive anchor retains the symbol through the auto-optimize bitcode pipeline, and it is declared in the runtime decls.Validation
test-files/test_gap_2817_2843_2816_object_defineproperty.tscovers every case in all three issues. Compiled with the DEFAULT auto-optimize flow, its output is byte-identical tonode --experimental-strip-types.cargo test --release -p perry-runtime object— green (82 passed). One unit test (test_unboxed_object_accessor_define_property_falls_back) used{ get: 1 }, now invalid per runtime: validate Object.defineProperty descriptors and throw TypeErrors #2817; updated it to use a real callable getter so it still exercises the accessor shape-invalidation path.cargo fmt --all -- --check— clean.test_issue_450_defineProperty_accessor,test_gap_2159_defineproperty_class_prototype,test_issue_1805_object_create_instanceof,test_gap_object_create_*,test_gap_object_methods,test_gap_object_get_own_property_descriptors,test_gap_2442_object_literal_accessors) — all stay byte-identical to Node.