diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-09 21:30:12 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-09 21:49:20 +0100 |
commit | ad401ca09832a5ed01a1b05da2d913fa4091a040 (patch) | |
tree | fd3caed56c285c965733e4a1ec113b898be53f75 | |
parent | 363c40e3f33b6b7e07eb82c1d7998574ef0695bc (diff) | |
download | serenity-ad401ca09832a5ed01a1b05da2d913fa4091a040.zip |
js: Add another little test AST to exercise marking of locals
-rw-r--r-- | Userland/js.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/Userland/js.cpp b/Userland/js.cpp index 419f4b7ced..64ae49abfa 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -32,12 +32,13 @@ #include <stdio.h> //static void build_program_1(JS::Program&); -static void build_program_2(JS::Program&); +//static void build_program_2(JS::Program&); +static void build_program_3(JS::Program&); int main() { auto program = make<JS::Program>(); - build_program_2(*program); + build_program_3(*program); program->dump(0); @@ -47,13 +48,7 @@ int main() printf("%s\n", result.to_string().characters()); - interpreter.heap().allocate<JS::Object>(); - - dbg() << "Collecting garbage..."; - interpreter.heap().collect_garbage(); - - interpreter.global_object().put("foo", JS::Value(123)); - dbg() << "Collecting garbage after overwriting global_object.foo..."; + dbg() << "Collecting garbage on exit..."; interpreter.heap().collect_garbage(); return 0; } @@ -79,6 +74,7 @@ void build_program_1(JS::Program& program) } #endif +#if 0 void build_program_2(JS::Program& program) { // c = 1; @@ -113,3 +109,22 @@ void build_program_2(JS::Program& program) program.append<JS::FunctionDeclaration>("foo", move(block)); program.append<JS::CallExpression>("foo"); } +#endif + +void build_program_3(JS::Program& program) +{ + // function foo() { + // var x = {}; + // $gc(); + // } + // foo(); + + auto block = make<JS::BlockStatement>(); + block->append<JS::VariableDeclaration>( + make<JS::Identifier>("x"), + make<JS::ObjectExpression>()); + block->append<JS::CallExpression>("$gc"); + + program.append<JS::FunctionDeclaration>("foo", move(block)); + program.append<JS::CallExpression>("foo"); +} |