Skip to content

Commit f00dc46

Browse files
committed
fix JSObject.construct(from:)
1 parent 2c1d59d commit f00dc46

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ public final class JSBigInt: JSObject {
2424
super.init(id: _i64_to_bigint_slow(UInt32(value & 0xffffffff), UInt32(value >> 32), false))
2525
}
2626

27-
override public class func construct(from value: JSValue) -> Self? {
28-
value.bigInt as? Self
29-
}
30-
3127
override public var jsValue: JSValue {
3228
.bigInt(self)
3329
}

Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public class JSFunction: JSObject {
8989
fatalError("unavailable")
9090
}
9191

92-
override public class func construct(from value: JSValue) -> Self? {
93-
return value.function as? Self
94-
}
95-
9692
override public var jsValue: JSValue {
9793
.function(self)
9894
}

Sources/JavaScriptKit/FundamentalObjects/JSObject.swift

+16-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,22 @@ public class JSObject: Equatable {
150150
return lhs.id == rhs.id
151151
}
152152

153-
public class func construct(from value: JSValue) -> Self? {
154-
return value.object as? Self
153+
public static func construct(from value: JSValue) -> Self? {
154+
switch value {
155+
case .boolean,
156+
.string,
157+
.number,
158+
.null,
159+
.undefined: return nil
160+
case .object(let object):
161+
return object as? Self
162+
case .function(let function):
163+
return function as? Self
164+
case .symbol(let symbol):
165+
return symbol as? Self
166+
case .bigInt(let bigInt):
167+
return bigInt as? Self
168+
}
155169
}
156170

157171
public var jsValue: JSValue {

Sources/JavaScriptKit/FundamentalObjects/JSSymbol.swift

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public class JSSymbol: JSObject {
4141
Symbol.keyFor!(symbol).string
4242
}
4343

44-
override public class func construct(from value: JSValue) -> Self? {
45-
return value.symbol as? Self
46-
}
47-
4844
override public var jsValue: JSValue {
4945
.symbol(self)
5046
}

0 commit comments

Comments
 (0)