Closed Bug 872983 Opened 11 years ago Closed 11 years ago

event.settingValue in mozSettings.onsettingchange gives wrong value

Categories

(Firefox OS Graveyard :: General, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(blocking-b2g:leo+, firefox22 wontfix, firefox23 wontfix, firefox24 fixed, b2g18 fixed, b2g18-v1.0.0 wontfix, b2g18-v1.0.1 wontfix, b2g-v1.1hd fixed)

RESOLVED FIXED
blocking-b2g leo+
Tracking Status
firefox22 --- wontfix
firefox23 --- wontfix
firefox24 --- fixed
b2g18 --- fixed
b2g18-v1.0.0 --- wontfix
b2g18-v1.0.1 --- wontfix
b2g-v1.1hd --- fixed

People

(Reporter: johnhu, Assigned: gwagner)

References

Details

Attachments

(1 file)

While putting an array of object to mozSettings, the event.settingValue of onsettingchange event gives wrong value. It just removes all properties of those objects.

I did a simple test on this issue with the following code:
      if (event.settingName === 'test.key')
      console.log('onsettingchange: ' + JSON.stringify(event.settingValue));
    };
    var cset = [{'a':'b','c':[{'d':'e'}]}];
    console.log('set: ' + JSON.stringify(cset));
    navigator.mozSettings.createLock().set({'test.key': cset});

And the console outputs: 

E/GeckoConsole( 1031): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:115 in settings_init: set: [{"a":"b","c":[{"d":"e"}]}]
E/GeckoConsole( 1031): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:112 in anonymous: onsettingchange: [{}]

But, if we use mozSettings.createLock().get('test.key'), it gives the correct value, [{"a":"b","c":[{"d":"e"}]}].
Sorry, above code is incomplete. 

Please use the following code:

    navigator.mozSettings.onsettingchange = function(event) {
      if (event.settingName === 'test.key')
      console.log('onsettingchange: ' + JSON.stringify(event.settingValue));
    };
    var cset = [{"a":"b","c":[{"d":"e"}]}];
    console.log('set: ' + JSON.stringify(cset));
    navigator.mozSettings.createLock().set({'test.key': cset});
JSON.stringify often lies to you in such cases. Can you try to access/print the "a"property directly?
Gregor, 

Sure, here they are:

New version of testing code:
    navigator.mozSettings.onsettingchange = function(event) {
      if (event.settingName === 'test.key') {
        console.log('onsettingchange: a property: ' + event.settingValue[0]['a']);
        console.log('onsettingchange: c property: ' + event.settingValue[0]['c']);
      }
    };
    var cset = [{'a':'b','c':[{'d':'e'}]}];
    console.log('set: ' + JSON.stringify(cset));
    navigator.mozSettings.createLock().set({'test.key': cset});

logcat result:

E/GeckoConsole( 1226): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:117 in settings_init: set: [{"a":"b","c":[{"d":"e"}]}]
E/GeckoConsole( 1226): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:112 in anonymous: onsettingchange: a property: undefined
E/GeckoConsole( 1226): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:113 in anonymous: onsettingchange: c property: undefined

I had tested this in Inari, Unagi, and Leo with b2g18. They all gave me the same result.
Does it work if you do .get('test.key')?
Reuben, 

Yes. It works if I use get('test.key').

I found this bug because we want to make a memory copy of our settings to prevent multiple querying on mozSettings. Most of them works, but this case, an array of object, doesn't. So, we have to change our code to use get('xxxxxxx');
The improvement John described was made in bug 840322. It looks like the settings cache fails in this case.
Attached patch patchSplinter Review
Another expose issue...
Thanks for finding!
Assignee: nobody → anygregor
John, can you try this patch?
Gregor, 

Sorry, it doesn't works. It gives another error about this patch. I am not sure if this is my problem on Gecko version.

E/GeckoConsole(  641): [JavaScript Error: "this._wrap is not a function" {file: "jar:file:///system/b2g/omni.ja!/components/SettingsManager.js" line: 318}]

my gecko version: dd60c168dc409bc44196d86907dcfef84c7367fb
blocking-b2g: --- → leo?
Depends on: 849616
(In reply to John Hu [:johnhu] from comment #9)
> Gregor, 
> 
> Sorry, it doesn't works. It gives another error about this patch. I am not
> sure if this is my problem on Gecko version.
> 
> E/GeckoConsole(  641): [JavaScript Error: "this._wrap is not a function"
> {file: "jar:file:///system/b2g/omni.ja!/components/SettingsManager.js" line:
> 318}]
> 
> my gecko version: dd60c168dc409bc44196d86907dcfef84c7367fb

You need the patch from bug 849616 as well.
Don't we all love this branching mess.
Gregor, 

Great, it works now, see:

E/GeckoConsole(  640): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:112 in anonymous: onsettingchange: [{"a":"b","c":[{"d":"e"}]}]
E/GeckoConsole(  640): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:113 in anonymous: onsettingchange: a property: b
E/GeckoConsole(  640): Content JS LOG at app://settings.gaiamobile.org/js/settings.js:114 in anonymous: onsettingchange: c property: [object Object]
Blocking based on developer impact and the fact that we're close to a fix.
blocking-b2g: leo? → leo+
Attachment #750847 - Flags: review+
Note that the patch in bug 849616 needs to be uplifted first.
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/603891a7c4b1
Status: NEW → RESOLVED
Closed: 11 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Flags: in-moztrap-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: