1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-28 11:52:26 +01:00

Use services.dactyl when available.

This commit is contained in:
Kris Maglione
2011-09-22 21:55:58 -04:00
parent 6af256bc53
commit e1db34990b
6 changed files with 147 additions and 31 deletions

10
common/bootstrap.js vendored
View File

@@ -58,6 +58,13 @@ let components = {};
let resources = [];
let getURI = null;
function updateLoader() {
try {
JSMLoader.loader = Cc["@dactyl.googlecode.com/extra/utils"].getService(Ci.dactylIUtils);
}
catch (e) {};
}
/**
* Performs necessary migrations after a version change.
*/
@@ -100,6 +107,8 @@ function startup(data, reason) {
name = data.id.replace(/@.*/, "");
AddonManager.getAddonByID(addon.id, function (a) {
addon = a;
updateLoader();
updateVersion();
if (typeof require !== "undefined")
require(global, "main");
@@ -259,6 +268,7 @@ function init() {
Services.obs.notifyObservers(null, "dactyl-rehash", null);
updateVersion();
updateLoader();
if (addon !== addonData)
require(global, "main");
}

View File

@@ -492,38 +492,45 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let info = contexts.context;
if (fileName == null)
if (info && info.file[0] !== "[")
if (info)
({ file: fileName, line: lineNumber, context: ctxt }) = info;
if (fileName && fileName[0] == "[")
fileName = "dactyl://command-line/";
if (!context && fileName && fileName[0] !== "[")
context = ctxt || _userContext;
if (isinstance(context, ["Sandbox"]))
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
else
try {
if (!context)
context = userContext || ctxt;
else {
if (!context)
context = userContext || ctxt;
context[EVAL_ERROR] = null;
context[EVAL_STRING] = str;
context[EVAL_RESULT] = null;
this.loadScript("resource://dactyl-content/eval.js", context);
if (context[EVAL_ERROR]) {
try {
context[EVAL_ERROR].fileName = info.file;
context[EVAL_ERROR].lineNumber += info.line;
if (services.has("dactyl") && services.dactyl.evalInContext)
return services.dactyl.evalInContext(str, context, fileName, lineNumber);
else
try {
context[EVAL_ERROR] = null;
context[EVAL_STRING] = str;
context[EVAL_RESULT] = null;
this.loadScript("resource://dactyl-content/eval.js", context);
if (context[EVAL_ERROR]) {
try {
context[EVAL_ERROR].fileName = info.file;
context[EVAL_ERROR].lineNumber += info.line;
}
catch (e) {}
throw context[EVAL_ERROR];
}
catch (e) {}
throw context[EVAL_ERROR];
return context[EVAL_RESULT];
}
return context[EVAL_RESULT];
}
finally {
delete context[EVAL_ERROR];
delete context[EVAL_RESULT];
delete context[EVAL_STRING];
}
finally {
delete context[EVAL_ERROR];
delete context[EVAL_RESULT];
delete context[EVAL_STRING];
}
}
},
/**

View File

@@ -139,7 +139,13 @@ var Modules = function Modules(window) {
newContext: function newContext(proto, normal) {
if (normal)
return create(proto);
let sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules, wantXrays: false });
if (services.has("dactyl") && services.dactyl.createGlobal)
var sandbox = services.dactyl.createGlobal();
else
sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules,
wantXrays: false });
// Hack:
sandbox.Object = jsmodules.Object;
sandbox.File = jsmodules.File;