🐛 compatible with nested sandbox to avoid stack overflow while createElement calling (#2414)

This commit is contained in:
Kuitos 2023-02-27 22:06:41 +08:00 committed by GitHub
parent 901dac8c7b
commit bcfc96cd62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,8 +50,10 @@ function patchDocument(cfg: { sandbox: SandBox; speedy: boolean }) {
},
get: (target, p) => {
if (p === 'createElement') {
return (...args: Parameters<typeof document.createElement>) => {
const element = document.createElement(...args);
// Must store the original createElement function to avoid error in nested sandbox
const targetCreateElement = target.createElement;
return function createElement(...args: Parameters<typeof document.createElement>) {
const element = targetCreateElement.call(target, ...args);
attachElementToProxy(element, sandbox.proxy);
return element;
};