5 ms·
JavaScript doesn't get compiled into binary. The human readable source code file just gets processed directly by an engine that executes each command. You're ri
by ryusage 14y ago
JavaScript doesn't get compiled into binary. The human readable source code file just gets processed directly by an engine that executes each command. You're right though, the fact that this is in a form that's so easy to read is extremely surprising.
Normally what's done with script languages like JavaScript is to obfuscate the file by processing it with a tool that would rename everything to be meaningless, and change spacing, line breaks, etc in a way that is still executable, but overwhelmingly tedious/difficult for any human to read and understand.
Did they really ship the game with such open sourced code? For a company so concerned about preventing piracy, I find that pretty hard to believe. It's like they didn't even try.
- derefr 14y ago> JavaScript doesn't get compiled into binary. Well, it can. V8 and other Javascript engines do Just-In-Time (JIT) binary compilation, meaning that they start by interpreting and executing each line of code as they read it, but when they see a function getting executed a lot, they convert just that function to native machine code as a performance optimization for the next time it gets called. And, because this does happen, you can ship compiled Javascript--by dumping the memory-image of the Javascript interpreter after running it for a while (JITed routines and all) and then reloading it on the client end. node-webkit (an application framework similar to the one EA/Maxis uses for SimCity's UI) has a good example of this concept in action: https://github.com/rogerwang/node-webkit/wiki/Protect-JavaScript-source-code-with-v8-snapshot https://github.com/rogerwang/node-webkit/wiki/Protect-JavaSc...
- munificent 14y ago> meaning that they start by interpreting and executing each line of code as they read it, but when they see a function getting executed a lot, they convert just that function to native machine code as a performance optimization for the next time it gets called. Technically V8 does not have an interpreter pass at all. It always JITs to machine code. It does have two compilers though: a fast JIT and a slow JIT. The fast one gets code running as quickly as possible so your app starts fast, but doesn't generate optimal code. The slow JIT kicks in for hot code and spends more timing compiling it to something that will run faster.
- zevyoura 14y agoThe pastebin has been de-obfuscated and manually cleaned up significantly compared to the original that's bundled with the game.
- ryusage 14y agoAh, thank you. That makes infinitely more sense.
- jfoutz 14y agoAnother trick, that's clearly not as fancy as derefr's, its to parse the js, then save the interpreter and parsed ast as a big binary. The dart guys are always talking about how long it takes to parse js. it's not a huge win, but still quicker doing the parsing up front.