diff --git a/build.xml b/build.xml index cad1336e..f6f57c38 100644 --- a/build.xml +++ b/build.xml @@ -108,7 +108,7 @@ - + @@ -134,6 +134,7 @@ + diff --git a/dist/platform/core.js b/dist/platform/core.js index bb0ac89f..3d3ad220 100644 --- a/dist/platform/core.js +++ b/dist/platform/core.js @@ -26,6 +26,7 @@ Envjs.appCodeName = "Envjs"; //eg "Gecko/20070309 Firefox/2.0.0.3" Envjs.appName = "Resig/20070309 PilotFish/1.2.0.1"; + /* * Envjs core-env.1.2.0.0 * Pure JavaScript Browser Environment diff --git a/dist/platform/rhino.js b/dist/platform/rhino.js index 5eb02b56..6e79fe28 100644 --- a/dist/platform/rhino.js +++ b/dist/platform/rhino.js @@ -1,3 +1,11 @@ +/* + * Envjs rhino-env.1.2.0.0 + * Pure JavaScript Browser Environment + * By John Resig and the Envjs Team + * Copyright 2008-2010 John Resig, under the MIT License + */ + +var __context__ = Packages.org.mozilla.javascript.Context.getCurrentContext(); /* * Envjs rhino-env.1.2.0.0 @@ -39,6 +47,25 @@ Envjs.sleep = function(millseconds){ java.lang.Thread.currentThread().sleep(millseconds); }; +/** + * provides callback hook for when the system exits + */ +Envjs.onExit = function(callback){ + var rhino = Packages.org.mozilla.javascript, + contextFactory = __context__.getFactory(), + listener = new rhino.ContextFactory.Listener({ + contextReleased: function(context){ + if(context === __context__) + console.log('context released', context); + contextFactory.removeListener(this); + if(callback) + callback(); + } + }); + contextFactory.addListener(listener); +}; + + /** * resolves location relative to doc location * @param {Object} path diff --git a/dist/window.js b/dist/window.js index 94ad8abf..314de8e1 100644 --- a/dist/window.js +++ b/dist/window.js @@ -5,7 +5,8 @@ var Window, Screen, History, - Navigator; + Navigator, + __this__ = this; /* @@ -547,6 +548,11 @@ Window = function(scope, parent, opener){ var __windows__ = {}; +//finally pre-supply the window with the window-like environment +new Window(__this__, __this__); + + + /** * @author john resig & the envjs team * @uri http://www.envjs.com/ diff --git a/.local_settings.js b/local_settings.js similarity index 100% rename from .local_settings.js rename to local_settings.js diff --git a/src/env/__global__.js b/src/env/core/__global__.js similarity index 99% rename from src/env/__global__.js rename to src/env/core/__global__.js index 5b280a38..2911db59 100644 --- a/src/env/__global__.js +++ b/src/env/core/__global__.js @@ -25,3 +25,4 @@ var Envjs = function(){ Envjs.appCodeName = "Envjs"; //eg "Gecko/20070309 Firefox/2.0.0.3" Envjs.appName = "Resig/20070309 PilotFish/1.2.0.1"; + diff --git a/src/env/rhino/__global__.js b/src/env/rhino/__global__.js new file mode 100644 index 00000000..60002370 --- /dev/null +++ b/src/env/rhino/__global__.js @@ -0,0 +1,8 @@ +/* + * Envjs @VERSION@ + * Pure JavaScript Browser Environment + * By John Resig and the Envjs Team + * Copyright 2008-2010 John Resig, under the MIT License + */ + +var __context__ = Packages.org.mozilla.javascript.Context.getCurrentContext(); diff --git a/src/env/rhino/timer.js b/src/env/rhino/timer.js index 486127ae..343b6f49 100644 --- a/src/env/rhino/timer.js +++ b/src/env/rhino/timer.js @@ -13,3 +13,22 @@ Envjs.sync = sync; Envjs.sleep = function(millseconds){ java.lang.Thread.currentThread().sleep(millseconds); }; + +/** + * provides callback hook for when the system exits + */ +Envjs.onExit = function(callback){ + var rhino = Packages.org.mozilla.javascript, + contextFactory = __context__.getFactory(), + listener = new rhino.ContextFactory.Listener({ + contextReleased: function(context){ + if(context === __context__) + console.log('context released', context); + contextFactory.removeListener(this); + if(callback) + callback(); + } + }); + contextFactory.addListener(listener); +}; + diff --git a/src/window/__global__.js b/src/window/__global__.js index f0874bfd..97dc078c 100644 --- a/src/window/__global__.js +++ b/src/window/__global__.js @@ -5,5 +5,6 @@ var Window, Screen, History, - Navigator; + Navigator, + __this__ = this; diff --git a/src/window/window.js b/src/window/window.js index 92cffb06..557b791e 100644 --- a/src/window/window.js +++ b/src/window/window.js @@ -283,3 +283,8 @@ Window = function(scope, parent, opener){ }; var __windows__ = {}; + +//finally pre-supply the window with the window-like environment +new Window(__this__, __this__); + + diff --git a/test/specs/env/spec.js b/test/specs/env/spec.js index 4def003f..42bd5049 100644 --- a/test/specs/env/spec.js +++ b/test/specs/env/spec.js @@ -50,7 +50,8 @@ test('Envjs Platform Interfaces Available', function(){ }); -var document = null; +var document = null, + path = 'specs/env/spec.html'; test('Envjs.location', function(){ @@ -120,5 +121,9 @@ test('Envjs.proxy', function(){ }); +Envjs.onExit(function(){ + console.log('onExit!'); +}); + _start(); diff --git a/test/specs/window/spec.js b/test/specs/window/spec.js index 38c892d6..5f41dc89 100644 --- a/test/specs/window/spec.js +++ b/test/specs/window/spec.js @@ -9,8 +9,7 @@ var _load, _endtime, Envjs; -var __this__ = this, - expected_path = 'test/specs/window/spec.html'; +var expected_path = 'test/specs/window/spec.html'; try{ _load = load; @@ -27,11 +26,10 @@ try{ _load('settings.js'); _load('local_settings.js'); - //mock the window and document in envjs - new Window(__this__, __this__); document.async = false; _load('test/specs/qunit.js'); + location = SETTINGS.AJAX_BASE + expected_path; }catch(e){