Skip to content

Commit

Permalink
fix: assignment to readonly property to allow running in strict mode (#…
Browse files Browse the repository at this point in the history
…270)

* Replaced assignment to readonly Function.name with Object.defineProperty, as you can't assign to readonly properties in strict mode.

* added check to make sure the name property is configurable before trying to configure it.

This should allow compatibility with both strict mode and non-standard, pre-ES2015 implementations, such as in node 0.12.x

* Removed extra blank newline.
  • Loading branch information
G-Rath authored and broofa committed Jun 22, 2018
1 parent c47702c commit d062fdc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/v35.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ module.exports = function(name, version, hashfunc) {
return buf || bytesToUuid(bytes);
};

generateUUID.name = name;
// only attempt to set the name if's configurable (which it should be on node > 0.12)
if (Object.getOwnPropertyDescriptor(generateUUID, 'name').configurable) {
Object.defineProperty(generateUUID, 'name', {value: name});
}

// Pre-defined namespaces, per Appendix C
generateUUID.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
Expand Down

0 comments on commit d062fdc

Please sign in to comment.