Skip to content

Commit 74d4207

Browse files
committed
migrate tested global variable of commonjs environment from window to env.
eliminates problems with garbage collection after iframe is deleted
1 parent e56fcd1 commit 74d4207

8 files changed

+19
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clientside-require",
3-
"version": "4.6.1",
3+
"version": "4.7.1",
44
"description": "Node.js style require() statements in the browser. Load npm modules, js, html, css, json without any bundling.",
55
"main": "src/index.js",
66
"bundle": "dist/bundle.js",

src/utilities/content_loading/commonjs.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
frame.contentWindow.clientside_require = window.clientside_require; // pass by reference the clientside_require object
6666
frame.contentWindow.root_window = window; // pass the root window (browser window) to the module so it can use it if needed
6767
frame.contentWindow.load = load_function; // inject the load function
68+
frame.contentWindow.env = frame.contentWindow; // pass the window property of the iframe as the env property
6869
},
6970
browser_variables : function(frame, path){ // browser environment variables (those not present in iframes)
7071
frame.contentWindow.console = window.console; // pass the console functionality
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = window.clientside_require;
1+
module.exports = env.clientside_require;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = env;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = window.load;
1+
module.exports = env.load;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = window.script_location;
1+
module.exports = env.script_location;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = window.require;
1+
module.exports = env.require;

test/utilities/content_loading/commonjs.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var test_paths = {
66
js_commonjs : "file:///"+ process.env.test_env_root + "/basic_content/test_js_commonjs.js",
77
reference_clientside_require : "file:///"+ process.env.test_env_root + "/test_js/reference_clientside_require_in_module.js",
88
reference_window : "file:///"+ process.env.test_env_root + "/test_js/reference_window_in_module.js",
9+
reference_env : "file:///"+ process.env.test_env_root + "/test_js/reference_env_in_module.js",
910
reference_load : "file:///"+ process.env.test_env_root + "/test_js/reference_load_in_module.js",
1011
reference_require : "file:///"+ process.env.test_env_root + "/test_js/reference_require_in_module.js",
1112
reference_root_window : "file:///"+ process.env.test_env_root + "/test_js/reference_root_window_in_module.js",
@@ -74,28 +75,34 @@ describe('commonjs', function(){
7475
assert.equal(typeof exports, "object", "window should be defined");
7576
assert.equal(typeof exports.document, "object", "window.document should be defined");
7677
})
77-
it("should define window.clientside_require in the modules environment", async function(){
78+
it('should define env in the modules environment', async function(){
79+
var commonjs_loader = require(process.env.src_root + "/utilities/content_loading/commonjs.js");
80+
var exports = await commonjs_loader.promise_to_retreive_exports(test_paths.reference_env, "async");
81+
assert.equal(typeof exports, "object", "env should be defined");
82+
assert.equal(typeof exports.document, "object", "env.document should be defined");
83+
})
84+
it("should define env.clientside_require in the modules environment", async function(){
7885
var commonjs_loader = require(process.env.src_root + "/utilities/content_loading/commonjs.js");
7986
var exports = await commonjs_loader.promise_to_retreive_exports(test_paths.reference_clientside_require, "async");
8087
assert.equal(typeof exports, "object", "window.clientside_require should be defined");
8188
assert.equal(typeof exports.asynchronous_require, "function", "window.clientside_require.asynchronous_require should be defined");
8289
})
83-
it('should define window.require in the modules environment', async function(){
90+
it('should define env.require in the modules environment', async function(){
8491
var commonjs_loader = require(process.env.src_root + "/utilities/content_loading/commonjs.js");
8592
var exports = await commonjs_loader.promise_to_retreive_exports(test_paths.reference_load, "async");
8693
assert.equal(typeof exports, "function", "require method should be defined");
8794
})
88-
it('should define window.load in the modules environment', async function(){
95+
it('should define env.load in the modules environment', async function(){
8996
var commonjs_loader = require(process.env.src_root + "/utilities/content_loading/commonjs.js");
9097
var exports = await commonjs_loader.promise_to_retreive_exports(test_paths.reference_require, "async");
9198
assert.equal(typeof exports, "function", "load method should be defined");
9299
})
93-
it('should define window.root_window in the modules environment', async function(){
100+
it('should define env.root_window in the modules environment', async function(){
94101
var commonjs_loader = require(process.env.src_root + "/utilities/content_loading/commonjs.js");
95102
var exports = await commonjs_loader.promise_to_retreive_exports(test_paths.reference_root_window, "async");
96103
assert.equal(typeof exports, "object", "root_window should be defined");
97104
})
98-
it('should define window.location in the modules environment accurately', async function(){
105+
it('should define env.location in the modules environment accurately', async function(){
99106
var commonjs_loader = require(process.env.src_root + "/utilities/content_loading/commonjs.js");
100107
var exports = await commonjs_loader.promise_to_retreive_exports(test_paths.reference_location, "async");
101108
assert.equal(typeof exports, "object", "location should be defined");

0 commit comments

Comments
 (0)