aemkei / jsfuck

Write any JavaScript with 6 Characters: []()!+
jsfuck.com
Do What The F*ck You Want To Public License
8.14k stars 672 forks source link

Why `escapeSequence()` treat characters whose charCodes is under 256 as ascii, not utf-16? #115

Closed yichung279 closed 3 years ago

yichung279 commented 3 years ago

In escapeSequence(),characters whose charCodes is under 256 will turn into ascii code. However, it works well if we treat it as utf-16. Both "\141" and "\u0061" represent "a". https://github.com/aemkei/jsfuck/blob/94c38357375e5009ebeb97fcc6934aaea482b210/jsfuck.js#L232-L240

Is

if (cc < 256) { 
     return '\\' + cc.toString(8); 
} 

a necessary statement?

yichung279 commented 3 years ago

If it is not necessary, I remove it in #116

frobinsonj commented 3 years ago

Although both work, this was added as the resulting jsfuck is shorter when representing ASCII chars using the ISO-8859-1 escape notation (\XXX (where XXX is 1–3 octal digits; range of 0–377)). See pull requests #93 and #88 :)

hazzik commented 3 years ago

This was done to optimize the length of resulting code

yichung279 commented 3 years ago

Oh, I see. What a great work!