File size: 1,521 Bytes
b5ea024
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";

var test = function (arg1, arg2) { return arg2; };

try {
	Object.defineProperty(test, "length", {
		configurable: true,
		writable: false,
		enumerable: false,
		value: 1
	});
}
catch (ignore) {}

if (test.length === 1) {
	// ES2015+
	var desc = { configurable: true, writable: false, enumerable: false };
	module.exports = function (length, fn) {
		if (fn.length === length) return fn;
		desc.value = length;
		return Object.defineProperty(fn, "length", desc);
	};
	return;
}

module.exports = function (length, fn) {
	if (fn.length === length) return fn;
	switch (length) {
		case 0:
			return function () { return fn.apply(this, arguments); };
		case 1:
			return function (ignored1) { return fn.apply(this, arguments); };
		case 2:
			return function (ignored1, ignored2) { return fn.apply(this, arguments); };
		case 3:
			return function (ignored1, ignored2, ignored3) { return fn.apply(this, arguments); };
		case 4:
			return function (ignored1, ignored2, ignored3, ignored4) {
				return fn.apply(this, arguments);
			};
		case 5:
			return function (ignored1, ignored2, ignored3, ignored4, ignored5) {
				return fn.apply(this, arguments);
			};
		case 6:
			return function (ignored1, ignored2, ignored3, ignored4, ignored5, ignored6) {
				return fn.apply(this, arguments);
			};
		case 7:
			return function (ignored1, ignored2, ignored3, ignored4, ignored5, ignored6, ignored7) {
				return fn.apply(this, arguments);
			};
		default:
			throw new Error("Usupported function length");
	}
};