Skip to content

Commit

Permalink
nonmutating
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzd committed Nov 17, 2024
1 parent dd0c977 commit d8a01fd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Sources/JavaScriptKit/JSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,26 @@ public extension JSValue {
}
#endif

/// An unsafe convenience method of `JSObject.subscript(_ index: Int) -> JSValue`
/// An unsafe convenience method of `JSObject.subscript(_ index: String) -> JSValue`
/// - Precondition: `self` must be a JavaScript Object.
subscript(dynamicMember name: String) -> JSValue {
get { self.object![name] }
set { self.object![name] = newValue }
nonmutating set { self.object![name] = newValue }
}

/// An unsafe convenience method of `JSObject.subscript(_ index: String) -> JSValue`
/// - Precondition: `self` must be a JavaScript Object.
@_disfavoredOverload
subscript(dynamicMember name: String) -> ConvertibleToJSValue {
get { self.object![name] }
nonmutating set { self.object![name] = newValue.jsValue }
}

/// An unsafe convenience method of `JSObject.subscript(_ index: Int) -> JSValue`
/// - Precondition: `self` must be a JavaScript Object.
subscript(_ index: Int) -> JSValue {
get { object![index] }
set { object![index] = newValue }
nonmutating set { object![index] = newValue }
}
}

Expand Down

0 comments on commit d8a01fd

Please sign in to comment.