1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 17:28:11 +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:
Matthew Olsson 2020-05-27 22:22:08 -07:00 committed by Andreas Kling
parent 5ae9419a06
commit 786722149b
8 changed files with 172 additions and 2 deletions

View file

@ -31,6 +31,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <LibJS/AST.h>
#include <LibJS/Console.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Heap.h>
@ -123,6 +124,8 @@ public:
const LexicalEnvironment* current_environment() const { return m_call_stack.last().environment; }
LexicalEnvironment* current_environment() { return m_call_stack.last().environment; }
bool in_strict_mode() const { return m_scope_stack.last().scope_node->in_strict_mode(); }
size_t argument_count() const
{
if (m_call_stack.is_empty())