зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1765167 - Part 2: Stop using Cu.import in devtools/. r=mossop
Differential Revision: https://phabricator.services.mozilla.com/D144095
This commit is contained in:
Родитель
7dfdb15ec9
Коммит
8c9eb71d74
|
@ -36,8 +36,12 @@
|
|||
var isInChrome = window.location.href.includes("chrome:");
|
||||
if (isInChrome) {
|
||||
var exports = {};
|
||||
var { require, loader } = Cu.import("resource://devtools/shared/loader/Loader.jsm");
|
||||
var { BrowserLoader } = Cu.import("resource://devtools/shared/loader/browser-loader.js");
|
||||
var { require, loader } = ChromeUtils.import(
|
||||
"resource://devtools/shared/loader/Loader.jsm"
|
||||
);
|
||||
var { BrowserLoader } = ChromeUtils.import(
|
||||
"resource://devtools/shared/loader/browser-loader.js"
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ const Services = require("Services");
|
|||
In the rare event where you don't have access to the DevTools' require method, you can use
|
||||
|
||||
```javascript
|
||||
const { Services } = Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
```
|
||||
|
||||
### Services.pref.get* and Services.pref.set*
|
||||
|
|
|
@ -82,7 +82,7 @@ One exported symbol from ``Console.jsm`` is ``console``. Below is an example of
|
|||
|
||||
.. code-block:: JavaScript
|
||||
|
||||
Components.utils.import("resource://gre/modules/Console.jsm");
|
||||
const { console } = ChromeUtils.import("resource://gre/modules/Console.jsm");
|
||||
console.log("Hello from Firefox code"); //output messages to the console</pre>
|
||||
|
||||
Learn more:
|
||||
|
|
|
@ -34,7 +34,9 @@ This page shows how to use the :doc:`Debugger API <../index>` to show how many o
|
|||
|
||||
// This defines the 'Debugger' constructor in this
|
||||
// Scratchpad; it doesn't actually start debugging anything.
|
||||
Components.utils.import('resource://gre/modules/jsdebugger.jsm');
|
||||
const { addDebuggerToGlobal } = ChromeUtils.import(
|
||||
'resource://gre/modules/jsdebugger.jsm'
|
||||
);
|
||||
addDebuggerToGlobal(window);
|
||||
|
||||
(function () {
|
||||
|
|
|
@ -40,8 +40,12 @@ This tutorial was tested against Firefox 58 Beta and Nightly. It does not work i
|
|||
|
||||
.. code-block:: javascript
|
||||
|
||||
Components.utils.import("resource://gre/modules/jsdebugger.jsm");
|
||||
Components.utils.import("resource://gre/modules/Console.jsm");
|
||||
const { addDebuggerToGlobal } = ChromeUtils.import(
|
||||
"resource://gre/modules/jsdebugger.jsm"
|
||||
);
|
||||
const { console } = ChromeUtils.import(
|
||||
"resource://gre/modules/Console.jsm"
|
||||
);
|
||||
|
||||
// This defines 'Debugger' in this Scratchpad;
|
||||
// it doesn't actually start debugging anything.
|
||||
|
|
|
@ -166,10 +166,15 @@ function createLongStringFront(conn, form) {
|
|||
return front;
|
||||
}
|
||||
|
||||
function createTestGlobal(name) {
|
||||
const sandbox = Cu.Sandbox(
|
||||
Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal)
|
||||
function createTestGlobal(name, options) {
|
||||
const principal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
|
||||
Ci.nsIPrincipal
|
||||
);
|
||||
// NOTE: The Sandbox constructor behaves differently based on the argument
|
||||
// length.
|
||||
const sandbox = options
|
||||
? Cu.Sandbox(principal, options)
|
||||
: Cu.Sandbox(principal);
|
||||
sandbox.__name = name;
|
||||
// Expose a few mocks to better represent a Window object.
|
||||
// These attributes will be used by DOCUMENT_EVENT resource listener.
|
||||
|
|
|
@ -8,7 +8,9 @@ function run_test() {
|
|||
"resource://gre/modules/jsdebugger.jsm"
|
||||
);
|
||||
addDebuggerToGlobal(this);
|
||||
const g = createTestGlobal("test");
|
||||
const g = createTestGlobal("test", {
|
||||
wantGlobalProperties: ["ChromeUtils"],
|
||||
});
|
||||
const dbg = new Debugger();
|
||||
const gw = dbg.addDebuggee(g);
|
||||
|
||||
|
@ -20,7 +22,9 @@ function run_test() {
|
|||
enumerable: true
|
||||
});
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
// This is a CCW.
|
||||
XPCOMUtils.defineLazyGetter(this, "foo", function() { return "foo"; });
|
||||
|
|
|
@ -403,10 +403,16 @@ var {
|
|||
|
||||
// To ensure that the this passed to addDebuggerToGlobal is a global, the
|
||||
// Debugger object needs to be defined in a sandbox.
|
||||
const sandbox = Cu.Sandbox(principal, {});
|
||||
const sandbox = Cu.Sandbox(principal, {
|
||||
wantGlobalProperties: ["ChromeUtils"],
|
||||
});
|
||||
Cu.evalInSandbox(
|
||||
"Components.utils.import('resource://gre/modules/jsdebugger.jsm');" +
|
||||
"addDebuggerToGlobal(this);",
|
||||
`
|
||||
const { addDebuggerToGlobal } = ChromeUtils.import(
|
||||
'resource://gre/modules/jsdebugger.jsm'
|
||||
);
|
||||
addDebuggerToGlobal(this);
|
||||
`,
|
||||
sandbox
|
||||
);
|
||||
const Debugger = sandbox.Debugger;
|
||||
|
|
Загрузка…
Ссылка в новой задаче