Commit b9a2ffc2 authored by Masatoshi Kimura's avatar Masatoshi Kimura
Browse files

Bug 1482279 - Stop using Cu.forcePermissiveCOWs() in SpecialPowers. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D74641
parent 22b8c9b3
......@@ -46,7 +46,7 @@ function tryChromeLoad() {
}
function tryComponentsClasses() {
return SpecialPowers.Components.classes["@mozilla.org/dummy;1"];
return SpecialPowers.unwrap(SpecialPowers.Cc)["@mozilla.org/dummy;1"];
}
......
......@@ -6,7 +6,7 @@ window.onmessage = event => {
const innerNode = window.document.getElementById("inner-node");
const wrappedNode = SpecialPowers.wrap(innerNode);
const wrappedQuads = wrappedNode.getBoxQuadsFromWindowOrigin();
const [quad] = SpecialPowers.unwrap(wrappedQuads);
const quad = SpecialPowers.unwrap(wrappedQuads[0]);
window.parent.postMessage({ quad }, "*");
};
......
......@@ -146,6 +146,7 @@ async function waitForFinishedFrames(numFrames) {
await delay(500);
for (let win of SpecialPowers.getGroupTopLevelWindows(window)) {
win = SpecialPowers.unwrap(win);
await searchForFinishedFrames(win);
}
}
......@@ -158,6 +159,7 @@ async function waitForFinishedFrames(numFrames) {
async function getFramesByName(name) {
let results = [];
for (let win of SpecialPowers.getGroupTopLevelWindows(window)) {
win = SpecialPowers.unwrap(win);
if (
(await SpecialPowers.spawn(win, [], () => this.content.name)) === name
) {
......@@ -170,6 +172,7 @@ async function getFramesByName(name) {
async function cleanupWindows() {
for (let win of SpecialPowers.getGroupTopLevelWindows(window)) {
win = SpecialPowers.unwrap(win);
if (win.closed) {
continue;
}
......
......@@ -72,7 +72,7 @@ function observeAnimSyncStyling(funcToMakeRestyleHappen) {
const markers = docShell.popProfileTimelineMarkers();
docShell.recordProfileTimelineMarkers = false;
return markers.filter((marker, index) => {
return Array.prototype.filter.call(markers, (marker, index) => {
return marker.name == 'Styles' && marker.isAnimationOnly;
});
}
......
......@@ -521,9 +521,12 @@ function observeStylingInTargetWindow(aWindow, aFrameCount, aOnFrame) {
return waitForAnimationFrames(aFrameCount, aOnFrame, aWindow).then(() => {
const markers = docShell.popProfileTimelineMarkers();
docShell.recordProfileTimelineMarkers = false;
const stylingMarkers = markers.filter((marker, index) => {
return marker.name == "Styles" && marker.isAnimationOnly;
});
const stylingMarkers = Array.prototype.filter.call(
markers,
(marker, index) => {
return marker.name == "Styles" && marker.isAnimationOnly;
}
);
resolve(stylingMarkers);
});
});
......
......@@ -19,8 +19,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
xoObjects.push(window[0]);
xoObjects.push(window[0].location);
xoObjects.push(SpecialPowers.unwrap(SpecialPowers.wrap(window[0]).document));
xoObjects.push(SpecialPowers);
xoObjects.push(SpecialPowers.wrap);
xoObjects.push(SpecialPowers.unwrap(SpecialPowers));
xoObjects.push(SpecialPowers.unwrap(SpecialPowers.wrap));
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go);
}
......
......@@ -41,7 +41,7 @@ ConsoleListener.prototype = {
waitFor(cb) {
return new Promise(resolve => {
this._cb = cb;
this._cb = SpecialPowers.wrapCallback(cb);
this._resolve = resolve;
});
},
......@@ -106,7 +106,10 @@ async function runTest() {
ok(true, "Console.count == 1 received!");
}
runTest().then(SimpleTest.finish);
runTest().then(() => {
listener.shutdown();
SimpleTest.finish();
});
</script>
</body>
......
......@@ -15,6 +15,8 @@
const JSM = "chrome://mochitests/content/chrome/dom/console/tests/console.jsm";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
let dumpCalled = 0;
function dumpFunction(msg) {
ok(msg.includes("_PREFIX_"), "we have a prefix");
......@@ -23,7 +25,7 @@ function dumpFunction(msg) {
}
function consoleListener() {
SpecialPowers.addObserver(this, "console-api-log-event");
Services.obs.addObserver(this, "console-api-log-event");
}
consoleListener.prototype = {
......@@ -59,7 +61,7 @@ consoleListener.prototype = {
if (this.count == 4) {
is(dumpCalled, 2, "Dump has been called!");
SpecialPowers.removeObserver(this, "console-api-log-event");
Services.obs.removeObserver(this, "console-api-log-event");
SimpleTest.finish();
}
}
......
......@@ -39,7 +39,7 @@ ConsoleListener.prototype = {
waitFor(cb) {
return new Promise(resolve => {
this._cb = cb;
this._cb = SpecialPowers.wrapCallback(cb);
this._resolve = resolve;
});
},
......
......@@ -13,7 +13,7 @@ const { Services } = SpecialPowers.Cu.import('resource://gre/modules/Services.js
let observe = topic => new Promise(r => Services.obs.addObserver(function o(...args) {
Services.obs.removeObserver(o, topic);
r(args);
r(args.map(x => SpecialPowers.wrap(x)));
}, topic));
let getDevices = async constraints => {
......@@ -22,9 +22,12 @@ let getDevices = async constraints => {
observe("getUserMedia:request")
]);
let window = Services.wm.getOuterWindowWithId(windowID);
let devices = await new Promise((resolve, reject) =>
let devices = await new Promise((resolve, reject) => {
resolve = SpecialPowers.wrapCallback(resolve);
reject = SpecialPowers.wrapCallback(reject);
window.navigator.mozGetUserMediaDevices({}, resolve, reject,
innerWindowID, callID));
innerWindowID, callID);
});
return devices.map(SpecialPowers.wrapCallback(d => d.QueryInterface(Ci.nsIMediaDevice)));
};
......@@ -34,7 +37,7 @@ runTest(async () => {
["media.navigator.permission.force", true]);
let devices = await getDevices({video: { mediaSource: "window" }});
ok(devices.length, "Found one or more windows.");
devices = devices.filter(d => d.scary);
devices = Array.prototype.filter.call(devices, d => d.scary);
ok(devices.length, "Found one or more scary windows (our own counts).");
devices.filter(d => d.name.includes("MochiTest"));
ok(devices.length,
......@@ -43,7 +46,7 @@ runTest(async () => {
devices = await getDevices({video: { mediaSource: "screen" }});
let numScreens = devices.length;
ok(numScreens, "Found one or more screens.");
devices = devices.filter(d => d.scary);
devices = Array.prototype.filter.call(devices, d => d.scary);
is(devices.length, numScreens, "All screens are scary.");
});
......
......@@ -50,21 +50,7 @@ function requestFinished(request) {
return new Promise(function(resolve, reject) {
request.callback = SpecialPowers.wrapCallback(function(req) {
if (req.resultCode === SpecialPowers.Cr.NS_OK) {
let result = req.result;
if (
SpecialPowers.call_Instanceof(result, SpecialPowers.Ci.nsISDBResult)
) {
let wrapper = {};
for (let i in result) {
if (typeof result[i] == "function") {
wrapper[i] = SpecialPowers.unwrap(result[i]);
} else {
wrapper[i] = result[i];
}
}
result = wrapper;
}
resolve(result);
resolve(req.result);
} else {
reject(req.resultCode);
}
......
......@@ -64,7 +64,7 @@ function registerMockPromptService()
{
this._toggleModalState();
promptState = {method: "alert",
parent: this.domWindow,
parent: SpecialPowers.unwrap(this.domWindow),
title: aDialogTitle,
msg: aText
};
......@@ -74,7 +74,7 @@ function registerMockPromptService()
{
this._toggleModalState();
promptState = {method: "alertCheck",
parent: this.domWindow,
parent: SpecialPowers.unwrap(this.domWindow),
title: aDialogTitle,
msg: aText,
checkMsg: aCheckMsg,
......@@ -88,7 +88,7 @@ function registerMockPromptService()
{
this._toggleModalState();
promptState = {method: "confirm",
parent: this.domWindow,
parent: SpecialPowers.unwrap(this.domWindow),
title: aDialogTitle,
msg: aText
};
......@@ -100,7 +100,7 @@ function registerMockPromptService()
{
this._toggleModalState();
promptState = {method: "confirmCheck",
parent: this.domWindow,
parent: SpecialPowers.unwrap(this.domWindow),
title: aDialogTitle,
msg: aText,
checkMsg: aCheckMsg,
......@@ -118,7 +118,7 @@ function registerMockPromptService()
{
this._toggleModalState();
promptState = {method: "confirmCheck",
parent: this.domWindow,
parent: SpecialPowers.unwrap(this.domWindow),
title: aDialogTitle,
msg: aText,
checkMsg: aCheckMsg,
......@@ -136,7 +136,7 @@ function registerMockPromptService()
{
this._toggleModalState();
promptState = {method: "prompt",
parent: this.domWindow,
parent: SpecialPowers.unwrap(this.domWindow),
title: aDialogTitle,
msg: aText,
checkMsg: aCheckMsg,
......@@ -168,7 +168,7 @@ function registerMockPromptService()
getPrompt(aDOMWindow, aIID)
{
return new MockPrompt(aDOMWindow);
return SpecialPowers.wrapCallbackObject(new MockPrompt(aDOMWindow));
},
alert(aParent, aDialogTitle, aText)
......
......@@ -20,8 +20,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850517
sb.win = window;
sb.childA = ifrA.contentWindow;
sb.childB = ifrB.contentWindow;
SpecialPowers.setWrapped(sb, 'is', SpecialPowers.wrap(is));
SpecialPowers.setWrapped(sb, 'ok', SpecialPowers.wrap(ok));
SpecialPowers.setWrapped(sb, 'is', SpecialPowers.wrapFor(is, sb));
SpecialPowers.setWrapped(sb, 'ok', SpecialPowers.wrapFor(ok, sb));
is(window.theoneandonly.frameElement, ifrA, "Named child resolution works");
SpecialPowers.Cu.evalInSandbox('is(win.theoneandonly, childA, "Named child resolution works via Xray");', sb);
ifrA.removeAttribute('name');
......
......@@ -85,7 +85,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1530413
sandbox = SpecialPowers.unwrap(Cu.Sandbox(this, { sameZoneAs: this, freshCompartment: true}));
sandbox.window = window;
sandbox.crossCompartmentObject = {};
sandbox.waiveXrays = Cu.waiveXrays;
sandbox.waiveXrays = SpecialPowers.wrapFor(Cu.waiveXrays, sandbox);
window[Symbol.hasInstance] = function(instance) {
instance.window = this;
......
......@@ -30,7 +30,7 @@
var Cu = SpecialPowers.Cu;
var princ = SpecialPowers.wrap(window.document).nodePrincipal;
var sandbox = Cu.Sandbox(princ, { sameZoneAs: this });
sandbox.win = window.frames.diffDomain;
SpecialPowers.unwrap(sandbox).win = window.frames.diffDomain;
var err = `Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://example.com’) does not match the recipient window’s origin (‘https://example.org’).`;
let consolePromise = waitForErrorMessage(err);
Cu.evalInSandbox(
......
......@@ -18,10 +18,12 @@
const CHILD_WORKER_URL = "WorkerDebugger.console_childWorker.js";
const DEBUGGER_URL = BASE_URL + "WorkerDebugger.console_debugger.js";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
consoleMessagesReceived = 0;
function test() {
function consoleListener() {
SpecialPowers.addObserver(this, "console-api-log-event");
Services.obs.addObserver(this, "console-api-log-event");
}
consoleListener.prototype = {
......@@ -32,7 +34,7 @@
!consoleMessagesReceived) {
consoleMessagesReceived++;
ok(true, "Something has been received");
SpecialPowers.removeObserver(this, "console-api-log-event");
Services.obs.removeObserver(this, "console-api-log-event");
}
}
}
......
......@@ -24,7 +24,7 @@ SimpleTest.waitForExplicitFinish();
async function snapshotFirst()
{
var iframeelem = document.getElementById('test-iframe');
first = await snapshotWindow(iframeelem, false);
first = await SpecialPowers.wrap(snapshotWindow(iframeelem, false));
iframeelem.onload = snapshotSecond;
iframeelem.src = "http://example.com/tests/image/test/mochitest/bug671906-iframe.html";
......@@ -33,7 +33,7 @@ async function snapshotFirst()
async function snapshotSecond()
{
var iframeelem = document.getElementById('test-iframe');
second = await snapshotWindow(iframeelem, false);
second = await SpecialPowers.wrap(snapshotWindow(iframeelem, false));
// We must have loaded the image again, because the principals for the
// loading document are different.
......@@ -47,7 +47,7 @@ async function snapshotSecond()
async function snapshotThird()
{
var iframeelem = document.getElementById('test-iframe');
third = await snapshotWindow(iframeelem, false);
third = await SpecialPowers.wrap(snapshotWindow(iframeelem, false));
// We must have loaded the image again, because the principals for the
// loading document are different.
......
......@@ -618,14 +618,6 @@ bool mozJSComponentLoader::ReuseGlobal(nsIURI* aURI) {
return false;
}
// Some SpecialPowers jsms call Cu.forcePermissiveCOWs(),
// which sets a per-compartment flag that disables certain
// security wrappers, so don't use the shared global for them
// to avoid breaking tests.
if (FindInReadable(NS_LITERAL_CSTRING("resource://specialpowers/"), spec)) {
return false;
}
return true;
}
......
......@@ -2,18 +2,19 @@
<head>
<script>
function check_wrapper(ok, wrapper, expected, note) {
var utils = SpecialPowers.DOMWindowUtils;
ok(utils.getClassName(wrapper) === expected, note);
let { getClassName } = SpecialPowers.unwrap(
SpecialPowers.wrap(window).ChromeUtils
);
ok(getClassName(wrapper, false) === expected, note);
}
function run_test(ok, xpcnw, sjow) {
// both wrappers should point to our window: XOW
check_wrapper(ok, ok, "Proxy", "functions are wrapped properly")
check_wrapper(ok, ok, "Proxy", "functions are wrapped properly");
check_wrapper(ok, xpcnw, "Proxy", "XPCNWs are transformed correctly");
check_wrapper(ok, sjow, "Proxy", "SJOWs are transformed correctly");
check_wrapper(ok, window.location, "Proxy",
"Content needs a same-compartment security wrappers around location");
check_wrapper(ok, window.location, "Location",
"same-compartment security wrappers are gone");
ok(defprop1 === 1, "defprop1 exists");
window.defprop1 = 2;
......
......@@ -38,15 +38,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=416896
for (var i = 0; i < inspectedRules.length; ++i)
{
var rule = SpecialPowers.unwrap(inspectedRules[i]);
var rule = inspectedRules[i];
var sheet = rule.parentStyleSheet;
if (sheet == inlineSheet) {
if (SpecialPowers.unwrap(sheet) == inlineSheet) {
is(sheet.href, null, "It's an inline sheet");
is(seenInline, false, "Only one inline rule matches");
seenInline = true;
} else {
isnot(sheet.href, null, "Shouldn't have null href here " + i);
if (sheet == linkedSheet) {
if (SpecialPowers.unwrap(sheet) == linkedSheet) {
is(seenLinked, false, "Only one linked rule matches");
seenLinked = true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment