Difference between revisions of "Talk:GM.getValue"

From GreaseSpot Wiki
Jump to navigationJump to search
m (Discussion)
 
Line 12: Line 12:


:If the desired behavior is to return undefined, it will need to be corrected in the trunk as well as a.m.o.
: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
<pre>
// ==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)
</pre>
I get:
<pre>
val: undefined
typeof(val): undefined
val==undefined: true
val===undefined: true
val==null: true
val===null: false
</pre>
I believe (but haven't tested) that [http://greasemonkey.devjavu.com/browser/trunk/src/chrome/chromeFiles/content/prefmanager.js#L36 lines 36-38] returns defaultValue (i.e undefined) and lines 50 and 52 are never executed.
<pre>
  if (prefType == pref.PREF_INVALID) {
    return defaultValue;
  }
</pre>
--[[User:Gingerhendrix|Gingerhendrix]] 21:13, 6 January 2008 (EST)

Revision as of 22:13, 6 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)