From df40e54bbf0d290f564ea2fd94c5f2e65de6ae4d Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 26 Apr 2018 01:01:31 +1200 Subject: [PATCH] fix assignment to readonly property to allow running in strict mode (#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. --- lib/v35.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/v35.js b/lib/v35.js index 842c60ea..1f05d38d 100644 --- a/lib/v35.js +++ b/lib/v35.js @@ -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';