Skip to content

Commit

Permalink
fix(TS): define functions on Object
Browse files Browse the repository at this point in the history
  • Loading branch information
vringar committed Sep 13, 2023
1 parent bdf7960 commit 2b4d05c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions Extension/src/stealth/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function logValue(
value, // : any,
operation, // : string, // from JSOperation object please
callContext, // : any,
logSettings = false, // : LogSettings,
logSettings: typeof jsInstrumentationSettings[0] | { logFunctionsAsStrings: boolean } = { logFunctionsAsStrings: false }, // : LogSettings,
) {
if (inLog) {
return;
Expand Down Expand Up @@ -327,7 +327,16 @@ function logCall(instrumentedFunctionName, args, callContext, _logSettings) {
/**
* Provides the properties per prototype object
*/
Object.getPrototypeByDepth = function (subject, depth) {

declare global {
interface Object {
getPrototypeByDepth(subject: string | undefined, depth: number): any
getPropertyNamesPerDepth(subject: any, maxDepth: number): any
findPropertyInChain(subject, propertyName)
}
}

Object.prototype.getPrototypeByDepth = function (subject, depth) {
if (subject === undefined) {
throw new Error("Can't get property names for undefined");
}
Expand All @@ -348,7 +357,7 @@ Object.getPrototypeByDepth = function (subject, depth) {
* Traverses the prototype chain to collect properties. Returns an array containing
* an object with the depth, propertyNames and scanned subject
*/
Object.getPropertyNamesPerDepth = function (subject, maxDepth = 0) {
Object.prototype.getPropertyNamesPerDepth = function (subject, maxDepth = 0) {
if (subject === undefined) {
throw new Error("Can't get property names for undefined");
}
Expand All @@ -370,7 +379,7 @@ Object.getPropertyNamesPerDepth = function (subject, maxDepth = 0) {
/**
* Finds a property along the prototype chain
*/
Object.findPropertyInChain = function (subject, propertyName) {
Object.prototype.findPropertyInChain = function (subject, propertyName) {
if (subject === undefined || propertyName === undefined) {
throw new Error("Object and property name must be defined");
}
Expand Down Expand Up @@ -457,9 +466,9 @@ function notify(type, content) {
});
}

function filterPropertiesPerDepth(collection, excluded) {
for (let i = 0; i < collection.length; i++) {
collection[i].propertyNames = collection[i].propertyNames.filter(
function filterPropertiesPerDepth<T>(collection: {propertyNames: T[]}[], excluded: T[]) {
for (const elem of collection) {
elem.propertyNames = elem.propertyNames.filter(
(p) => !excluded.includes(p),
);
}
Expand Down
4 changes: 2 additions & 2 deletions Extension/src/stealth/stealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
const interceptedWindows = new WeakMap();
const proxies = new Map();
const changedToStrings = new WeakMap();

export type ModifiedWindow = Window & typeof globalThis & { wrappedJSObject: any };
// Entry point for this extension
(function () {
// console.log("Starting frame script");
try {
interceptWindow(window);
interceptWindow(window as ModifiedWindow);
} catch (error) {
console.log("Instrumentation initialisation crashed. Reason: " + error);
console.log(error.stack);
Expand Down

0 comments on commit 2b4d05c

Please sign in to comment.