<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Global_object</title><link>https://sourceforge.net/p/greasemonkey/wiki/Global_object/</link><description>Recent changes to Global_object</description><atom:link href="https://sourceforge.net/p/greasemonkey/wiki/Global_object/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 05 Aug 2019 09:51:19 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/greasemonkey/wiki/Global_object/feed" rel="self" type="application/rss+xml"/><item><title>Global_object modified by mmartz</title><link>https://sourceforge.net/p/greasemonkey/wiki/Global_object/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v3
+++ v4
@@ -18,7 +18,7 @@

 A Greasemonkey [User script](User_script), however, by default wraps up all code inside an anonymous function wrapper that swallows identifiers, causing them not to end up on the global object. The useful effect of this wrapper is to protect user scripts from global identifiers in the Greasemonkey sandbox that might otherwise collide with yours and make it not work *(yielding unhelpful errors such as "invalid value")*.

-Historically it was also a measure to not unwittingly pollute the window object. [0.8.0](Version_history#0.8.20080609.0) removed it and [0.8.1](Version_history#0.8.20090123.1) re-added it by default, unless the script wright disables it manually using [@unwrap](Metadata_Block#unwrap). In the context of such a *user script*, the *special operator* [this](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this) acts as *"the global object is passed as the context object"*, which behind the scenes is also linked to the `window` object, which is in turn a [XPCNativeWrapper](XPCNativeWrapper) wrapped version of [unsafeWindow](unsafeWindow) - the window of the *user script's* target page. 
+Historically it was also a measure to not unwittingly pollute the window object. [0.8.0](Version_history#08200806090) removed it and [0.8.1](Version_history#08200901231) re-added it by default, unless the script wright disables it manually using [@unwrap](Metadata_Block#unwrap). In the context of such a *user script*, the *special operator* [this](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this) acts as *"the global object is passed as the context object"*, which behind the scenes is also linked to the `window` object, which is in turn a [XPCNativeWrapper](XPCNativeWrapper) wrapped version of [unsafeWindow](unsafeWindow) - the window of the *user script's* target page. 

 ### Debugging

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mmartz</dc:creator><pubDate>Mon, 05 Aug 2019 09:51:19 -0000</pubDate><guid>https://sourceforge.net4fe9409842a637359d3c70386d949e562feba275</guid></item><item><title>Global_object modified by Martz</title><link>https://sourceforge.net/p/greasemonkey/wiki/Global_object/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -18,14 +18,14 @@

 A Greasemonkey [User script](User_script), however, by default wraps up all code inside an anonymous function wrapper that swallows identifiers, causing them not to end up on the global object. The useful effect of this wrapper is to protect user scripts from global identifiers in the Greasemonkey sandbox that might otherwise collide with yours and make it not work *(yielding unhelpful errors such as "invalid value")*.

-Historically it was also a measure to not unwittingly pollute the window object. [0.8.0](Version_history#0.8.20080609.0) removed it and [0.8.1](Version_history#0.8.20090123.1) re-added it by default, unless the script wright disables it manually using [@unwrap](Greasemonkey_Manual:Metadata_Block#unwrap). In the context of such a *user script*, the *special operator* [this](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this) acts as *"the global object is passed as the context object"*, which behind the scenes is also linked to the `window` object, which is in turn a [XPCNativeWrapper](XPCNativeWrapper) wrapped version of [unsafeWindow](unsafeWindow) - the window of the *user script's* target page. 
+Historically it was also a measure to not unwittingly pollute the window object. [0.8.0](Version_history#0.8.20080609.0) removed it and [0.8.1](Version_history#0.8.20090123.1) re-added it by default, unless the script wright disables it manually using [@unwrap](Metadata_Block#unwrap). In the context of such a *user script*, the *special operator* [this](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this) acts as *"the global object is passed as the context object"*, which behind the scenes is also linked to the `window` object, which is in turn a [XPCNativeWrapper](XPCNativeWrapper) wrapped version of [unsafeWindow](unsafeWindow) - the window of the *user script's* target page. 

 ### Debugging

 One consequence of being unable to access a *user script's global object* is that [debuggers and inspectors](Greasemonkey_Manual%3AOther_Useful_Tools) are unable to see anything in a *user script*. In order to inspect a data structure in the script's scope it can be temporarily added to `unsafeWindow`. e.g. `unsafeWindow.myScriptMyStruct = myStruct;`.

-With the [@unwrap](Greasemonkey_Manual:Metadata_Block#unwrap) header in place, you can export the whole global object in this fashion, which lets you inspect the whole running context of the script using such tools: 
+With the [@unwrap](Metadata_Block#unwrap) header in place, you can export the whole global object in this fashion, which lets you inspect the whole running context of the script using such tools: 

 ~~~~~~
 // ==UserScript==
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martz</dc:creator><pubDate>Sun, 10 Aug 2014 06:43:50 -0000</pubDate><guid>https://sourceforge.net16dd2224f6e3f16fb4cac14353c21d3a5ea7f0d3</guid></item><item><title>Global_object modified by Martz</title><link>https://sourceforge.net/p/greasemonkey/wiki/Global_object/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,51 +1,40 @@
 ## Overview

-In JavaScript, top-level functions and global variables are stored as properties of the [global object](http://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#Global_Variables). For a script on a webpage, the global object is the page's [window](http://developer.mozilla.org/en/docs/DOM:window), and thus functions or variables like 
+In JavaScript, top-level functions and global variables are stored as properties of the [global object](http://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#Global_Variables). For a script on a webpage, the global object is the page's [window](https://developer.mozilla.org/docs/Web/API/Window), and thus functions or variables like 

-    V = "V's value";
-    function F(){return "F's value"};
+~~~~~~
+V = "V's value";
+function F() {
+  return "F's value"
+};
+~~~~~~

+can be looked up through `window`. This gives the equivalences: 

-can be looked up through 
-    
-    window
+~~~~~~    
+(V == window.V) &amp;amp;&amp;amp; (V == window['V'])
+(F == window.F) &amp;amp;&amp;amp; (F == window['F'])
+~~~~~~    

-. This gives the equivalences: 
-    
-    (V == window.V) &amp;amp;&amp;amp; (V == window['V'])
-    (F == window.F) &amp;amp;&amp;amp; (F == window['F'])
-    
+A Greasemonkey [User script](User_script), however, by default wraps up all code inside an anonymous function wrapper that swallows identifiers, causing them not to end up on the global object. The useful effect of this wrapper is to protect user scripts from global identifiers in the Greasemonkey sandbox that might otherwise collide with yours and make it not work *(yielding unhelpful errors such as "invalid value")*.

-A Greasemonkey [User_script], however, by default wraps up all code inside an anonymous function wrapper that swallows identifiers, causing them not to end up on the global object. The useful effect of this wrapper is to protect user scripts from global identifiers in the Greasemonkey sandbox that might otherwise collide with yours and make it not work (yielding unhelpful errors such as "invalid value"). 
-
-Historically it was also a measure to not unwittingly pollute the window object. [0.8.0](Version_history#0.8.20080609.0) removed it and [0.8.1](Version_history#0.8.20090123.1) re-added it by default, unless the script wright disables it manually using [@unwrap](Greasemonkey_Manual:Metadata_Block#.40unwrap). In the context of such a _user script_, the _special operator_ [this](http://developer.mozilla.org/en/JavaScript/Reference/Operators/Special/this) acts as _"the global object is passed as the context object"_, which behind the scenes is also linked to the 
-    
-    window
-
-object, which is in turn a [XPCNativeWrapper] wrapped version of [UnsafeWindow] - the window of the _user script's_ target page. 
+Historically it was also a measure to not unwittingly pollute the window object. [0.8.0](Version_history#0.8.20080609.0) removed it and [0.8.1](Version_history#0.8.20090123.1) re-added it by default, unless the script wright disables it manually using [@unwrap](Greasemonkey_Manual:Metadata_Block#unwrap). In the context of such a *user script*, the *special operator* [this](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this) acts as *"the global object is passed as the context object"*, which behind the scenes is also linked to the `window` object, which is in turn a [XPCNativeWrapper](XPCNativeWrapper) wrapped version of [unsafeWindow](unsafeWindow) - the window of the *user script's* target page. 

 ### Debugging

-One consequence of being unable to access a _user script's_ _global object_ is that [debuggers and inspectors](Useful_Tools_for_Script_Writers) are unable to see anything in a _user script_. In order to inspect a data structure in the script's scope it can be temporarily added to 
-    
-    unsafeWindow
-
-. E.g.: 
-    
-    unsafeWindow.myScriptMyStruct = myStruct;
+One consequence of being unable to access a *user script's global object* is that [debuggers and inspectors](Greasemonkey_Manual%3AOther_Useful_Tools) are unable to see anything in a *user script*. In order to inspect a data structure in the script's scope it can be temporarily added to `unsafeWindow`. e.g. `unsafeWindow.myScriptMyStruct = myStruct;`.

-With the [@unwrap](Greasemonkey_Manual:Metadata_Block#.40unwrap) header in place, you can export the whole global object in this fashion, which lets you inspect the whole running context of the script using such tools: 
+With the [@unwrap](Greasemonkey_Manual:Metadata_Block#unwrap) header in place, you can export the whole global object in this fashion, which lets you inspect the whole running context of the script using such tools: 

-    // ==UserScript==
-    // ...
-    // @unwrap
-    // ==/UserScript==
+~~~~~~
+// ==UserScript==
+// ...
+// @unwrap
+// ==/UserScript==

-    unsafeWindow.myScript = this;
-    
+unsafeWindow.myScript = this;
+~~~~~~    

 **After debugging this sort of binding should be removed to avoid security and scope related problems.**
-
-[Category:Scripting_context] 
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martz</dc:creator><pubDate>Sun, 10 Aug 2014 06:41:33 -0000</pubDate><guid>https://sourceforge.net6716b5abe98cdbee32f7bf2a200230da62f6ce75</guid></item><item><title>Global_object modified by Martz</title><link>https://sourceforge.net/p/greasemonkey/wiki/Global_object/</link><description>&lt;div class="markdown_content"&gt;&lt;h2 id="overview"&gt;Overview&lt;/h2&gt;
&lt;p&gt;In JavaScript, top-level functions and global variables are stored as properties of the &lt;a class="" href="http://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#Global_Variables" rel="nofollow"&gt;global object&lt;/a&gt;. For a script on a webpage, the global object is the page's &lt;a class="" href="http://developer.mozilla.org/en/docs/DOM:window" rel="nofollow"&gt;window&lt;/a&gt;, and thus functions or variables like &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="nx"&gt;V&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;V's value&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;F's value&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;can be looked up through &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;window&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;. This gives the equivalences: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sc"&gt;'V'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sc"&gt;'F'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A Greasemonkey &lt;a class="alink" href="/p/greasemonkey/wiki/User_script/"&gt;[User_script]&lt;/a&gt;, however, by default wraps up all code inside an anonymous function wrapper that swallows identifiers, causing them not to end up on the global object. The useful effect of this wrapper is to protect user scripts from global identifiers in the Greasemonkey sandbox that might otherwise collide with yours and make it not work (yielding unhelpful errors such as "invalid value"). &lt;/p&gt;
&lt;p&gt;Historically it was also a measure to not unwittingly pollute the window object. &lt;a class="" href="../Version_history#0.8.20080609.0"&gt;0.8.0&lt;/a&gt; removed it and &lt;a class="" href="../Version_history#0.8.20090123.1"&gt;0.8.1&lt;/a&gt; re-added it by default, unless the script wright disables it manually using &lt;a class="" href="../Greasemonkey_Manual:Metadata_Block#.40unwrap"&gt;@unwrap&lt;/a&gt;. In the context of such a &lt;em&gt;user script&lt;/em&gt;, the &lt;em&gt;special operator&lt;/em&gt; &lt;a class="" href="http://developer.mozilla.org/en/JavaScript/Reference/Operators/Special/this" rel="nofollow"&gt;this&lt;/a&gt; acts as &lt;em&gt;"the global object is passed as the context object"&lt;/em&gt;, which behind the scenes is also linked to the &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;window&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;object, which is in turn a &lt;a class="alink" href="/p/greasemonkey/wiki/XPCNativeWrapper/"&gt;[XPCNativeWrapper]&lt;/a&gt; wrapped version of &lt;a class="alink" href="/p/greasemonkey/wiki/UnsafeWindow/"&gt;[UnsafeWindow]&lt;/a&gt; - the window of the &lt;em&gt;user script's&lt;/em&gt; target page. &lt;/p&gt;
&lt;h3 id="debugging"&gt;Debugging&lt;/h3&gt;
&lt;p&gt;One consequence of being unable to access a &lt;em&gt;user script's&lt;/em&gt; &lt;em&gt;global object&lt;/em&gt; is that &lt;a class="" href="../Useful_Tools_for_Script_Writers"&gt;debuggers and inspectors&lt;/a&gt; are unable to see anything in a &lt;em&gt;user script&lt;/em&gt;. In order to inspect a data structure in the script's scope it can be temporarily added to &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;unsafeWindow&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;. E.g.: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;unsafeWindow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;myScriptMyStruct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myStruct&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With the &lt;a class="" href="../Greasemonkey_Manual:Metadata_Block#.40unwrap"&gt;@unwrap&lt;/a&gt; header in place, you can export the whole global object in this fashion, which lets you inspect the whole running context of the script using such tools: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// ==UserScript==&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="c1"&gt;// @unwrap&lt;/span&gt;
&lt;span class="c1"&gt;// ==/UserScript==&lt;/span&gt;

&lt;span class="n"&gt;unsafeWindow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;myScript&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After debugging this sort of binding should be removed to avoid security and scope related problems.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[Category:Scripting_context]&lt;/span&gt; &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martz</dc:creator><pubDate>Fri, 27 Jun 2014 23:42:41 -0000</pubDate><guid>https://sourceforge.net094adac9e18971f21c0270909d54b10d670061fb</guid></item></channel></rss>