ShadowRealm.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Completion.h>
  8. #include <LibJS/Runtime/Object.h>
  9. #include <LibJS/Runtime/Realm.h>
  10. namespace JS {
  11. class ShadowRealm final : public Object {
  12. JS_OBJECT(ShadowRealm, Object);
  13. public:
  14. ShadowRealm(Realm&, ExecutionContext, Object& prototype);
  15. virtual ~ShadowRealm() override = default;
  16. [[nodiscard]] Realm const& shadow_realm() const { return m_shadow_realm; }
  17. [[nodiscard]] Realm& shadow_realm() { return m_shadow_realm; }
  18. [[nodiscard]] ExecutionContext const& execution_context() const { return m_execution_context; }
  19. [[nodiscard]] ExecutionContext& execution_context() { return m_execution_context; }
  20. private:
  21. virtual void visit_edges(Visitor&) override;
  22. // 3.5 Properties of ShadowRealm Instances, https://tc39.es/proposal-shadowrealm/#sec-properties-of-shadowrealm-instances
  23. Realm& m_shadow_realm; // [[ShadowRealm]]
  24. ExecutionContext m_execution_context; // [[ExecutionContext]]
  25. };
  26. ThrowCompletionOr<void> copy_name_and_length(GlobalObject&, FunctionObject& function, FunctionObject& target, StringView prefix, Optional<unsigned> arg_count = {});
  27. ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
  28. ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject&, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context);
  29. ThrowCompletionOr<Value> get_wrapped_value(GlobalObject&, Realm& caller_realm, Value);
  30. }