ExecutionContext.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include <LibJS/Bytecode/Executable.h>
  9. #include <LibJS/Runtime/ExecutionContext.h>
  10. #include <LibJS/Runtime/FunctionObject.h>
  11. namespace JS {
  12. ExecutionContext::ExecutionContext(Heap& heap)
  13. : arguments(heap)
  14. , local_variables(heap)
  15. {
  16. }
  17. ExecutionContext::ExecutionContext(MarkedVector<Value> existing_arguments, MarkedVector<Value> existing_local_variables)
  18. : arguments(move(existing_arguments))
  19. , local_variables(move(existing_local_variables))
  20. {
  21. }
  22. ExecutionContext ExecutionContext::copy() const
  23. {
  24. ExecutionContext copy { arguments, local_variables };
  25. copy.function = function;
  26. copy.realm = realm;
  27. copy.script_or_module = script_or_module;
  28. copy.lexical_environment = lexical_environment;
  29. copy.variable_environment = variable_environment;
  30. copy.private_environment = private_environment;
  31. copy.instruction_stream_iterator = instruction_stream_iterator;
  32. copy.function_name = function_name;
  33. copy.this_value = this_value;
  34. copy.is_strict_mode = is_strict_mode;
  35. return copy;
  36. }
  37. void ExecutionContext::visit_edges(Cell::Visitor& visitor)
  38. {
  39. visitor.visit(function);
  40. visitor.visit(realm);
  41. visitor.visit(variable_environment);
  42. visitor.visit(lexical_environment);
  43. visitor.visit(private_environment);
  44. visitor.visit(context_owner);
  45. visitor.visit(this_value);
  46. if (instruction_stream_iterator.has_value())
  47. visitor.visit(const_cast<Bytecode::Executable*>(instruction_stream_iterator.value().executable()));
  48. script_or_module.visit(
  49. [](Empty) {},
  50. [&](auto& script_or_module) {
  51. visitor.visit(script_or_module);
  52. });
  53. }
  54. }