ShadowRealm.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/ExecutionContext.h>
  9. #include <LibJS/Runtime/Object.h>
  10. #include <LibJS/Runtime/Realm.h>
  11. namespace JS {
  12. class ShadowRealm final : public Object {
  13. JS_OBJECT(ShadowRealm, Object);
  14. JS_DECLARE_ALLOCATOR(ShadowRealm);
  15. public:
  16. virtual ~ShadowRealm() override = default;
  17. [[nodiscard]] Realm const& shadow_realm() const { return m_shadow_realm; }
  18. [[nodiscard]] Realm& shadow_realm() { return m_shadow_realm; }
  19. [[nodiscard]] ExecutionContext const& execution_context() const { return *m_execution_context; }
  20. [[nodiscard]] ExecutionContext& execution_context() { return *m_execution_context; }
  21. private:
  22. ShadowRealm(Realm&, NonnullOwnPtr<ExecutionContext>, Object& prototype);
  23. virtual void visit_edges(Visitor&) override;
  24. // 3.5 Properties of ShadowRealm Instances, https://tc39.es/proposal-shadowrealm/#sec-properties-of-shadowrealm-instances
  25. NonnullGCPtr<Realm> m_shadow_realm; // [[ShadowRealm]]
  26. NonnullOwnPtr<ExecutionContext> m_execution_context; // [[ExecutionContext]]
  27. };
  28. ThrowCompletionOr<void> copy_name_and_length(VM&, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix = {}, Optional<unsigned> arg_count = {});
  29. ThrowCompletionOr<Value> perform_shadow_realm_eval(VM&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
  30. ThrowCompletionOr<Value> shadow_realm_import_value(VM&, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context);
  31. ThrowCompletionOr<Value> get_wrapped_value(VM&, Realm& caller_realm, Value);
  32. }