Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can't run with --use_strict due to assignment of read-only function.name property in v35.js #268

Closed
G-Rath opened this issue Apr 5, 2018 · 2 comments

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Apr 5, 2018

https://github.com/kelektiv/node-uuid/blob/17d443f7d8cfb65a7d85803218df27a6b4ae8397/lib/v35.js#L46

The above line is assigning to a read-only variable, which is a violation when running in strict mode (via Node's --use_strict argument).

Outside of strict mode, this doesn't actually result in the function name being changed anyway, as assignments to Function.name are ignored.

There are other ways to change the name of a function that hopefully would work.

If I comment that line out, everything works fine, with no other errors.

@broofa
Copy link
Member

broofa commented Apr 5, 2018

Interesting! I wasn't aware of that read-only limitation.

FWIW, it looks like defineProperty will work. See below.

defineProperty is broadly supported enough I'd be willing to take a PR with that change.

kieffer@RWK-Mac-2017$ node --use-strict
> function foo() {}
undefined
> foo.name
'foo'
> foo.name='bar'
TypeError: Cannot assign to read only property 'name' of function 'function foo() {}'
    at repl:1:9
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)
    at REPLServer.Interface._line (readline.js:590:8)
> Object.defineProperty(foo, 'name', {value: 'bar'})
[Function: bar]
> foo.name
'bar'

@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 5, 2018

@broofa awesome, that's what I was thinking too - I'll make a PR in a couple of hours when I get to work :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants