mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:38:10 +00:00
LibJS: Make Reference aware of DeclarativeEnvironment indices
VM::resolve_binding() can now return a Reference that knows the exact binding index if it's pointing into a DeclarativeEnvironment. Reading/writing through the Reference will now use direct environment access when possible.
This commit is contained in:
parent
540ce075b6
commit
4444bcabde
3 changed files with 14 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Runtime/DeclarativeEnvironment.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Reference.h>
|
||||
|
@ -48,7 +49,10 @@ void Reference::put_value(GlobalObject& global_object, Value value)
|
|||
|
||||
VERIFY(m_base_type == BaseType::Environment);
|
||||
VERIFY(m_base_environment);
|
||||
m_base_environment->set_mutable_binding(global_object, m_name.as_string(), value, m_strict);
|
||||
if (m_index_in_declarative_environment.has_value())
|
||||
static_cast<DeclarativeEnvironment*>(m_base_environment)->set_mutable_binding_direct(global_object, m_index_in_declarative_environment.value(), value, m_strict);
|
||||
else
|
||||
m_base_environment->set_mutable_binding(global_object, m_name.as_string(), value, m_strict);
|
||||
}
|
||||
|
||||
void Reference::throw_reference_error(GlobalObject& global_object) const
|
||||
|
@ -77,6 +81,8 @@ Value Reference::get_value(GlobalObject& global_object) const
|
|||
|
||||
VERIFY(m_base_type == BaseType::Environment);
|
||||
VERIFY(m_base_environment);
|
||||
if (m_index_in_declarative_environment.has_value())
|
||||
return static_cast<DeclarativeEnvironment*>(m_base_environment)->get_binding_value_direct(global_object, m_index_in_declarative_environment.value(), m_strict);
|
||||
return m_base_environment->get_binding_value(global_object, m_name.as_string(), m_strict);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue