Skip to content

Commit d361080

Browse files
Decode ConstructibleFromJSValue directly if possible
1 parent ec37bdf commit d361080

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/JavaScriptKit/JSValueDecoder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ public class JSValueDecoder {
262262
from value: JSValue,
263263
userInfo: [CodingUserInfoKey: Any] = [:]
264264
) throws -> T where T: Decodable {
265+
if let jsType = T.self as? ConstructibleFromJSValue.Type {
266+
let maybeValue = jsType.construct(from: value)
267+
if let value = maybeValue { return value as! T }
268+
}
265269
let decoder = _Decoder(referencing: value, userInfo: userInfo)
266270
return try T(from: decoder)
267271
}

0 commit comments

Comments
 (0)