mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 04:45:06 +00:00
js: Take the script file as a command-line argument
Now that we have the beginnings of a parser, let's take the script to run as a command-line argument and move all the test scripts into /home/anon/js :^) To run a script, simply use "js": $ js my-script.js To get an AST dump before execution, you can use "js -A"
This commit is contained in:
parent
0d42097cf1
commit
4d942cc1d0
7 changed files with 56 additions and 141 deletions
5
Base/home/anon/js/forced-gc.js
Normal file
5
Base/home/anon/js/forced-gc.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
function foo() {
|
||||
var x = {};
|
||||
$gc();
|
||||
}
|
||||
foo();
|
2
Base/home/anon/js/simple-function.js
Normal file
2
Base/home/anon/js/simple-function.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() { return (1 + 2) + 3; }
|
||||
foo();
|
7
Base/home/anon/js/simple-parse.js
Normal file
7
Base/home/anon/js/simple-parse.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
var foo = 1;
|
||||
function bar() {
|
||||
return 38;
|
||||
}
|
||||
foo = {};
|
||||
foo = bar() + 4;
|
||||
foo;
|
9
Base/home/anon/js/simple-scopes.js
Normal file
9
Base/home/anon/js/simple-scopes.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
function foo() {
|
||||
function bar() {
|
||||
var y = 6;
|
||||
}
|
||||
|
||||
bar()
|
||||
return y;
|
||||
}
|
||||
foo(); //I should return `undefined` because y is bound to the inner-most enclosing function, i.e the nested one (bar()), therefore, it's undefined in the scope of foo()
|
7
Base/home/anon/js/simple-variables.js
Normal file
7
Base/home/anon/js/simple-variables.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
c = 1;
|
||||
function foo() {
|
||||
var a = 5;
|
||||
var b = 7;
|
||||
return a + b + c;
|
||||
}
|
||||
foo();
|
3
Base/home/anon/js/string-length.js
Normal file
3
Base/home/anon/js/string-length.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
"hello friends".length
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue