Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

extend throws when run under strict mode #5

Closed
dobrite opened this issue Dec 31, 2014 · 11 comments
Closed

extend throws when run under strict mode #5

dobrite opened this issue Dec 31, 2014 · 11 comments

Comments

@dobrite
Copy link

dobrite commented Dec 31, 2014

First off let me say thanks for all your open-source work! It is because of people like you I've learned some incredible things.

I also want to say I'm not sure what to do about this, or where the fix should lie so feel free to point the finger elsewhere 😄

This issue is related to this issue in cycle.js. cycle.js runs in strict mode. This recent commit ends up assigning the name property of source to the target function object createError which is usually a no-op but throws under strict mode with at least chrome.

Uncaught TypeError: Cannot assign to read only property 'name' of function createError(opts) {
            var result = new Error()... <more>
@Raynos
Copy link
Owner

Raynos commented Dec 31, 2014

@dobrite this is why you cannot turn on global strict mode.

You must turn on strict mode at a per file level.

@dobrite
Copy link
Author

dobrite commented Dec 31, 2014

In regards to a global use strict. The code I wrote is not doing this. Should I take it up with cyclejs then?

I do feel that a utility library should adhere to strict mode, in this case skipping the name property and instead using an alternate property (_name in your case). It is already a no-op on at least chrome.

In any case thanks for the quick response and happy new year! 🎉

@Raynos
Copy link
Owner

Raynos commented Dec 31, 2014

@dobrite

Interestingly the problem you described doesn't exist in node but exists in chrome.

@Raynos
Copy link
Owner

Raynos commented Dec 31, 2014

I can reproduce the problem in node 0.11.x

still error itself doesn't use strict mode so unless you use global strict mode this shouldn't happen.

For example

> function foo() { 'use strict'; function g() {}; g.name = 'bar'; return g; }
undefined
> foo()
TypeError: Cannot assign to read only property 'name' of function g() {}
    at foo (repl:1:56)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:130:27)
    at bound (domain.js:257:14)
    at REPLServer.runBound [as eval] (domain.js:270:12)
    at REPLServer.<anonymous> (repl.js:277:12)
    at REPLServer.EventEmitter.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:202:10)
    at REPLServer.Interface._line (readline.js:531:8)
    at REPLServer.Interface._ttyWrite (readline.js:812:14)
> function foo() { function g() {}; g.name = 'bar'; return g; }
undefined
> foo()
[Function: g]
> function fab() { 'use strict'; return foo(); }
undefined
> fab()
[Function: g]

@dobrite
Copy link
Author

dobrite commented Dec 31, 2014

I updated my comment above (sorry). Since it already is a no-op on Chrome error and extend shouldn't rely on it working. Perhaps skip the name property with extend? That way strict doesn't throw and _name is set for whatever nefarious purposes you have 😁

@Raynos
Copy link
Owner

Raynos commented Dec 31, 2014

@dobrite I can skip the name property but that requires an extra copy and a delete.

I'm taking advantage of the fact that assigning name is a no-op so I dont have to write more code or do more copies.

@Raynos
Copy link
Owner

Raynos commented Dec 31, 2014

@dobrite how exactly are you using webpack and cycle together ?

@dobrite
Copy link
Author

dobrite commented Dec 31, 2014

It's just cyclejs''s README code and a minimal package.json and webpack config to get it going.

I have to run out the door but I'll throw up a repo later. cheers!

@Raynos
Copy link
Owner

Raynos commented Dec 31, 2014

Might be related to Raynos/xtend#25

@staltz
Copy link

staltz commented Dec 31, 2014

I think webpack might be enforcing a global 'use strict' then. Cycle.js doesn't do that, it uses strict per file only.

@dobrite
Copy link
Author

dobrite commented Dec 31, 2014

So the issue was es6-loader in the webpack config I was using. es6-loader uses es6-module-transpiler and es6-transpiler, the former of which enforces use strict on es6 modules. A few different threads turned up that es6 modules, by definition, always enforce strict semantics (TIL!).

I think I can get by with excluding node_modules from es6-loader.

I apologize for the issues as it ultimately was not your libraries. Thank you both for your help! Cheers 🍻

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

No branches or pull requests

3 participants