Talk:GM.getValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
Marti (talk | contribs)
m Reply and question for Gingerhendrix :)
Line 51: Line 51:


--[[User:Gingerhendrix|Gingerhendrix]] 21:13, 6 January 2008 (EST)
--[[User:Gingerhendrix|Gingerhendrix]] 21:13, 6 January 2008 (EST)
LOL We're both correct here.:) In your test case it will return undefined because no default value was supplied... however in my test case here it will return null because I made sure that the value stored wasn't a string, int or boolean.<br />
<strong>Do you think this is worth a trouble ticket for devjavu?</strong><br />
[[User:Marti|Marti]]

Revision as of 05:37, 7 January 2008

[1]

Ref: 0.7.20070607.0 Release on a.m.o prefmanager.js
Line 49 return null;
Ref: Current trunk as of 2007 01 03 prefmanager.js
Line 52 return null;
There is a difference between null and undefined.
null is an object (e.g. alert(typeof(null));)
undefined has no memory allocated (e.g. alert(typeof(undefined));)
If the desired behavior is to return undefined, it will need to be corrected in the trunk as well as a.m.o.

Try something along the lines of

// ==UserScript==
// @name          GetSetValueTest
// @description   Tests the behaviour of gm_getValue for a missing property
// @include       http://www.example.com/
// ==/UserScript==

var val = GM_getValue("missingProperty");
var msg = "val: " + val + "\n"
     + "typeof(val): " + typeof(val) + "\n"
     + "val==undefined: " + (val==undefined) + "\n"
     + "val===undefined: " + (val===undefined) + "\n"
     + "val==null: " + (val==null) + "\n"
     + "val===null: " + (val===null) + "\n";
alert(msg)

I get:

val: undefined 
typeof(val): undefined 
val==undefined: true 
val===undefined: true 
val==null: true 
val===null: false

I believe (but haven't tested) that lines 36-38 returns defaultValue (i.e undefined) and lines 50 and 52 are never executed.

  if (prefType == pref.PREF_INVALID) {
    return defaultValue;
  }

--Gingerhendrix 21:13, 6 January 2008 (EST)


LOL We're both correct here.:) In your test case it will return undefined because no default value was supplied... however in my test case here it will return null because I made sure that the value stored wasn't a string, int or boolean.
Do you think this is worth a trouble ticket for devjavu?
Marti