Skip to content

Commit d8a01fd

Browse files
committed
nonmutating
1 parent dd0c977 commit d8a01fd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Sources/JavaScriptKit/JSValue.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,26 @@ public extension JSValue {
109109
}
110110
#endif
111111

112-
/// An unsafe convenience method of `JSObject.subscript(_ index: Int) -> JSValue`
112+
/// An unsafe convenience method of `JSObject.subscript(_ index: String) -> JSValue`
113113
/// - Precondition: `self` must be a JavaScript Object.
114114
subscript(dynamicMember name: String) -> JSValue {
115115
get { self.object![name] }
116-
set { self.object![name] = newValue }
116+
nonmutating set { self.object![name] = newValue }
117+
}
118+
119+
/// An unsafe convenience method of `JSObject.subscript(_ index: String) -> JSValue`
120+
/// - Precondition: `self` must be a JavaScript Object.
121+
@_disfavoredOverload
122+
subscript(dynamicMember name: String) -> ConvertibleToJSValue {
123+
get { self.object![name] }
124+
nonmutating set { self.object![name] = newValue.jsValue }
117125
}
118126

119127
/// An unsafe convenience method of `JSObject.subscript(_ index: Int) -> JSValue`
120128
/// - Precondition: `self` must be a JavaScript Object.
121129
subscript(_ index: Int) -> JSValue {
122130
get { object![index] }
123-
set { object![index] = newValue }
131+
nonmutating set { object![index] = newValue }
124132
}
125133
}
126134

0 commit comments

Comments
 (0)