jsvalue becomes a struct, to align with actual JavaScriptKit#104
jsvalue becomes a struct, to align with actual JavaScriptKit#104tayloraswift merged 1 commit intomasterfrom
Conversation
Summary of ChangesHello @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 Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| @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 | ||
| } |
There was a problem hiding this comment.
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.
| @inlinable public var isNull: Bool { | ||
| guard case .null = self else { | ||
| guard case .null = self.storage else { | ||
| return false | ||
| } | ||
| return true | ||
| } |
There was a problem hiding this comment.
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
}
}jsvalue becomes a struct, to align with actual JavaScriptKit
No description provided.