Closed Le0Developer closed 3 months ago
Implemented in 1.7.2 through a very similar way
@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")
}
});
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:
Also I should note that we can get root by other NON-global function constructors, like GeneratorFunction
or AsyncFunction
or AsyncGeneratorFunction
.
The only way to get pure
this
with ability to check is byeval
. 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.
The current implementation does not work as expected. If
global
is not known, it immediately throws a ReferenceError and does not even trywindow
ornew Function("return this")()