Bug 553102 - Waive COW checks on SpecialPowers wrapper objects. r=mrbkap

This commit is contained in:
Bobby Holley 2012-05-24 13:04:57 +02:00
Родитель ec08cbb3fc
Коммит 0783825f23
1 изменённых файлов: 24 добавлений и 0 удалений

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

@ -159,6 +159,26 @@ function crawlProtoChain(obj, fn) {
return crawlProtoChain(Object.getPrototypeOf(obj), fn);
};
/*
* We want to waive the __exposedProps__ security check for SpecialPowers-wrapped
* objects. We do this by creating a proxy singleton that just always returns 'rw'
* for any property name.
*/
function ExposedPropsWaiverHandler() {
// NB: XPConnect denies access if the relevant member of __exposedProps__ is not
// enumerable.
var _permit = { value: 'rw', writable: false, configurable: false, enumerable: true };
return {
getOwnPropertyDescriptor: function(name) { return _permit; },
getPropertyDescriptor: function(name) { return _permit; },
getOwnPropertyNames: function() { throw Error("Can't enumerate ExposedPropsWaiver"); },
getPropertyNames: function() { throw Error("Can't enumerate ExposedPropsWaiver"); },
enumerate: function() { throw Error("Can't enumerate ExposedPropsWaiver"); },
defineProperty: function(name) { throw Error("Can't define props on ExposedPropsWaiver"); },
delete: function(name) { throw Error("Can't delete props from ExposedPropsWaiver"); }
};
};
ExposedPropsWaiver = Proxy.create(ExposedPropsWaiverHandler());
function SpecialPowersHandler(obj) {
this.wrappedObject = obj;
@ -172,6 +192,10 @@ SpecialPowersHandler.prototype.doGetPropertyDescriptor = function(name, own) {
if (name == "SpecialPowers_wrappedObject")
return { value: this.wrappedObject, writeable: false, configurable: false, enumerable: false };
// Handle __exposedProps__.
if (name == "__exposedProps__")
return { value: ExposedPropsWaiver, writable: false, configurable: false, enumerable: false };
// In general, we want Xray wrappers for content DOM objects, because waiving
// Xray gives us Xray waiver wrappers that clamp the principal when we cross
// compartment boundaries. However, Xray adds some gunk to toString(), which