Skip to content

Commit 5ed0310

Browse files
committed
fix(tame-metering): log problems trying to meter roots
1 parent 5b54e07 commit 5ed0310

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/tame-metering/src/tame.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function tameMetering() {
3737
const FunctionPrototype = Function.prototype;
3838

3939
let globalMeter = null;
40+
const definePropertyFailures = new Set();
4041
const wrapped = new WeakMap();
4142
const setWrapped = (...args) => apply(wmSet, wrapped, args);
4243
const getWrapped = (...args) => apply(wmGet, wrapped, args);
@@ -63,8 +64,9 @@ export function tameMetering() {
6364
const wrapDescriptor = (desc, pname = undefined) => {
6465
const newDesc = {};
6566
for (const [k, v] of entries(desc)) {
67+
const path = pname && (k === 'value' ? pname : `${pname}.${k}`);
6668
// eslint-disable-next-line no-use-before-define
67-
newDesc[k] = wrap(v, pname && `${pname}.${k}`);
69+
newDesc[k] = wrap(v, path);
6870
}
6971
return newDesc;
7072
};
@@ -243,6 +245,12 @@ export function tameMetering() {
243245
defineProperty(o, p, newDesc);
244246
} catch (e) {
245247
// Ignore: TypeError: Cannot redefine property: ...
248+
const path = pname ? `${pname}.${String(p)}` : '*unknown*';
249+
if (!definePropertyFailures.has(path)) {
250+
definePropertyFailures.add(path);
251+
// This is an intentional use of console.log, not a debugging vestige.
252+
console.log(`Cannot meter ${path}`);
253+
}
246254
}
247255
}
248256
};
@@ -261,7 +269,7 @@ export function tameMetering() {
261269

262270
// Override the globals and anonymous intrinsics with wrappers.
263271
const wrapRoot = {
264-
globalThis,
272+
Function,
265273
async AsyncFunction() {
266274
await Promise.resolve(123);
267275
return 456;
@@ -272,7 +280,12 @@ export function tameMetering() {
272280
async *AsyncGeneratorFunction() {
273281
yield 123;
274282
},
283+
globalThis,
275284
};
285+
286+
// Clear out the prototype of the wrapRoot so that we iterate only
287+
// on the explicit properties.
288+
Object.setPrototypeOf(wrapRoot, null);
276289
wrap(wrapRoot, '#');
277290

278291
// Provide a way to set the meter.

0 commit comments

Comments
 (0)