Skip to content

Commit d062fdc

Browse files
G-Rathbroofa
authored andcommitted
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.
1 parent c47702c commit d062fdc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/v35.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ module.exports = function(name, version, hashfunc) {
4343
return buf || bytesToUuid(bytes);
4444
};
4545

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

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

0 commit comments

Comments
 (0)