add instance/prototype properties to rust JSG#6401
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds #[jsg_prototype_property], #[jsg_instance_property], and #[jsg_inspect_property] macro support to the Rust JSG layer, mirroring the corresponding C++ JSG_PROTOTYPE_PROPERTY, JSG_INSTANCE_PROPERTY, JSG_LAZY_INSTANCE_PROPERTY, and JSG_INSPECT_PROPERTY macros.
Issues found (ranked by severity):
- [HIGH]
extract_name_attributesilently drops name override whenlazyflag is present.#[jsg_instance_property(lazy, name = "cachedLabel")]— the documented combined form — does not work. - [MEDIUM] Lazy instance properties don't actually cache the getter result — the Rust side uses
SetAccessorPropertyinstead of C++'sSetLazyDataProperty, so the getter fires on every access. The user-facing docs claim caching behavior. - [LOW] Inspect properties don't register in the
inspectPropertiesdictionary —node:util inspect()may not discover Rust-defined inspect properties.
This review was generated by an AI assistant and may contain inaccuracies.
|
Review posted successfully. Here's a summary of what I found: 3 issues filed on PR #6401 (all posted as inline comments in a single batch review):
|
036c771 to
d9f1930
Compare
127a643 to
9f7bd00
Compare
9f7bd00 to
f4a70ad
Compare
|
/bigbonk review this PR again |
There was a problem hiding this comment.
Follow-up review after lazy support removal and inspect properties fix.
Previously flagged issues — status:
- [HIGH]
extract_name_attribute+lazy— No longer applicable.lazyhas been removed;#[jsg_property]now usesparse_jsg_property_argswhich properly handles comma-separated meta items.extract_name_attributeis only called wherename = "..."is the sole argument. - [MEDIUM] Lazy properties don't cache — Resolved. Lazy support removed per jasnell's feedback.
- [LOW] Missing
inspectPropertiesdictionary — Fixed. Lines 768-773 create the ObjectTemplate and line 845 registers each inspect symbol. - jasnell's
NewFromUtf8length check — Addressed withKJ_REQUIREat line 779.
New findings below (posted as inline comments).
This review was generated by an AI assistant and may contain inaccuracies.
|
Review posted on PR #6401 with 4 inline comments. Here's a summary: Previously flagged issues (all resolved):
New findings:
|
…Rust JSG - Prototype read-write properties were registered with DontEnum; they should use None (enumerable) to match C++ registerPrototypeProperty which uses Gcb::enumerable = true (resource.h:1454-1455). - Prototype read-only properties were registered with ReadOnly|DontEnum; they should use ReadOnly only, matching registerReadonlyPrototypeProperty (resource.h:1498-1501) with Gcb::enumerable = true. - The spec-compliant path of makePropFn was passing the constructor signature to FunctionTemplate::New; C++ passes an empty v8::Local<v8::Signature>() for spec-compliant prototype properties (resource.h:1438-1441). - Add three new tests that assert prototype properties are enumerable and appear in for...in, providing regression coverage for the DontEnum fix.
- PropertyKind::Prototype doc said 'Not directly enumerable' which is wrong after the DontEnum fix; update to say enumerable. - jsg_inspect_property docstring claimed no get_/set_ stripping occurs for the auto-derived symbol name, but derive_js_name() does strip those prefixes; correct the description to match the implementation. - scan_property_annotations used BTreeMap which sorted property groups alphabetically, causing registration order to differ from source order. Replace with a Vec-based find-or-insert to preserve source order. - methods and static_constants loops in create_resource_template were missing the KJ_REQUIRE length check added for properties; add it for consistency. - Remove redundant static_cast<v8::PropertyAttribute> wrapping a single enum value in the read-only instance property branch. - Remove dead 'let _ = p' binding in the readonly match arm of parse_jsg_property_args; p is already consumed by the guard expression.
d122647 to
db3380b
Compare
Merging this PR will improve performance by 25.38%
Performance Changes
Comparing Footnotes
|
No description provided.