diff --git a/Sources/JavaScriptKit/JSValue.swift b/Sources/JavaScriptKit/JSValue.swift index fe1400e2..1052aa6b 100644 --- a/Sources/JavaScriptKit/JSValue.swift +++ b/Sources/JavaScriptKit/JSValue.swift @@ -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 } } }