mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +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
|
@ -26,10 +26,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AST.h"
|
||||
#include "Lexer.h"
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Lexer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -134,12 +134,20 @@ private:
|
|||
void save_state();
|
||||
void load_state();
|
||||
|
||||
enum class UseStrictDirectiveState {
|
||||
None,
|
||||
Looking,
|
||||
Found,
|
||||
};
|
||||
|
||||
struct ParserState {
|
||||
Lexer m_lexer;
|
||||
Token m_current_token;
|
||||
Vector<Error> m_errors;
|
||||
Vector<NonnullRefPtrVector<VariableDeclaration>> m_var_scopes;
|
||||
Vector<NonnullRefPtrVector<VariableDeclaration>> m_let_scopes;
|
||||
UseStrictDirectiveState m_use_strict_directive { UseStrictDirectiveState::None };
|
||||
bool m_strict_mode { false };
|
||||
|
||||
explicit ParserState(Lexer);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue