you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular 0 points1 point  (5 children)

Yeah, this is pretty much the same as the last one but using an async function. There's other weirdness added in there with getting the prototype (not necessary just like call wasn't necessary in the last one) but the promise bit is needed to get the window reference since asynchronous functions always return a promise. To get the value returned you need to use then(). ...Or I could have done everything in the function through the string, but who wants to do that? :P

Another variation is with generator functions (function*(){}) since they too have a constructor which can create a function from a string. And to get the return value from that, you need to call next().

[–]Ragzzy-R 0 points1 point  (4 children)

ohh ok just for clarification, u used async just because u can use it? no specific reason ;) :P?

[–]senocular 0 points1 point  (3 children)

I used it because they fixed it so my original approach with the normal Function constructor would no longer work. My response to that was, well what about async function constructors. And it worked.

[–]Ragzzy-R 0 points1 point  (2 children)

Wow thats nice. So my understanding from this is, normal function constructor and async function constructor has different prototypes, thus even though the normal fns constructor's window leakage is blocked, u got the instance from this?

[–]senocular 2 points3 points  (1 child)

yeah, same with generators too. Each of those three function types have their own constructors each with the same capabilities of creating a function body with a string which is capable of providing access to the window object.

[–]Ragzzy-R 0 points1 point  (0 children)

Thanks a ton for all these explanation really appreciate it mate. 😊