WithScope.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/AST.h>
  7. #include <LibJS/Runtime/WithScope.h>
  8. namespace JS {
  9. WithScope::WithScope(Object& object, ScopeObject* parent_scope)
  10. : ScopeObject(parent_scope)
  11. , m_object(object)
  12. {
  13. }
  14. void WithScope::visit_edges(Cell::Visitor& visitor)
  15. {
  16. Base::visit_edges(visitor);
  17. visitor.visit(&m_object);
  18. }
  19. Optional<Variable> WithScope::get_from_scope(const FlyString& name) const
  20. {
  21. auto value = m_object.get(name);
  22. if (value.is_empty())
  23. return {};
  24. return Variable { value, DeclarationKind::Var };
  25. }
  26. void WithScope::put_to_scope(const FlyString& name, Variable variable)
  27. {
  28. m_object.put(name, variable.value);
  29. }
  30. bool WithScope::delete_from_scope(FlyString const& name)
  31. {
  32. return m_object.delete_property(name);
  33. }
  34. bool WithScope::has_this_binding() const
  35. {
  36. return parent()->has_this_binding();
  37. }
  38. Value WithScope::get_this_binding(GlobalObject& global_object) const
  39. {
  40. return parent()->get_this_binding(global_object);
  41. }
  42. }