Skip to content

Commit b4edc19

Browse files
j-f1kateinoigakukun
andcommitted
Update based on review suggestions
Co-Authored-By: Yuta Saito <11702759+kateinoigakukun@users.noreply.github.com>
1 parent 479ad20 commit b4edc19

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

Diff for: Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

-9
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ public class JSClosure: JSFunction {
9090
}
9191
}
9292

93-
public required convenience init(jsValue: JSValue) {
94-
switch jsValue {
95-
case let .function(fun):
96-
self.init { fun(arguments: $0) }
97-
default:
98-
fatalError()
99-
}
100-
}
101-
10293
public func release() {
10394
Self.sharedFunctions[hostFuncRef] = nil
10495
isReleased = true

Diff for: Sources/JavaScriptKit/JSValueConvertible.swift

+26-24
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,20 @@ extension Dictionary: JSValueConvertible where Value == JSValueConvertible, Key
9898
private let NativeJSArray = JSObject.global.Array.function!
9999
extension Dictionary: JSValueConstructible where Value: JSValueConstructible, Key == String {
100100
public static func construct(from value: JSValue) -> Self? {
101-
if let objectRef = value.object,
102-
let keys: [String] = Object.keys!(objectRef.jsValue()).fromJSValue() {
103-
var entries = [(String, Value)]()
104-
entries.reserveCapacity(keys.count)
105-
for key in keys {
106-
guard let value: Value = objectRef[key].fromJSValue() else {
107-
return nil
108-
}
109-
entries.append((key, value))
101+
guard
102+
let objectRef = value.object,
103+
let keys: [String] = Object.keys!(objectRef.jsValue()).fromJSValue()
104+
else { return nil }
105+
106+
var entries = [(String, Value)]()
107+
entries.reserveCapacity(keys.count)
108+
for key in keys {
109+
guard let value: Value = objectRef[key].fromJSValue() else {
110+
return nil
110111
}
111-
return Dictionary(uniqueKeysWithValues: entries)
112+
entries.append((key, value))
112113
}
113-
return nil
114+
return Dictionary(uniqueKeysWithValues: entries)
114115
}
115116
}
116117

@@ -152,20 +153,21 @@ extension Array: JSValueConvertible where Element == JSValueConvertible {
152153

153154
extension Array: JSValueConstructible where Element: JSValueConstructible {
154155
public static func construct(from value: JSValue) -> [Element]? {
155-
if let objectRef = value.object,
156-
objectRef.isInstanceOf(JSObject.global.Array.function!) {
157-
let count: Int = objectRef.length.fromJSValue()!
158-
var array = [Element]()
159-
array.reserveCapacity(count)
160-
161-
for i in 0 ..< count {
162-
guard let value: Element = objectRef[i].fromJSValue() else { return nil }
163-
array.append(value)
164-
}
165-
166-
return array
156+
guard
157+
let objectRef = value.object,
158+
objectRef.isInstanceOf(JSObject.global.Array.function!)
159+
else { return nil }
160+
161+
let count: Int = objectRef.length.fromJSValue()!
162+
var array = [Element]()
163+
array.reserveCapacity(count)
164+
165+
for i in 0 ..< count {
166+
guard let value: Element = objectRef[i].fromJSValue() else { return nil }
167+
array.append(value)
167168
}
168-
return nil
169+
170+
return array
169171
}
170172
}
171173

0 commit comments

Comments
 (0)