
Before this we used an ad-hoc combination of references and 'variables' stored in a hashmap. This worked in most cases but is not spec like. Additionally hoisting, dynamically naming functions and scope analysis was not done properly. This patch fixes all of that by: - Implement BindingInitialization for destructuring assignment. - Implementing a new ScopePusher which tracks the lexical and var scoped declarations. This hoists functions to the top level if no lexical declaration name overlaps. Furthermore we do checking of redeclarations in the ScopePusher now requiring less checks all over the place. - Add methods for parsing the directives and statement lists instead of having that code duplicated in multiple places. This allows declarations to pushed to the appropriate scope more easily. - Remove the non spec way of storing 'variables' in DeclarativeEnvironment and make Reference follow the spec instead of checking both the bindings and 'variables'. - Remove all scoping related things from the Interpreter. And instead use environments as specified by the spec. This also includes fixing that NativeFunctions did not produce a valid FunctionEnvironment which could cause issues with callbacks and eval. All FunctionObjects now have a valid NewFunctionEnvironment implementation. - Remove execute_statements from Interpreter and instead use ASTNode::execute everywhere this simplifies AST.cpp as you no longer need to worry about which method to call. - Make ScopeNodes setup their own environment. This uses four different methods specified by the spec {Block, Function, Eval, Global}DeclarationInstantiation with the annexB extensions. - Implement and use NamedEvaluation where specified. Additionally there are fixes to things exposed by these changes to eval, {for, for-in, for-of} loops and assignment. Finally it also fixes some tests in test-js which where passing before but not now that we have correct behavior :^).
64 lines
2.6 KiB
C++
64 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Runtime/Completion.h>
|
|
#include <LibJS/Runtime/FunctionObject.h>
|
|
|
|
namespace JS {
|
|
|
|
class ProxyObject final : public FunctionObject {
|
|
JS_OBJECT(ProxyObject, FunctionObject);
|
|
|
|
public:
|
|
static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
|
|
|
|
ProxyObject(Object& target, Object& handler, Object& prototype);
|
|
virtual ~ProxyObject() override;
|
|
|
|
virtual Value call() override;
|
|
virtual Value construct(FunctionObject& new_target) override;
|
|
virtual const FlyString& name() const override;
|
|
virtual FunctionEnvironment* new_function_environment(Object* new_target) override;
|
|
virtual bool has_constructor() const override { return true; }
|
|
|
|
const Object& target() const { return m_target; }
|
|
const Object& handler() const { return m_handler; }
|
|
|
|
bool is_revoked() const { return m_is_revoked; }
|
|
void revoke() { m_is_revoked = true; }
|
|
|
|
// 10.5 Proxy Object Internal Methods and Internal Slots, https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots
|
|
|
|
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
|
virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
|
|
virtual ThrowCompletionOr<bool> internal_is_extensible() const override;
|
|
virtual ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
|
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyName const&) const override;
|
|
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
|
|
virtual ThrowCompletionOr<bool> internal_has_property(PropertyName const&) const override;
|
|
virtual ThrowCompletionOr<Value> internal_get(PropertyName const&, Value receiver) const override;
|
|
virtual ThrowCompletionOr<bool> internal_set(PropertyName const&, Value value, Value receiver) override;
|
|
virtual ThrowCompletionOr<bool> internal_delete(PropertyName const&) override;
|
|
virtual ThrowCompletionOr<MarkedValueList> internal_own_property_keys() const override;
|
|
|
|
private:
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
virtual bool is_function() const override { return m_target.is_function(); }
|
|
virtual bool is_proxy_object() const final { return true; }
|
|
|
|
Object& m_target;
|
|
Object& m_handler;
|
|
bool m_is_revoked { false };
|
|
};
|
|
|
|
template<>
|
|
inline bool Object::fast_is<ProxyObject>() const { return is_proxy_object(); }
|
|
|
|
}
|