Skip to content

Commit d3469b9

Browse files
committed
fix(TS): define functions on Object
1 parent 886e4f9 commit d3469b9

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Extension/src/stealth/instrument.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function logValue(
237237
value, // : any,
238238
operation, // : string, // from JSOperation object please
239239
callContext, // : any,
240-
logSettings = false, // : LogSettings,
240+
logSettings: typeof jsInstrumentationSettings[0] | { logFunctionsAsStrings: boolean } = { logFunctionsAsStrings: false }, // : LogSettings,
241241
) {
242242
if (inLog) {
243243
return;
@@ -327,7 +327,16 @@ function logCall(instrumentedFunctionName, args, callContext, _logSettings) {
327327
/**
328328
* Provides the properties per prototype object
329329
*/
330-
Object.getPrototypeByDepth = function (subject, depth) {
330+
331+
declare global {
332+
interface Object {
333+
getPrototypeByDepth(subject: string | undefined, depth: number): any
334+
getPropertyNamesPerDepth(subject: any, maxDepth: number): any
335+
findPropertyInChain(subject, propertyName)
336+
}
337+
}
338+
339+
Object.prototype.getPrototypeByDepth = function (subject, depth) {
331340
if (subject === undefined) {
332341
throw new Error("Can't get property names for undefined");
333342
}
@@ -348,7 +357,7 @@ Object.getPrototypeByDepth = function (subject, depth) {
348357
* Traverses the prototype chain to collect properties. Returns an array containing
349358
* an object with the depth, propertyNames and scanned subject
350359
*/
351-
Object.getPropertyNamesPerDepth = function (subject, maxDepth = 0) {
360+
Object.prototype.getPropertyNamesPerDepth = function (subject, maxDepth = 0) {
352361
if (subject === undefined) {
353362
throw new Error("Can't get property names for undefined");
354363
}
@@ -370,7 +379,7 @@ Object.getPropertyNamesPerDepth = function (subject, maxDepth = 0) {
370379
/**
371380
* Finds a property along the prototype chain
372381
*/
373-
Object.findPropertyInChain = function (subject, propertyName) {
382+
Object.prototype.findPropertyInChain = function (subject, propertyName) {
374383
if (subject === undefined || propertyName === undefined) {
375384
throw new Error("Object and property name must be defined");
376385
}
@@ -457,9 +466,9 @@ function notify(type, content) {
457466
});
458467
}
459468

460-
function filterPropertiesPerDepth(collection, excluded) {
461-
for (let i = 0; i < collection.length; i++) {
462-
collection[i].propertyNames = collection[i].propertyNames.filter(
469+
function filterPropertiesPerDepth<T>(collection: {propertyNames: T[]}[], excluded: T[]) {
470+
for (const elem of collection) {
471+
elem.propertyNames = elem.propertyNames.filter(
463472
(p) => !excluded.includes(p),
464473
);
465474
}

Extension/src/stealth/stealth.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
const interceptedWindows = new WeakMap();
1414
const proxies = new Map();
1515
const changedToStrings = new WeakMap();
16-
16+
export type ModifiedWindow = Window & typeof globalThis & { wrappedJSObject: any };
1717
// Entry point for this extension
1818
(function () {
1919
// console.log("Starting frame script");
2020
try {
21-
interceptWindow(window);
21+
interceptWindow(window as ModifiedWindow);
2222
} catch (error) {
2323
console.log("Instrumentation initialisation crashed. Reason: " + error);
2424
console.log(error.stack);

0 commit comments

Comments
 (0)