From 501309118d18d21cd6326f7c9e20ccd3a0cc1e00 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Sat, 29 Apr 2017 11:38:34 -0400 Subject: [PATCH] Fix bug in zero-args calls to the impl This was introduced in 4dd82b0af691ba0c345f1dc24c44f33be7d4b7f0. --- lib/constructs/operation.js | 7 ++++--- lib/parameters.js | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/constructs/operation.js b/lib/constructs/operation.js index ff3e3b4b..b9da03fe 100644 --- a/lib/constructs/operation.js +++ b/lib/constructs/operation.js @@ -53,22 +53,23 @@ Operation.prototype.generate = function () { const callOn = this.idl.static ? "Impl" : "this[impl]"; const parameterConversions = Parameters.generateOverloadConversions(overloads, this.obj.opts.customTypes); + const argsSpread = parameterConversions.hasArgs ? "...args" : ""; Object.assign(requires, parameterConversions.requires); str += parameterConversions.body; if (!this.idl.stringifier && overloads.every((overload) => conversions[overload.operation.idlType.idlType])) { str += ` - return ${callOn}.${name}.apply(${callOn}, args); + return ${callOn}.${name}(${argsSpread}); };\n`; } else { str += ` - return utils.tryWrapperForImpl(${callOn}.${name}.apply(${callOn}, args)); + return utils.tryWrapperForImpl(${callOn}.${name}(${argsSpread})); };\n`; } if (this.idl.stringifier && name !== "toString") { str += `\n${this.name}.prototype.toString(${minConstructor.nameList.join(", ")}) {`; str += parameterConversions.body; str += ` - return ${callOn}.${name}.apply(${callOn}, args); + return ${callOn}.${name}.apply(${argsSpread}); };\n`; } diff --git a/lib/parameters.js b/lib/parameters.js index 2b10ad23..9b8fd715 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -114,6 +114,7 @@ module.exports.generateOverloadConversions = function (overloads, customTypes) { } return { requires, - body: str + body: str, + hasArgs: !isAlwaysZeroArgs }; };