Skip to content

Commit c19ca4b

Browse files
committed
Add shouldSafeMethodCall option
1 parent e75679d commit c19ca4b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

WKJavaScriptController/WKJavaScriptController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ open class JSFloat: JSValueType {
5959
}
6060

6161
open class WKJavaScriptController: NSObject {
62+
// If true, do not allow NSNull(If pass undefined in JavaScript) for method arguments.
63+
// That is, if get NSNull as arguments, do not call method.
64+
open var shouldSafeMethodCall = true
65+
6266
fileprivate let name: String
6367
fileprivate weak var target: AnyObject?
6468
fileprivate let bridgeProtocol: Protocol
@@ -256,6 +260,14 @@ extension WKJavaScriptController: WKScriptMessageHandler {
256260
return
257261
}
258262

263+
if shouldSafeMethodCall {
264+
for arg in args {
265+
if arg is NSNull {
266+
return
267+
}
268+
}
269+
}
270+
259271
let method = class_getInstanceMethod(target.classForCoder, bridge.nativeSelector)
260272
if method == nil {
261273
log("An unimplemented method has been called. (selector: \(bridge.nativeSelector))")

0 commit comments

Comments
 (0)