refactor: add getOwnPropertyDescriptor to sandbox proxies for enhanced property handling

This commit is contained in:
Nawaz Dhandala
2026-03-06 18:12:53 +00:00
parent d4f9791732
commit 47c136a140

View File

@@ -123,6 +123,27 @@ function createSandboxProxy(
);
});
},
getOwnPropertyDescriptor(
fnTarget: (...args: unknown[]) => unknown,
prop: string | symbol,
): PropertyDescriptor | undefined {
if (
typeof prop === "string" &&
BLOCKED_SANDBOX_PROPERTIES.has(prop)
) {
return undefined;
}
const desc: PropertyDescriptor | undefined =
Reflect.getOwnPropertyDescriptor(fnTarget, prop);
if (desc && "value" in desc) {
desc.value = createSandboxProxy(
desc.value,
cache,
fnTarget as GenericObject,
);
}
return desc;
},
},
);
return fnProxy;
@@ -165,6 +186,20 @@ function createSandboxProxy(
return !(typeof k === "string" && BLOCKED_SANDBOX_PROPERTIES.has(k));
});
},
getOwnPropertyDescriptor(
objTarget: GenericObject,
prop: string | symbol,
): PropertyDescriptor | undefined {
if (typeof prop === "string" && BLOCKED_SANDBOX_PROPERTIES.has(prop)) {
return undefined;
}
const desc: PropertyDescriptor | undefined =
Reflect.getOwnPropertyDescriptor(objTarget, prop);
if (desc && "value" in desc) {
desc.value = createSandboxProxy(desc.value, cache, objTarget);
}
return desc;
},
});
cache.set(target, objProxy);