From d8a01fdbac844354a74660d6f71933dcc0c671d0 Mon Sep 17 00:00:00 2001 From: Casper Zandbergen Date: Sun, 17 Nov 2024 13:03:48 +0100 Subject: [PATCH] nonmutating --- Sources/JavaScriptKit/JSValue.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 } } }