ShadowRealm.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, 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<Value> perform_shadow_realm_eval(GlobalObject&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
  27. ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject&, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context);
  28. ThrowCompletionOr<Value> get_wrapped_value(GlobalObject&, Realm& caller_realm, Value);
  29. }