ShadowRealm.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. public:
  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. ShadowRealm(Realm&, ExecutionContext, Object& prototype);
  22. virtual void visit_edges(Visitor&) override;
  23. // 3.5 Properties of ShadowRealm Instances, https://tc39.es/proposal-shadowrealm/#sec-properties-of-shadowrealm-instances
  24. NonnullGCPtr<Realm> m_shadow_realm; // [[ShadowRealm]]
  25. ExecutionContext m_execution_context; // [[ExecutionContext]]
  26. };
  27. ThrowCompletionOr<void> copy_name_and_length(VM&, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix = {}, Optional<unsigned> arg_count = {});
  28. ThrowCompletionOr<Value> perform_shadow_realm_eval(VM&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
  29. ThrowCompletionOr<Value> shadow_realm_import_value(VM&, DeprecatedString specifier_string, DeprecatedString export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context);
  30. ThrowCompletionOr<Value> get_wrapped_value(VM&, Realm& caller_realm, Value);
  31. }