mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibJS: Fix "use strict" directive false positives
By having the "is this a use strict directive?" logic in parse_string_literal() we would apply it to *any* string literal, which is incorrect and would lead to false positives - e.g.: "use strict" + 1 `"use strict"` "\123"; ({"use strict": ...}) Relevant part from the spec which is now implemented properly: [...] and where each ExpressionStatement in the sequence consists entirely of a StringLiteral token [...] I also got rid of UseStrictDirectiveState which is not needed anymore. Fixes #3903.
This commit is contained in:
parent
21912123c4
commit
9e80c67608
4 changed files with 54 additions and 55 deletions
|
@ -64,6 +64,8 @@ public:
|
|||
virtual bool is_call_expression() const { return false; }
|
||||
virtual bool is_new_expression() const { return false; }
|
||||
virtual bool is_super_expression() const { return false; }
|
||||
virtual bool is_expression_statement() const { return false; };
|
||||
virtual bool is_string_literal() const { return false; };
|
||||
|
||||
protected:
|
||||
ASTNode() { }
|
||||
|
@ -99,11 +101,15 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
Value execute(Interpreter&, GlobalObject&) const override;
|
||||
const char* class_name() const override { return "ExpressionStatement"; }
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual bool is_expression_statement() const override { return true; }
|
||||
|
||||
const Expression& expression() const { return m_expression; };
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "ExpressionStatement"; }
|
||||
|
||||
NonnullRefPtr<Expression> m_expression;
|
||||
};
|
||||
|
||||
|
@ -590,20 +596,24 @@ private:
|
|||
|
||||
class StringLiteral final : public Literal {
|
||||
public:
|
||||
explicit StringLiteral(String value)
|
||||
explicit StringLiteral(String value, bool is_use_strict_directive = false)
|
||||
: m_value(move(value))
|
||||
, m_is_use_strict_directive(is_use_strict_directive)
|
||||
{
|
||||
}
|
||||
|
||||
StringView value() const { return m_value; }
|
||||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual bool is_string_literal() const override { return true; };
|
||||
|
||||
StringView value() const { return m_value; }
|
||||
bool is_use_strict_directive() const { return m_is_use_strict_directive; };
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "StringLiteral"; }
|
||||
|
||||
String m_value;
|
||||
bool m_is_use_strict_directive;
|
||||
};
|
||||
|
||||
class NullLiteral final : public Literal {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue