mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:57:46 +00:00
LibJS: Make indirect bindings of module behave like normal bindings
Before this we attempted to hack around this by only overriding has_binding. However this did not cover all cases, for example when assigning to variables before their declaration it didn't throw. By using the new find_binding_and_index virtual method we can just pretend the indirect bindings are real. Since indirect binding do come from a normal environment we need to ensure you cannot modify the binding and that properties like mutable are false as expected by the spec for such an indirect binding.
This commit is contained in:
parent
2484bbc4e0
commit
0fc67ffd62
5 changed files with 85 additions and 17 deletions
|
@ -27,12 +27,6 @@ public:
|
|||
virtual ThrowCompletionOr<Value> get_this_binding(VM&) const final;
|
||||
ThrowCompletionOr<void> create_import_binding(FlyString name, Module* module, FlyString binding_name);
|
||||
|
||||
// Note: Although the spec does not explicitly say this we also have to implement HasBinding as
|
||||
// the HasBinding method of Declarative Environment records states:
|
||||
// "It determines if the argument identifier is one of the identifiers bound by the record"
|
||||
// And this means that we have to include the indirect bindings of a Module Environment.
|
||||
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override;
|
||||
|
||||
private:
|
||||
explicit ModuleEnvironment(Environment* outer_environment);
|
||||
|
||||
|
@ -43,6 +37,8 @@ private:
|
|||
};
|
||||
IndirectBinding const* get_indirect_binding(FlyString const& name) const;
|
||||
|
||||
virtual Optional<BindingAndIndex> find_binding_and_index(FlyString const& name) const override;
|
||||
|
||||
// FIXME: Since we always access this via the name this could be a map.
|
||||
Vector<IndirectBinding> m_indirect_bindings;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue