fasttime / JScrewIt

Write any JavaScript with six characters: ! ( ) + [ ]
https://jscrew.it
ISC License
161 stars 13 forks source link

New feature `CALL_ON_GLOBAL`, new global objects and functions related definitions #53

Closed Clayblockunova closed 1 month ago

Clayblockunova commented 2 months ago

IDK how to simulate it, tho.

fasttime commented 2 months ago

Thanks for the PR. How did you test these definitions? They're all failing for me. Even just running [].sort.call() in a browser in non-strict mode is throwing an error.

Clayblockunova commented 2 months ago

I just simulate it with [].sort.call(self) since I think that's the intended behavior. does INCR_CHAR work under your rest environment? nether CALL_ON_GLOBAL nor INCR_CHAR work when I tried to execute JS code with data URI.

fasttime commented 2 months ago

INCR_CHAR says for example that ++"0"[0] will evaluate to 1. You can see that this is happening in non-strict mode here. In strict mode, the same code will throw an error (here). Now, [].sort.call() throws an error no matter how it is called.

Clayblockunova commented 2 months ago

as someone mentioned in 2012, CALL_ON_GLOBAL would be a feature working on super-legacy platforms. IDK whether are those platforms beyond this project's support.

Clayblockunova commented 2 months ago

should I close this PR now? or should I do anything else?

fasttime commented 2 months ago

Maybe CALL_ON_GLOBAL would be available in ES3 compliant browsers (that don't support strict mode at all). At least this is what the spec suggests at https://tc39.es/ecma262/#sec-function.prototype.call (NOTE 1):

The thisArg value is passed without modification as the this value. This is a change from Edition 3, where an undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value. Even though the thisArg is passed without modification, non-strict functions still perform these transformations upon entry to the function.

I appreciate the idea of this PR but I don't think that JScrewIt would run on such old browsers. Feel free to close if you don't have any other use cases.

Clayblockunova commented 1 month ago

AFAIK from caniuse.com, Android browser 4.0 does not support zero-width chars in identifiers & Immutable undefined. so I reopened the PR, but I still don't know how to simulate.

fasttime commented 1 month ago

AFAIK from caniuse.com, Android browser 4.0 does not support zero-width chars in identifiers & Immutable undefined. so I reopened the PR, but I still don't know how to simulate.

I use Android Studio on Windows x64 to emulate old Android devices. Then I usually start a server on the host from the JScrewIt folder, and enter the URL http\://10.0.2.2/JScrewIt.html in Android browser. I haven't been able to check this PR yet.

Clayblockunova commented 1 month ago

so, what should I do now?

Clayblockunova commented 1 month ago

should I do some change to the makefile? or just leave that for you?

fasttime commented 1 month ago

Sorry, being a little busy at the moment. I checked on Android Browser 4.0 and CALL_ON_GLOBAL is available! But the character definitions are still not working. If you leave this open I could have a later look to see what is wrong.

Clayblockunova commented 1 month ago

should I change Array.prototype.fill definition or just leave it for you?

fasttime commented 1 month ago

Array.prototype.fill does not exist in Android Browser, but even Array.prototype.sort seems unsafe because if window.length is greater than zero, it will overwrite global values window[0], window[1], etc.

Clayblockunova commented 1 month ago

according to MDN, window.length means number of frames in the page. what does window[0] mean? should I close the PR anyway?

fasttime commented 1 month ago

according to MDN, window.length means number of frames in the page. what does window[0] mean?

Yes, those are IFRAME objects. window[0] is the first IFRAME. The value can be overwritten in JavaScript but the DOM doesn't change accordingly (at least not in Android Browser).

should I close the PR anyway?

We can't introduce side effects in the code. If Array.prototype.sort is the only alternative then we can't use this feature, sorry.

Clayblockunova commented 1 month ago

just tried Array.prototype.concat.

Clayblockunova commented 1 month ago

Just added self based variant of global objects and functions.