开发者

stop javascript execution

开发者 https://www.devze.com 2022-12-27 01:56 出处:网络
When I run javascript script file in wi开发者_开发百科ndows command line environment, and there is a free text coming after my code. How can I stop javascript interpreter to run into it?

When I run javascript script file in wi开发者_开发百科ndows command line environment, and there is a free text coming after my code. How can I stop javascript interpreter to run into it? For example:

var fso = new ActiveXObject("Scripting.FileSystemObject");
delete fso;
exit(); // some kind of WORKING exit command
Hungry lazy frog ate a big brown fox.


There is nothing you can do to stop the interpreter before it the compiler sees a particular line because the whole Javascript source file is first compiled to bytecode and it is the bytecode that is interpreted not your source code.

What you could do (though it would still be messy) would be to put some free text in a comment at the end of the file. Then you could open the source file and read it from the rest of the code. It still can't be completely free text though as it would have to be a valid comment

/*
 whatever text you want provided it doesn't contain * followed immediately by /
 */

Much better is simply to admit defeat and store any data you need in a separate file.


If you surround that with quotes it will be interpreted/compiled but will have no effect eg

var fso = new ActiveXObject("Scripting.FileSystemObject");
delete fso;
exit(); // some kind of WORKING exit command
"Hungry lazy frog ate a big brown fox.";


Even if you did exit, you'd still have a problem because the whole script block needs to be parsed before the first instruction is executed. With any bogus content following an exit instruction, the script would fail to parse at all, even though that code would never be reached.

If the free text was a single line, you could get away with a trailing //. Doesn't work for multi-line comments though, as you would need a closing */. Same for conditional-comments requiring /*@end @*/.

0

精彩评论

暂无评论...
验证码 换一张
取 消