From e911e0061503446ecbc3b3d35f45135ab9b999c4 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Sat, 10 Feb 2018 10:56:39 -0500 Subject: Bug 1245141 - Use `new Proxy` for AddonManager.addonTypes (TychoAM) --- toolkit/mozapps/extensions/AddonManager.jsm | 95 ++++++++++++++--------------- 1 file changed, 47 insertions(+), 48 deletions(-) (limited to 'toolkit/mozapps') diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 38303726b..51030cb56 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -641,53 +641,6 @@ var AddonManagerInternal = { // Store telemetry details per addon provider telemetryDetails: {}, - // A read-only wrapper around the types dictionary - typesProxy: Proxy.create({ - getOwnPropertyDescriptor: function typesProxy_getOwnPropertyDescriptor(aName) { - if (!(aName in AddonManagerInternal.types)) - return undefined; - - return { - value: AddonManagerInternal.types[aName].type, - writable: false, - configurable: false, - enumerable: true - } - }, - - getPropertyDescriptor: function typesProxy_getPropertyDescriptor(aName) { - return this.getOwnPropertyDescriptor(aName); - }, - - getOwnPropertyNames: function typesProxy_getOwnPropertyNames() { - return Object.keys(AddonManagerInternal.types); - }, - - getPropertyNames: function typesProxy_getPropertyNames() { - return this.getOwnPropertyNames(); - }, - - delete: function typesProxy_delete(aName) { - // Not allowed to delete properties - return false; - }, - - defineProperty: function typesProxy_defineProperty(aName, aProperty) { - // Ignore attempts to define properties - }, - - fix: function typesProxy_fix(){ - return undefined; - }, - - // Despite MDC's claims to the contrary, it is required that this trap - // be defined - enumerate: function typesProxy_enumerate() { - // All properties are enumerable - return this.getPropertyNames(); - } - }), - recordTimestamp: function AMI_recordTimestamp(name, value) { this.TelemetryTimestamps.add(name, value); }, @@ -2423,7 +2376,53 @@ var AddonManagerInternal = { }, get addonTypes() { - return this.typesProxy; + // A read-only wrapper around the types dictionary + return new Proxy(this.types, { + defineProperty(target, property, descriptor) { + // Not allowed to define properties + return false; + }, + + deleteProperty(target, property) { + // Not allowed to delete properties + return false; + }, + + get(target, property, receiver) { + if (!target.hasOwnProperty(property)) + return undefined; + + return target[property].type; + }, + + getOwnPropertyDescriptor(target, property) { + if (!target.hasOwnProperty(property)) + return undefined; + + return { + value: target[property].type, + writable: false, + // Claim configurability to maintain the proxy invariants. + configurable: true, + enumerable: true + } + }, + + preventExtensions(target) { + // Not allowed to prevent adding new properties + return false; + }, + + set(target, property, value, receiver) { + // Not allowed to set properties + return false; + }, + + setPrototypeOf(target, prototype) { + // Not allowed to change prototype + return false; + } + }); }, get autoUpdateDefault() { -- cgit v1.2.3