From 99b54cdc991a652b709123aa4643ba4fb9e226f1 Mon Sep 17 00:00:00 2001 From: ketmar Date: Fri, 7 Aug 2015 16:27:43 +0000 Subject: [PATCH] more xpcshell unifications FossilOrigin-Name: 4a4e797a54fd719c0d024b674c1e08780d3ca77d92f8d72629454322844c5bdb --- includes/basic.js | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/includes/basic.js b/includes/basic.js index f1a91e9..8fa6559 100644 --- a/includes/basic.js +++ b/includes/basic.js @@ -111,7 +111,10 @@ function logException (msg, e) { function addExport (name, fn) { if (typeof(name) != "string" || name.length == 0) throw new Error("invalid export name"); - if (typeof(fn) === null || typeof(fn) == "undefined") { + if (typeof(fn) === "undefined") { + // only one operand, this must be function name + exportList[name] = name; + } else if (typeof(fn) === null) { // remove export delete exportList[name]; } else { @@ -120,19 +123,31 @@ function logException (msg, e) { } global.addExport = addExport; - addExport("Cu", global.Cu); - addExport("Cc", global.Cc); - addExport("Ci", global.Ci); - addExport("Services", global.Services); - - addExport("logException", global.logException); - addExport("logError", global.logError); - addExport("conlog", global.conlog); - function fillExports (scope) { - for (let name in exportList) if (typeof(name) == "string" && name.length > 0) scope[name] = exportList[name]; + for (let name in exportList) { + if (typeof(name) == "string" && name.length > 0) { + let exp = exportList[name]; + if (typeof(exp) === "string") { + if (!(exp in global)) continue; + //global.conlog("fillExports: indirect: '"+exp+"'"); + exp = global[exp]; + } + scope[name] = exp; + } + } } + addExport("Cu"); + addExport("Cc"); + addExport("Ci"); + addExport("Cr"); + addExport("Services"); + addExport("srvPrefs"); + + addExport("logException"); + addExport("logError"); + addExport("conlog"); + // imports a commonjs style javascript file with loadSubScrpt let modules = {}; // list of loaded modules @@ -165,15 +180,15 @@ function logException (msg, e) { return scope.exports; }; - addExport("getLocale", global.getLocale); - addExport("addExport", global.addExport); - addExport("require", global.require); + addExport("getLocale"); + addExport("addExport"); + addExport("require"); global.alert = function (str) { let ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService); ps.alert(null, "Guerilla", ""+str); }; - addExport("alert", global.alert); + addExport("alert"); let dirSvcProps = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); @@ -181,7 +196,7 @@ function logException (msg, e) { global.getProfileDir = function () { return dirSvcProps.get("ProfD", Ci.nsIFile); }; - addExport("getProfileDir", global.getProfileDir); + addExport("getProfileDir"); global.hitch = function (obj, method) { if (obj && method && typeof(method) == "string") { @@ -202,7 +217,7 @@ function logException (msg, e) { return method.apply(obj, args); }; }; - addExport("hitch", global.hitch); + addExport("hitch"); global.fileReadText = function (file, charset) { if (typeof(charset) !== "string") charset = "UTF-8"; @@ -222,5 +237,5 @@ function logException (msg, e) { if (charset == "UTF-8" && res.length >= 3 && res.substr(0, 3) == "\u00EF\u00BB\u00BF") res = res.substr(3); return res; }; - addExport("fileReadText", global.fileReadText); + addExport("fileReadText"); })(this); -- 2.11.4.GIT