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

Object.assign does not throw error when assign value to non-writable property. #22519

Closed
krave1986 opened this issue Dec 5, 2018 · 2 comments
Labels
Bug Resolution: Locked This issue was locked by the bot.

Comments

@krave1986
Copy link

krave1986 commented Dec 5, 2018

Environment

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Memory: 779.73 MB / 7.91 GB
Binaries:
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5056338

Reproducible Demo

var target = Object.defineProperty({}, 'foo', {value: 1, writable: false});
Object.assign(target, {foo: 2});

Description

As illustrated on MDN doc and according to the behavior of latest version of chomr, when trying to assign a property which is non-writable in target from source to target, Object.assign should throw a TypeError like:

TypeError: Cannot assign to read only property 'foo' of object '#'

@lemiesz
Copy link

lemiesz commented Dec 6, 2018

Hmm so I just tried this out, and although it does not throw an error in the React runtime.
It fails silently and the value of target.foo = 1.

What is interesting is that I would expect this to throw an error in the debugger regardless. Since all the debugger code is suppose to run in chrome

But maybe this is not a bug, as we are not using the chrome engine?

@Salakar
Copy link
Contributor

Salakar commented Mar 19, 2019

@krave1986 thanks for raising this issue 🎉

I can confirm that since the new JSC landed on Android (RN v0.59.x) this now behaves correctly and throws a valid error.

@Salakar Salakar closed this as completed Mar 19, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants