Skip to content

Commit 9f7d456

Browse files
committed
fix(transform-meter): Accommodate SES module proxies in meter
1 parent 53cc1e5 commit 9f7d456

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/transform-metering/src/meter.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ const ObjectConstructor = Object;
88
const bigIntWord = 2n ** 64n;
99
const bigIntZero = 0n;
1010

11+
/*
12+
* Getting the properties of a SES-shim module exports namespace object throws
13+
* an error if inspected before the module initializes.
14+
* Allowing this case is necessary for the compartment mapper to be hosted by
15+
* the compartment mapper under metering.
16+
*/
17+
const maybeGetOwnPropertyDescriptors = object => {
18+
try {
19+
return getOwnPropertyDescriptors(object);
20+
} catch (_error) {
21+
return {};
22+
}
23+
};
24+
1125
// Stop deducting when we reach a negative number.
1226
const makeCounter = initBalance => {
1327
let balance = initBalance;
@@ -77,7 +91,7 @@ export function makeAllocateMeter(maybeAbort, meter, allocateCounter = null) {
7791
} else {
7892
// Compute the number of own properties.
7993
// eslint-disable-next-line guard-for-in, no-unused-vars
80-
for (const p in getOwnPropertyDescriptors(value)) {
94+
for (const p in maybeGetOwnPropertyDescriptors(value)) {
8195
meter[c.METER_COMPUTE](undefined, throwForever);
8296
cost += 1;
8397
}

0 commit comments

Comments
 (0)