ExecutionContext.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/DeprecatedFlyString.h>
  10. #include <AK/WeakPtr.h>
  11. #include <LibJS/Bytecode/Instruction.h>
  12. #include <LibJS/Forward.h>
  13. #include <LibJS/Heap/MarkedVector.h>
  14. #include <LibJS/Module.h>
  15. #include <LibJS/Runtime/PrivateEnvironment.h>
  16. #include <LibJS/Runtime/Value.h>
  17. #include <LibJS/SourceRange.h>
  18. namespace JS {
  19. using ScriptOrModule = Variant<Empty, NonnullGCPtr<Script>, NonnullGCPtr<Module>>;
  20. // 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
  21. struct ExecutionContext {
  22. explicit ExecutionContext(Heap& heap);
  23. [[nodiscard]] ExecutionContext copy() const;
  24. void visit_edges(Cell::Visitor&);
  25. private:
  26. explicit ExecutionContext(MarkedVector<Value> existing_arguments, MarkedVector<Value> existing_local_variables);
  27. public:
  28. GCPtr<FunctionObject> function; // [[Function]]
  29. GCPtr<Realm> realm; // [[Realm]]
  30. ScriptOrModule script_or_module; // [[ScriptOrModule]]
  31. GCPtr<Environment> lexical_environment; // [[LexicalEnvironment]]
  32. GCPtr<Environment> variable_environment; // [[VariableEnvironment]]
  33. GCPtr<PrivateEnvironment> private_environment; // [[PrivateEnvironment]]
  34. // Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
  35. GCPtr<Cell> context_owner;
  36. Optional<Bytecode::InstructionStreamIterator> instruction_stream_iterator;
  37. DeprecatedFlyString function_name;
  38. Value this_value;
  39. MarkedVector<Value> arguments;
  40. MarkedVector<Value> local_variables;
  41. bool is_strict_mode { false };
  42. // https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
  43. // FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
  44. size_t skip_when_determining_incumbent_counter { 0 };
  45. };
  46. }