Talk:GM.getValue

From GreaseSpot Wiki
Revision as of 02:13, 7 January 2008 by Gingerhendrix (talk | contribs)
Jump to navigationJump to search

[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)