Skip to content

Commit 82c680e

Browse files
committed
Protocol.hasImpl reflection API
1 parent 4eab890 commit 82c680e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

index.js

+24
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,30 @@ function installMethodErrorMessage (proto, gf, target, name) {
7272

7373
Protocol.isDerivable = function (proto) { return proto._derivable }
7474

75+
Protocol.hasImpl = function (proto, arg, args) {
76+
args = args || []
77+
if (Object.getPrototypeOf(arg) === Array.prototype) {
78+
args = arg
79+
arg = null
80+
}
81+
var fns = proto._methodNames
82+
var gf
83+
for (var i = 0; i < fns.length; i++) {
84+
if (arg) {
85+
gf = arg[fns[i]]
86+
} else {
87+
gf = proto[fns[i]]
88+
}
89+
if (!gf ||
90+
(gf.hasMethod
91+
? !gf.hasMethod.apply(gf, args)
92+
: typeof gf === 'function')) {
93+
return false
94+
}
95+
}
96+
return true
97+
}
98+
7599
Protocol.impl = function (proto, target, types, implementations) {
76100
if (Object.getPrototypeOf(target) === Array.prototype) {
77101
// Proto([Array], { map() { ... } })

0 commit comments

Comments
 (0)