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

Write protection should not vary between debug and prod mode #376

Open
alunny opened this issue Sep 15, 2016 · 7 comments
Open

Write protection should not vary between debug and prod mode #376

alunny opened this issue Sep 15, 2016 · 7 comments

Comments

@alunny
Copy link
Contributor

alunny commented Sep 15, 2016

Discussed briefly with @PhUU and mentioned to @lawnsea.

Right now the canWriteProtect function in utils behaves different in debug mode from production/normal mode:
https://github.com/flightjs/flight/blob/master/lib/utils.js#L12

If debug.enabled is true, mixins cannot overwrite functions from earlier mixins. Otherwise, later mixins clobber functions from earlier mixins.

This can lead to nasty bugs where a component will behave differently when debugging from production mode.

I'd like to remove the setWritability calls entirely from compose.mixin, since that's how the library behaves in production. The alternative way to eliminate the discrepancy would be to always write protect, which is much slower.

Thoughts?

@angus-c
Copy link
Contributor

angus-c commented Sep 15, 2016

If clobbering is detected in debug mode doesn't it throw an error? If it does than I think that's fine. If it doesn't then it should.

@alunny
Copy link
Contributor Author

alunny commented Sep 16, 2016

Nope, writing to a non-writable property does not throw an error. It just fails silently.

> foo = {}
{}
> foo.bar = 'hello'
'hello'
> Object.defineProperty(foo, 'bar', { writable: false })
{ bar: 'hello' }
> foo.bar = 'goodbye'
'goodbye'
> foo.bar
'hello'

@angus-c
Copy link
Contributor

angus-c commented Sep 16, 2016

We should make it error (it used to). Unless no-one cares about clobbering (but they probably should)

@alunny
Copy link
Contributor Author

alunny commented Sep 16, 2016

It looks like this behavior's been the same since the first open source commit, at least.

@angus-c
Copy link
Contributor

angus-c commented Sep 16, 2016

yeah you right, idk.

@giuseppeg
Copy link
Contributor

weird it should throw in strict mode

@alunny
Copy link
Contributor Author

alunny commented Mar 10, 2017

(long delayed response).

weird it should throw in strict mode

Yeah my mistake, I was running the node repl in sloppy mode.

That said, flight cannot control whether the code that uses it runs in strict mode or sloppy mode. So I think the problem is still valid.

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

4 participants
@alunny @angus-c @giuseppeg and others