summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/AST.h
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-05-27 22:22:08 -0700
committerAndreas Kling <kling@serenityos.org>2020-05-28 17:18:42 +0200
commit786722149b5084dc52be0bdecf2d5628662d0941 (patch)
tree9a5afc8eac66b0602a4341e449ea404161d81100 /Libraries/LibJS/AST.h
parent5ae9419a069f8180197df14447b1a23f1cf9411d (diff)
downloadserenity-786722149b5084dc52be0bdecf2d5628662d0941.zip
LibJS: Add strict mode
Adds the ability for a scope (either a function or the entire program) to be in strict mode. Scopes default to non-strict mode. There are two ways to determine the strict-ness of the JS engine: 1. In the parser, this can be accessed with the parser_state variable m_is_strict_mode boolean. If true, the Parser is currently parsing in strict mode. This is done so that the Parser can generate syntax errors at parse time, which is required in some cases. 2. With Interpreter.is_strict_mode(). This allows strict mode checking at runtime as opposed to compile time. Additionally, in order to test this, a global isStrictMode() function has been added to the JS ReplObject under the test-mode flag.
Diffstat (limited to 'Libraries/LibJS/AST.h')
-rw-r--r--Libraries/LibJS/AST.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h
index 4dd15e5723..be605409c9 100644
--- a/Libraries/LibJS/AST.h
+++ b/Libraries/LibJS/AST.h
@@ -120,6 +120,9 @@ public:
void add_variables(NonnullRefPtrVector<VariableDeclaration>);
const NonnullRefPtrVector<VariableDeclaration>& variables() const { return m_variables; }
+ bool in_strict_mode() const { return m_strict_mode; }
+ void set_strict_mode() { m_strict_mode = true; }
+
protected:
ScopeNode() { }
@@ -127,6 +130,7 @@ private:
virtual bool is_scope_node() const final { return true; }
NonnullRefPtrVector<Statement> m_children;
NonnullRefPtrVector<VariableDeclaration> m_variables;
+ bool m_strict_mode { false };
};
class Program : public ScopeNode {