summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 10:56:39 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 10:56:39 -0500
commite911e0061503446ecbc3b3d35f45135ab9b999c4 (patch)
tree79e35a863ec5d5ae840d1e290e261b90e18bc1c0 /toolkit/mozapps/extensions
parent2ef95493bd6c9d9b04f2a59f0d9fe9feeb704d6e (diff)
downloadUXP-e911e0061503446ecbc3b3d35f45135ab9b999c4.tar
UXP-e911e0061503446ecbc3b3d35f45135ab9b999c4.tar.gz
UXP-e911e0061503446ecbc3b3d35f45135ab9b999c4.tar.lz
UXP-e911e0061503446ecbc3b3d35f45135ab9b999c4.tar.xz
UXP-e911e0061503446ecbc3b3d35f45135ab9b999c4.zip
Bug 1245141 - Use `new Proxy` for AddonManager.addonTypes (TychoAM)
Diffstat (limited to 'toolkit/mozapps/extensions')
-rw-r--r--toolkit/mozapps/extensions/AddonManager.jsm95
1 files changed, 47 insertions, 48 deletions
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() {