mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +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
|
@ -442,12 +442,14 @@ Reference VM::get_identifier_reference(Environment* environment, FlyString name,
|
|||
// a. Return the Reference Record { [[Base]]: unresolvable, [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]: empty }.
|
||||
return Reference { Reference::BaseType::Unresolvable, move(name), strict };
|
||||
}
|
||||
auto exists = environment->has_binding(name);
|
||||
|
||||
Optional<size_t> index;
|
||||
auto exists = environment->has_binding(name, &index);
|
||||
if (exception())
|
||||
return {};
|
||||
|
||||
if (exists)
|
||||
return Reference { *environment, move(name), strict };
|
||||
return Reference { *environment, move(name), strict, index };
|
||||
else
|
||||
return get_identifier_reference(environment->outer_environment(), move(name), strict);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue