Fix primitive handling for dynamic length

This commit is contained in:
Mariusz Nowak
2013-07-22 19:34:28 +02:00
parent ec90653d30
commit 2b4cf268c8
2 changed files with 16 additions and 2 deletions

View File

@@ -17,8 +17,8 @@ module.exports = require('./_base')(function (conf, length) {
if (length === 1) {
get = conf.get = getId1;
} else if (length === false) {
get = conf.get = function (args, length) {
var id = '', i;
get = conf.get = function (args) {
var id = '', i, length = args.length;
if (length) {
id += args[i = 0];
while (--length) {

View File

@@ -1,5 +1,7 @@
'use strict';
var join = Array.prototype.join;
module.exports = function (t) {
return {
"No args": function (a) {
@@ -25,6 +27,18 @@ module.exports = function (t) {
a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2");
a(i, 1, "Called once");
},
"Many args: Length false": function (a) {
var i = 0, fn = function () { ++i; return join.call(arguments, '|'); }
, y = { toString: function () { return 'foo'; } }, mfn;
mfn = t(fn, { primitive: true, length: false });
a(mfn(y, 'bar', 'zeta'), 'foo|bar|zeta', "#1");
a(mfn('foo', 'bar', 'zeta'), 'foo|bar|zeta', "#2");
a(i, 1, "Called once");
a(mfn(y, 'bar'), 'foo|bar', "#3");
a(i, 2, "Called twice");
a(mfn(y, 'bar'), 'foo|bar', "#4");
a(i, 2, "Called twice #2");
},
"Clear cache": function (a) {
var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn
, y = { toString: function () { return 'foo'; } };