StringObject.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibJS/Runtime/GlobalObject.h>
  8. #include <LibJS/Runtime/PrimitiveString.h>
  9. #include <LibJS/Runtime/StringObject.h>
  10. namespace JS {
  11. StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString& primitive_string)
  12. {
  13. return global_object.heap().allocate<StringObject>(global_object, primitive_string, *global_object.string_prototype());
  14. }
  15. StringObject::StringObject(PrimitiveString& string, Object& prototype)
  16. : Object(prototype)
  17. , m_string(string)
  18. {
  19. }
  20. StringObject::~StringObject()
  21. {
  22. }
  23. void StringObject::initialize(GlobalObject& global_object)
  24. {
  25. auto& vm = this->vm();
  26. Object::initialize(global_object);
  27. define_property(vm.names.length, Value(m_string.string().length()), 0);
  28. }
  29. void StringObject::visit_edges(Cell::Visitor& visitor)
  30. {
  31. Object::visit_edges(visitor);
  32. visitor.visit(&m_string);
  33. }
  34. }