You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good, confirmed this is PR #6284 by anonrig. I'm reviewing as ask-bonk[bot].
Now let me do my final analysis. Let me review the whole change holistically:
Summary of changes:
New #[jsg_static_constant] proc macro attribute (marker only)
generate_resource_impl in jsg-macros scans for #[jsg_static_constant] on const items
New ConstantValue enum and From impls for numeric types in jsg/lib.rs
New Member::StaticConstant variant
New StaticConstantDescriptor CXX shared struct in v8.rs
C++ FFI code in ffi.c++ that sets the constants on constructor and prototype
Comprehensive tests
Documentation updates
Analysis:
The implementation is well-structured and faithfully mirrors the C++ JSG_STATIC_CONSTANT behavior:
Property attributes match (ReadOnly + DontDelete when spec-compliant, ReadOnly otherwise)
Sets on both constructor and prototype template — matches C++ exactly
Name is used as-is (no camelCase) — correct for constants
Only numeric types — matches Web IDL constant semantics
Potential issues I've identified:
In ffi.c++, the constants are set on constructor (FunctionTemplate) and prototype (also from constructor->PrototypeTemplate()). The C++ JSG does constructor->Set(...) and constructor->PrototypeTemplate()->Set(...) — which is exactly the same thing. This is correct.
The let ConstantValue::Number(number_value) = value; destructuring in lib.rs:87 is an irrefutable pattern since there's only one variant. This is fine and will produce a compile error if a new variant is added, forcing updates.
Tests cover: constructor access, instance/prototype access, read-only enforcement, coexistence with methods. Good coverage.
The ConstantValue enum could potentially benefit from #[non_exhaustive] if it's intended to be extended with string or boolean constants later, but since this is all within the same crate, it doesn't matter. The enum is public though — worth noting but not actionable.
Documentation is comprehensive and consistent across all modified docs.
I don't see any actionable issues — no bugs, no safety concerns, no backward compat problems, no missing compat flags. The implementation correctly matches the C++ JSG behavior.
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
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.
Adds static constant support to Rust JSG. Example: