Skip to content

jsvalue becomes a struct, to align with actual JavaScriptKit#104

Merged
tayloraswift merged 1 commit intomasterfrom
jsvalue-struct
Feb 4, 2026
Merged

jsvalue becomes a struct, to align with actual JavaScriptKit#104
tayloraswift merged 1 commit intomasterfrom
jsvalue-struct

Conversation

@tayloraswift
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @tayloraswift, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the core JSValue type within the JavaScriptPersistence module. By transitioning JSValue from an enum to a struct that wraps an internal Storage enum, the change aims to improve consistency with JavaScriptKit and potentially offer more flexibility in future extensions. This modification necessitates updates across various extensions and accessors that interact with JSValue's underlying data, ensuring all operations correctly reference the new storage property.

Highlights

  • JSValue Type Change: The JSValue type has been refactored from an enum to a struct, aligning its design more closely with JavaScriptKit's approach.
  • Introduction of JSValue.Storage: A new JSValue.Storage enum has been introduced to encapsulate the actual underlying JavaScript value types (boolean, string, number, object, null, undefined, symbol, bigInt). The JSValue struct now holds an instance of this Storage enum.
  • Updated Access Patterns: All existing ConstructibleFromJSValue implementations and JSValue accessor properties (e.g., number, string, object) have been updated to access the underlying value via the new value.storage or self.storage property.
  • Simplified Numeric Accessors: The @available(*, unavailable) attributes that previously prevented direct access to number and bigInt properties on JSValue have been removed, simplifying their usage.
Changelog
  • Sources/JavaScriptPersistence/Array (ext).swift
    • Updated construct(from:) to access the storage property of JSValue.
  • Sources/JavaScriptPersistence/BinaryFloatingPoint (ext).swift
    • Updated construct(from:) to access the storage property of JSValue.
  • Sources/JavaScriptPersistence/ConstructibleFromJSValue.swift
    • Updated construct(from:) for SignedInteger and UnsignedInteger extensions to access the storage property of JSValue.
  • Sources/JavaScriptPersistence/JSString.swift
    • Updated construct(from:) to access the storage property of JSValue.
  • Sources/JavaScriptPersistence/JSValue.Storage.swift
    • Added new file defining the JSValue.Storage enum to hold the various JavaScript value types.
  • Sources/JavaScriptPersistence/JSValue.swift
    • Changed JSValue from an enum to a struct.
    • Added a storage property of type Storage to JSValue.
    • Introduced static factory methods (e.g., JSValue.boolean(_:), JSValue.string(_:)) for creating JSValue instances.
    • Updated the encode(to:) method to switch on self.storage.
    • Modified all accessor properties (number, bigInt, jsString, boolean, string, object, symbol, isNull, isUndefined) to retrieve values from self.storage.
    • Removed @available(*, unavailable) attributes from number and bigInt properties.
  • Sources/JavaScriptPersistence/Optional (ext).swift
    • Updated construct(from:) to access the storage property of JSValue.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors JSValue from an enum to a struct, which is a solid architectural improvement for better encapsulation and alignment with JavaScriptKit. The related changes throughout the codebase are consistent with this refactoring.

My review focuses on a couple of areas. I've raised a high-severity concern about the removal of @available attributes on the number and bigInt properties. These attributes previously enforced that developers handle both numeric types, and their removal could lead to subtle bugs. I've also provided a couple of medium-severity suggestions to improve the conciseness and readability of boolean-checking computed properties in JSValue.swift.

Overall, the refactoring is well done, but the implications of the API change for numeric types should be carefully considered.

Comment on lines +133 to +145
@inlinable public var number: Double? {
guard case .number(let value) = self.storage else {
return nil
}
return value
}

@available(
*, unavailable,
message: "code that expects a numeric value should check for 'Double' as well"
) @inlinable public var bigInt: JSBigInt? {
guard case .bigInt(let value) = self else {
@inlinable public var bigInt: JSBigInt? {
guard case .bigInt(let value) = self.storage else {
return nil
}
return value
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The @available(*, unavailable, ...) attributes on the number and bigInt properties have been removed. These attributes served an important purpose: they forced developers to consciously handle both Double and JSBigInt representations for numeric values, preventing potential bugs with large numbers that can't be represented as Double. Removing these checks makes the API easier to misuse. If this change was intentional, it would be beneficial to document the rationale and guide users on correct handling of numeric types. If it was an oversight, please consider reintroducing a mechanism to ensure both numeric types are handled correctly.

Comment on lines 184 to 189
@inlinable public var isNull: Bool {
guard case .null = self else {
guard case .null = self.storage else {
return false
}
return true
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The implementation of isNull can be made more concise and idiomatic by using a switch statement. While the guard statement is functionally correct, a switch is often clearer for checking enum cases.

    @inlinable public var isNull: Bool {
        switch self.storage {
        case .null:
            return true
        default:
            return false
        }
    }

@tayloraswift tayloraswift merged commit 95d1930 into master Feb 4, 2026
6 of 8 checks passed
@tayloraswift tayloraswift deleted the jsvalue-struct branch February 4, 2026 00:51
tayloraswift added a commit that referenced this pull request Mar 15, 2026
jsvalue becomes a struct, to align with actual JavaScriptKit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant