BooleanConstructor.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2020, Jack Karamanian <karamanian.jack@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Heap/Heap.h>
  7. #include <LibJS/Runtime/BooleanConstructor.h>
  8. #include <LibJS/Runtime/BooleanObject.h>
  9. #include <LibJS/Runtime/BooleanPrototype.h>
  10. #include <LibJS/Runtime/GlobalObject.h>
  11. namespace JS {
  12. BooleanConstructor::BooleanConstructor(GlobalObject& global_object)
  13. : NativeFunction(vm().names.Boolean, *global_object.function_prototype())
  14. {
  15. }
  16. void BooleanConstructor::initialize(GlobalObject& global_object)
  17. {
  18. auto& vm = this->vm();
  19. NativeFunction::initialize(global_object);
  20. define_property(vm.names.prototype, Value(global_object.boolean_prototype()), 0);
  21. define_property(vm.names.length, Value(1), Attribute::Configurable);
  22. }
  23. BooleanConstructor::~BooleanConstructor()
  24. {
  25. }
  26. Value BooleanConstructor::call()
  27. {
  28. return Value(vm().argument(0).to_boolean());
  29. }
  30. Value BooleanConstructor::construct(Function&)
  31. {
  32. return BooleanObject::create(global_object(), vm().argument(0).to_boolean());
  33. }
  34. }