mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
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.
This commit is contained in:
parent
5ae9419a06
commit
786722149b
8 changed files with 172 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue