Set.cpp 756 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Set.h>
  7. namespace JS {
  8. Set* Set::create(GlobalObject& global_object)
  9. {
  10. return global_object.heap().allocate<Set>(global_object, *global_object.set_prototype());
  11. }
  12. Set::Set(Object& prototype)
  13. : Object(prototype)
  14. {
  15. }
  16. Set::~Set()
  17. {
  18. }
  19. Set* Set::typed_this(VM& vm, GlobalObject& global_object)
  20. {
  21. auto* this_object = vm.this_value(global_object).to_object(global_object);
  22. if (!this_object)
  23. return {};
  24. if (!is<Set>(this_object)) {
  25. vm.throw_exception<TypeError>(global_object, ErrorType::NotA, "Set");
  26. return nullptr;
  27. }
  28. return static_cast<Set*>(this_object);
  29. }
  30. }