Skip to content

Commit c76c0de

Browse files
committed
Merge pull request #427 from mnphnic/expose_to_global
Expose useful variable(userContext, NS, etc...) to Global-scope.
2 parents 66e29f8 + 3d9c4a9 commit c76c0de

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

common/content/liberator.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
Cu.import("resource://gre/modules/XPCOMUtils.jsm", modules);
1010
Cu.import("resource://gre/modules/AddonManager.jsm")
1111

12-
const plugins = { __proto__: modules };
13-
const userContext = { __proto__: modules };
12+
// Use the `liberator.plugins` in place of the `plugins`.
13+
const plugins = Object.create(modules);
14+
15+
// Expose userContext to Global-scope.
16+
Object.defineProperty(modules, "userContext", {
17+
value: Object.create(modules),
18+
enumerable: true,
19+
writeable: true
20+
});
1421

1522
const EVAL_ERROR = "__liberator_eval_error";
1623
const EVAL_RESULT = "__liberator_eval_result";

common/content/util.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,34 @@
55

66
/** @scope modules */
77

8-
const {XHTML, XUL, NS} = (function () {
8+
(function () {
99
function Namespace(prefix, uri) {
1010
this.prefix = prefix;
1111
this.uri = uri;
1212
}
1313
Namespace.prototype.toString = function toString() { return this.uri; };
14-
return {
15-
XHTML: new Namespace("html", "http://www.w3.org/1999/xhtml"),
16-
XUL : new Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"),
17-
NS : new Namespace("liberator", "http://vimperator.org/namespaces/liberator"),
18-
};
14+
15+
// Expose XHTML,XUL,NS to Global-scope.
16+
Object.defineProperties(modules, {
17+
XHTML: {
18+
value: Object.freeze(
19+
new Namespace("html", "http://www.w3.org/1999/xhtml")
20+
),
21+
enumerable: true
22+
},
23+
XUL: {
24+
value: Object.freeze(
25+
new Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul")
26+
),
27+
enumerable: true
28+
},
29+
NS: {
30+
value: Object.freeze(
31+
new Namespace("liberator", "http://vimperator.org/namespaces/liberator")
32+
),
33+
enumerable: true
34+
}
35+
});
1936
})();
2037

2138
let Encoder = Components.Constructor("@mozilla.org/layout/documentEncoder;1?type=text/plain", "nsIDocumentEncoder", "init");

0 commit comments

Comments
 (0)