Skip to content

Commit ce44213

Browse files
author
Ruben Bridgewater
committed
A function name is only configurable from v8 >= v.4.3
1 parent 25aa8f6 commit ce44213

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Features
1010
- Updated [redis-parser](https://github.com/NodeRedis/redis-parser) dependency ([changelog](https://github.com/NodeRedis/redis-parser/releases/tag/v.2.0.0))
1111
- The JS parser is from now on the new default as it is a lot faster than the hiredis parser
1212
- This is no BC as there is no changed behavior for the user at all but just a performance improvement. Explicitly requireing the Hiredis parser is still possible.
13-
- Added name property to all Redis functions
13+
- Added name property to all Redis functions (Node.js >= 4.0)
1414

1515
Bugfixes
1616

lib/commands.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ var commands = require('redis-commands');
44
var Multi = require('./multi');
55
var RedisClient = require('../').RedisClient;
66
var Command = require('./command');
7+
// Feature detect if a function may change it's name
8+
var changeFunctionName = (function () {
9+
var fn = function abc () {};
10+
try {
11+
Object.defineProperty(fn, 'name', {
12+
value: 'foobar'
13+
});
14+
return true;
15+
} catch (e) {
16+
return false;
17+
}
18+
}());
719

820
// TODO: Rewrite this including the invidual commands into a Commands class
921
// that provided a functionality to add new commands to the client
@@ -45,9 +57,11 @@ commands.list.forEach(function (command) {
4557
}
4658
return this.internal_send_command(new Command(command, arr, callback));
4759
};
48-
Object.defineProperty(RedisClient.prototype[command], 'name', {
49-
value: command
50-
});
60+
if (changeFunctionName) {
61+
Object.defineProperty(RedisClient.prototype[command], 'name', {
62+
value: command
63+
});
64+
}
5165
}
5266

5367
// Do not override existing functions
@@ -86,8 +100,10 @@ commands.list.forEach(function (command) {
86100
this.queue.push(new Command(command, arr, callback));
87101
return this;
88102
};
89-
Object.defineProperty(Multi.prototype[command], 'name', {
90-
value: command
91-
});
103+
if (changeFunctionName) {
104+
Object.defineProperty(Multi.prototype[command], 'name', {
105+
value: command
106+
});
107+
}
92108
}
93109
});

0 commit comments

Comments
 (0)