Skip to content

Commit

Permalink
Fix promisifiy giving a function an invalid identifier as a name
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Apr 27, 2014
1 parent 60995e5 commit 968df84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/promisify.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ function parameterCount(fn) {
return 0;
}

var rident = /^[a-z$_][a-z$_0-9]*$/i;
function propertyAccess(id) {
var rident = /^[a-z$_][a-z$_0-9]*$/i;

if (rident.test(id)) {
return "." + id;
}
Expand Down Expand Up @@ -161,6 +160,10 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn) {
"break;";
}

if (!rident.test(callbackName)) {
callbackName = "promisified";
}

function generateArgumentSwitchCase() {
var ret = "";
for(var i = 0; i < argumentOrder.length; ++i) {
Expand Down
2 changes: 2 additions & 0 deletions test/mocha/promisify.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ describe( "Promisify from prototype to object", function() {

};

method["---invalid---"] = function(){};

if ((function(){"use strict"; return this === void 0})()) {
Object.defineProperty(method, "thrower", {
enumerable: true,
Expand Down

0 comments on commit 968df84

Please sign in to comment.