Skip to content

Commit

Permalink
A function name is only configurable from v8 >= v.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed May 28, 2016
1 parent 25aa8f6 commit ce44213
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Features
- Updated [redis-parser](https://github.com/NodeRedis/redis-parser) dependency ([changelog](https://github.com/NodeRedis/redis-parser/releases/tag/v.2.0.0))
- The JS parser is from now on the new default as it is a lot faster than the hiredis parser
- 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.
- Added name property to all Redis functions
- Added name property to all Redis functions (Node.js >= 4.0)

Bugfixes

Expand Down
28 changes: 22 additions & 6 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ var commands = require('redis-commands');
var Multi = require('./multi');
var RedisClient = require('../').RedisClient;
var Command = require('./command');
// Feature detect if a function may change it's name
var changeFunctionName = (function () {
var fn = function abc () {};
try {
Object.defineProperty(fn, 'name', {
value: 'foobar'
});
return true;
} catch (e) {
return false;
}
}());

// TODO: Rewrite this including the invidual commands into a Commands class
// that provided a functionality to add new commands to the client
Expand Down Expand Up @@ -45,9 +57,11 @@ commands.list.forEach(function (command) {
}
return this.internal_send_command(new Command(command, arr, callback));
};
Object.defineProperty(RedisClient.prototype[command], 'name', {
value: command
});
if (changeFunctionName) {
Object.defineProperty(RedisClient.prototype[command], 'name', {
value: command
});
}
}

// Do not override existing functions
Expand Down Expand Up @@ -86,8 +100,10 @@ commands.list.forEach(function (command) {
this.queue.push(new Command(command, arr, callback));
return this;
};
Object.defineProperty(Multi.prototype[command], 'name', {
value: command
});
if (changeFunctionName) {
Object.defineProperty(Multi.prototype[command], 'name', {
value: command
});
}
}
});

0 comments on commit ce44213

Please sign in to comment.