@@ -37,6 +37,7 @@ export function tameMetering() {
37
37
const FunctionPrototype = Function . prototype ;
38
38
39
39
let globalMeter = null ;
40
+ const definePropertyFailures = new Set ( ) ;
40
41
const wrapped = new WeakMap ( ) ;
41
42
const setWrapped = ( ...args ) => apply ( wmSet , wrapped , args ) ;
42
43
const getWrapped = ( ...args ) => apply ( wmGet , wrapped , args ) ;
@@ -63,8 +64,9 @@ export function tameMetering() {
63
64
const wrapDescriptor = ( desc , pname = undefined ) => {
64
65
const newDesc = { } ;
65
66
for ( const [ k , v ] of entries ( desc ) ) {
67
+ const path = pname && ( k === 'value' ? pname : `${ pname } .${ k } ` ) ;
66
68
// eslint-disable-next-line no-use-before-define
67
- newDesc [ k ] = wrap ( v , pname && ` ${ pname } . ${ k } ` ) ;
69
+ newDesc [ k ] = wrap ( v , path ) ;
68
70
}
69
71
return newDesc ;
70
72
} ;
@@ -243,6 +245,12 @@ export function tameMetering() {
243
245
defineProperty ( o , p , newDesc ) ;
244
246
} catch ( e ) {
245
247
// 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
+ }
246
254
}
247
255
}
248
256
} ;
@@ -261,7 +269,7 @@ export function tameMetering() {
261
269
262
270
// Override the globals and anonymous intrinsics with wrappers.
263
271
const wrapRoot = {
264
- globalThis ,
272
+ Function ,
265
273
async AsyncFunction ( ) {
266
274
await Promise . resolve ( 123 ) ;
267
275
return 456 ;
@@ -272,7 +280,12 @@ export function tameMetering() {
272
280
async * AsyncGeneratorFunction ( ) {
273
281
yield 123 ;
274
282
} ,
283
+ globalThis,
275
284
} ;
285
+
286
+ // Clear out the prototype of the wrapRoot so that we iterate only
287
+ // on the explicit properties.
288
+ Object . setPrototypeOf ( wrapRoot , null ) ;
276
289
wrap ( wrapRoot , '#' ) ;
277
290
278
291
// Provide a way to set the meter.
0 commit comments