mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
LibJS/Bytecode: Throw on destructuring object assignment to nullish LHS
24 new passes on test262. :^)
This commit is contained in:
parent
4032bfc2fc
commit
8021048bc9
4 changed files with 30 additions and 0 deletions
|
@ -989,6 +989,8 @@ Bytecode::CodeGenerationErrorOr<void> FunctionExpression::generate_bytecode(Byte
|
|||
|
||||
static Bytecode::CodeGenerationErrorOr<void> generate_object_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables)
|
||||
{
|
||||
generator.emit<Bytecode::Op::ThrowIfNullish>();
|
||||
|
||||
Vector<Bytecode::Register> excluded_property_names;
|
||||
auto has_rest = false;
|
||||
if (pattern.entries.size() > 0)
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
O(SuperCall) \
|
||||
O(Throw) \
|
||||
O(ThrowIfNotObject) \
|
||||
O(ThrowIfNullish) \
|
||||
O(ToNumeric) \
|
||||
O(Typeof) \
|
||||
O(TypeofVariable) \
|
||||
|
|
|
@ -844,6 +844,15 @@ ThrowCompletionOr<void> ThrowIfNotObject::execute_impl(Bytecode::Interpreter& in
|
|||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> ThrowIfNullish::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto value = interpreter.accumulator();
|
||||
if (value.is_nullish())
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotObjectCoercible, TRY_OR_THROW_OOM(vm, value.to_string_without_side_effects()));
|
||||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> EnterUnwindContext::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.enter_unwind_context(m_handler_target, m_finalizer_target);
|
||||
|
@ -1432,6 +1441,11 @@ DeprecatedString ThrowIfNotObject::to_deprecated_string_impl(Bytecode::Executabl
|
|||
return "ThrowIfNotObject";
|
||||
}
|
||||
|
||||
DeprecatedString ThrowIfNullish::to_deprecated_string_impl(Bytecode::Executable const&) const
|
||||
{
|
||||
return "ThrowIfNullish";
|
||||
}
|
||||
|
||||
DeprecatedString EnterUnwindContext::to_deprecated_string_impl(Bytecode::Executable const&) const
|
||||
{
|
||||
auto handler_string = m_handler_target.has_value() ? DeprecatedString::formatted("{}", *m_handler_target) : "<empty>";
|
||||
|
|
|
@ -958,6 +958,19 @@ public:
|
|||
void replace_references_impl(Register, Register) { }
|
||||
};
|
||||
|
||||
class ThrowIfNullish final : public Instruction {
|
||||
public:
|
||||
ThrowIfNullish()
|
||||
: Instruction(Type::ThrowIfNullish)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
||||
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
||||
void replace_references_impl(Register, Register) { }
|
||||
};
|
||||
|
||||
class EnterUnwindContext final : public Instruction {
|
||||
public:
|
||||
constexpr static bool IsTerminator = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue