Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix __getGlobal in BufferToStringTemplate #112

Closed

Conversation

Le0Developer
Copy link

The current implementation does not work as expected.
If global is not known, it immediately throws a ReferenceError and does not even try window or new Function("return this")()

@MichaelXF
Copy link
Owner

Implemented in 1.7.2 through a very similar way

@MichaelXF MichaelXF closed this Aug 4, 2024
@doctor8296
Copy link

@MichaelXF little note about getting global object.
Code can be wrapped in other function like this:

(function(window, globalThis, self, global) {
    // code
})(fakeProxyWindow, fakeProxyWindow, fakeProxyWindow, fakeProxyWindow)

and Function can be easily redefined.

window.Function = Function.prototype.constructor = new Proxy(Function, {
    apply(target, thisArg, args) {
         return Reflect.apply(target, thisArg, args).bind("fakeProxyWindowObject")
    }
});

image

The only way to get pure this with ability to check is by eval.
Eval has unique behaviour. It has access to the local scope, unless it is redefined.

let check = false;
eval("check = true")
if (!check) {
    throw new Error("Eval was redefined")
}

const root = eval("this");

Example:
image

@Le0Developer Le0Developer deleted the fix/tostring-template branch August 5, 2024 10:58
@doctor8296
Copy link

doctor8296 commented Aug 5, 2024

Also I should note that we can get root by other NON-global function constructors, like GeneratorFunction or AsyncFunction or AsyncGeneratorFunction.
Screenshot 2024-08-05 at 13 58 54

@MichaelXF
Copy link
Owner

The only way to get pure this with ability to check is by eval. Eval has unique behaviour. It has access to the local scope, unless it is redefined.

let check = false;
eval("check = true")
if (!check) {
    throw new Error("Eval was redefined")
}

const root = eval("this");

This is great, I'll try to find a way to implement this trick.

@MichaelXF MichaelXF linked an issue Aug 7, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get Global Improvements
3 participants