Skip to content

Commit

Permalink
Cannot assign to read only property 'product' of object '#<WorkerNavi…
Browse files Browse the repository at this point in the history
Summary:
When running in strict mode we run into the following error:
“Cannot assign to read only property 'product' of object '#<WorkerNavigator>’”

Moreover navigator.product = ‘ReactNative’; didn’t actually change the product value. Without strict mode this was silently ignored.

By using our defineProperty function we are able to run in strict mode and now navigator.product is really ReactNative.

See facebook#10881 for more information

---------------

Long story short - if we run in strict mode, the current code throws an error :
`Cannot assign to read only property 'product' of object '#<WorkerNavigator>' initializeCore.js`
(the current version of initializeCore.js doesn't have 'use strict'; on top, but if you are unfortunate enough to have a babel module that ads this for you, you are guaranteed to run into this. Moreover our contributing guidelines say that we should have 'use strict'; https://github.com/facebook/react-native/blob/master/CONTRIB
Closes facebook#11057

Differential Revision: D4219958

Pulled By: javache

fbshipit-source-id: 35568b2ce4b87fff1aa8248f067d49e5f9f9e9a2
  • Loading branch information
compojoom authored and DanielMSchmidt committed Jan 4, 2017
1 parent 4239773 commit 694afae
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* 2. Bridged modules.
*
*/
'use strict';

if (global.GLOBAL === undefined) {
global.GLOBAL = global;
Expand Down Expand Up @@ -178,7 +179,9 @@ let navigator = global.navigator;
if (navigator === undefined) {
global.navigator = navigator = {};
}
navigator.product = 'ReactNative';

// see https://github.com/facebook/react-native/issues/10881
defineProperty(navigator, 'product', () => 'ReactNative', true);
defineProperty(navigator, 'geolocation', () => require('Geolocation'));

// Set up collections
Expand Down

0 comments on commit 694afae

Please sign in to comment.