Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions lib/class-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,30 +1386,26 @@ dispatcherPrototype = Object.create(Function.prototype, {
invoke: {
value (receiver, args) {
const overloads = this._o;
const methodsThatCanBeInvoked = overloads.filter(method => method.canInvokeWith(args));
if (methodsThatCanBeInvoked.length === 0) {
throwOverloadError(this.methodName, this.overloads, 'argument types do not match any of:');
} else if (methodsThatCanBeInvoked.length > 1) {
throwIfDispatcherAmbiguous(this);
}
const method = methodsThatCanBeInvoked[0];

const isInstance = receiver.$h !== null;
if (method.type === INSTANCE_METHOD && !isInstance) {
const name = this.methodName;

for (let i = 0; i !== overloads.length; i++) {
const method = overloads[i];

if (!method.canInvokeWith(args)) {
continue;
}

if (method.type === INSTANCE_METHOD && !isInstance) {
const name = this.methodName;

if (name === 'toString') {
return `<class: ${receiver.$n}>`;
}

throw new Error(name + ': cannot call instance method without an instance');
if (name === 'toString') {
return `<class: ${receiver.$n}>`;
}

return method.apply(receiver, args);
throw new Error(name + ': cannot call instance method without an instance');
}

throwOverloadError(this.methodName, this.overloads, 'argument types do not match any of:');
return method.apply(receiver, args);
}
}
});
Expand Down