Bug 1448398. Stop returning unwrapped Components.interfaces from SpecialPowers.Ci. r=kmag

This commit is contained in:
Boris Zbarsky 2018-03-26 13:35:04 -04:00
Родитель 9851f29e1d
Коммит 1151dd21cc
8 изменённых файлов: 33 добавлений и 26 удалений

Просмотреть файл

@ -27,7 +27,7 @@ let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
function clearAllImageCaches() {
var tools = Cc["@mozilla.org/image/tools;1"]
.getService(SpecialPowers.Ci.imgITools);
.getService(Ci.imgITools);
var imageCache = tools.getImgCacheForDocument(window.document);
imageCache.clearCache(true); // true=chrome
imageCache.clearCache(false); // false=content

Просмотреть файл

@ -50,7 +50,7 @@ function go() {
frame.remove();
TestUtils.topicObserved("outer-window-nuked", (subject, data) => {
let id = subject.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
return id == winID;
}).then(() => {
ok(checkDead(), "Expected a dead object wrapper");

Просмотреть файл

@ -180,6 +180,13 @@ function unwrapPrivileged(x) {
return obj;
}
function specialPowersHasInstance(value) {
// Because we return wrapped versions of this function, when it's called its
// wrapper will unwrap the "this" as well as the function itself. So our
// "this" is the unwrapped thing we started out with.
return value instanceof this;
}
function SpecialPowersHandler(wrappedObject) {
this.wrappedObject = wrappedObject;
}
@ -224,7 +231,16 @@ SpecialPowersHandler.prototype = {
return this.wrappedObject;
let obj = waiveXraysIfAppropriate(this.wrappedObject, prop);
return wrapIfUnwrapped(Reflect.get(obj, prop));
let val = Reflect.get(obj, prop);
if (val === undefined && prop == Symbol.hasInstance) {
// Special-case Symbol.hasInstance to pass the hasInstance check on to our
// target. We only do this when the target doesn't have its own
// Symbol.hasInstance already. Once we get rid of JS engine class
// instance hooks (bug 1448218) and always use Symbol.hasInstance, we can
// remove this bit (bug 1448400).
return wrapPrivileged(specialPowersHasInstance);
}
return wrapIfUnwrapped(val);
},
set(target, prop, val, receiver) {
@ -256,8 +272,19 @@ SpecialPowersHandler.prototype = {
let obj = waiveXraysIfAppropriate(this.wrappedObject, prop);
let desc = Reflect.getOwnPropertyDescriptor(obj, prop);
if (desc === undefined)
if (desc === undefined) {
if (prop == Symbol.hasInstance) {
// Special-case Symbol.hasInstance to pass the hasInstance check on to
// our target. We only do this when the target doesn't have its own
// Symbol.hasInstance already. Once we get rid of JS engine class
// instance hooks (bug 1448218) and always use Symbol.hasInstance, we
// can remove this bit (bug 1448400).
return { value: wrapPrivileged(specialPowersHasInstance),
writeable: true, configurable: true, enumerable: false };
}
return undefined;
}
// Transitively maintain the wrapper membrane.
function wrapIfExists(key) {
@ -653,15 +680,10 @@ SpecialPowersAPI.prototype = {
},
/*
* Convenient shortcuts to the standard Components abbreviations. Note that
* we don't SpecialPowers-wrap Components.interfaces, because it's available
* to untrusted content, and wrapping it confuses QI and identity checks.
* Convenient shortcuts to the standard Components abbreviations.
*/
get Cc() { return wrapPrivileged(this.getFullComponents().classes); },
get Ci() {
return this.Components ? this.Components.interfaces
: Ci;
},
get Ci() { return wrapPrivileged(this.getFullComponents().interfaces); },
get Cu() { return wrapPrivileged(this.getFullComponents().utils); },
get Cr() { return wrapPrivileged(this.Components.results); },

Просмотреть файл

@ -14,9 +14,6 @@
<script class="testbody" type="text/javascript">
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)

Просмотреть файл

@ -16,9 +16,6 @@
<script class="testbody" type="text/javascript">
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)

Просмотреть файл

@ -16,9 +16,6 @@
<script class="testbody" type="text/javascript">
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)

Просмотреть файл

@ -16,9 +16,6 @@
<script class="testbody" type="text/javascript">
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)

Просмотреть файл

@ -16,9 +16,6 @@
<script class="testbody" type="text/javascript">
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)