Skip to content

Commit da12a40

Browse files
committed
Address comments
1 parent d61720e commit da12a40

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

injected/src/content-feature.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export default class ContentFeature extends ConfigFeature {
240240
* @param {Obj} object - object whose property we are wrapping (most commonly a prototype, e.g. globalThis.BatteryManager.prototype)
241241
* @param {Key} propertyName
242242
* @param {import('./wrapper-utils.js').StrictPropertyDescriptorGeneric<Obj, Key>} descriptor - requires all descriptor options to be defined because we can't validate correctness based on TS types
243-
*/
243+
*/
244244
defineProperty(object, propertyName, descriptor) {
245245
// make sure to send a debug flag when the property is used
246246
// NOTE: properties passing data in `value` would not be caught by this
@@ -258,7 +258,36 @@ export default class ContentFeature extends ConfigFeature {
258258
}
259259
});
260260

261-
return defineProperty(object, String(propertyName), /** @type {any} */ (descriptor));
261+
// Build complete strict descriptor all at once so TS doesn't complain about missing properties
262+
let strictDescriptor;
263+
264+
if (descriptor.value !== undefined || descriptor.writable !== undefined) {
265+
// Data descriptor
266+
strictDescriptor = {
267+
configurable: descriptor.configurable ?? false,
268+
enumerable: descriptor.enumerable ?? false,
269+
value: descriptor.value,
270+
writable: descriptor.writable ?? false,
271+
};
272+
} else if (descriptor.get !== undefined || descriptor.set !== undefined) {
273+
// Accessor descriptor
274+
strictDescriptor = {
275+
configurable: descriptor.configurable ?? false,
276+
enumerable: descriptor.enumerable ?? false,
277+
get: descriptor.get ?? (() => undefined),
278+
set: descriptor.set ?? (() => {}),
279+
};
280+
} else {
281+
// Default data descriptor
282+
strictDescriptor = {
283+
configurable: descriptor.configurable ?? false,
284+
enumerable: descriptor.enumerable ?? false,
285+
value: undefined,
286+
writable: false,
287+
};
288+
}
289+
290+
return defineProperty(object, String(propertyName), strictDescriptor);
262291
}
263292

264293
/**

injected/src/features/web-compat.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TypeScript is disabled for this file due to intentional DOM polyfills (e.g., Notification) that are incompatible with the DOM lib types.
21
import ContentFeature from '../content-feature.js';
32
// eslint-disable-next-line no-redeclare
43
import { URL } from '../captured-globals.js';

0 commit comments

Comments
 (0)