diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-09 21:13:55 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-09 21:49:20 +0100 |
commit | 1382dbc5e19cb16b3eee672745d3782188ed5749 (patch) | |
tree | 6a6748e2b55b7893c1a5f8c116293d33be1f5e49 /Libraries/LibJS/Interpreter.h | |
parent | ac3c19b91cd4c8785707952cf890e6c496c33790 (diff) | |
download | serenity-1382dbc5e19cb16b3eee672745d3782188ed5749.zip |
LibJS: Add basic support for (scoped) variables
It's now possible to assign expressions to variables. The variables are
put into the current scope of the interpreter.
Variable lookup follows the scope chain, ending in the global object.
Diffstat (limited to 'Libraries/LibJS/Interpreter.h')
-rw-r--r-- | Libraries/LibJS/Interpreter.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index 3de8e0a99e..e13dc8e518 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -26,6 +26,7 @@ #pragma once +#include <AK/HashMap.h> #include <AK/Vector.h> #include <LibJS/Forward.h> #include <LibJS/Heap.h> @@ -34,6 +35,7 @@ namespace JS { struct ScopeFrame { const ScopeNode& scope_node; + HashMap<String, Value> variables; }; class Interpreter { @@ -50,6 +52,10 @@ public: void do_return(); + Value get_variable(const String& name); + void set_variable(String name, Value); + void declare_variable(String name); + private: void enter_scope(const ScopeNode&); void exit_scope(const ScopeNode&); |