FunctionConstructor.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/FunctionKind.h>
  8. #include <LibJS/Runtime/NativeFunction.h>
  9. namespace JS {
  10. struct ParameterArgumentsAndBody {
  11. Vector<String> parameters;
  12. String body;
  13. };
  14. ThrowCompletionOr<ParameterArgumentsAndBody> extract_parameter_arguments_and_body(VM&, Span<Value> arguments);
  15. class FunctionConstructor final : public NativeFunction {
  16. JS_OBJECT(FunctionConstructor, NativeFunction);
  17. GC_DECLARE_ALLOCATOR(FunctionConstructor);
  18. public:
  19. static ThrowCompletionOr<GC::Ref<ECMAScriptFunctionObject>> create_dynamic_function(VM&, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, ReadonlySpan<String> parameter_args, String const& body_string);
  20. virtual void initialize(Realm&) override;
  21. virtual ~FunctionConstructor() override = default;
  22. virtual ThrowCompletionOr<Value> call() override;
  23. virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
  24. private:
  25. explicit FunctionConstructor(Realm&);
  26. virtual bool has_constructor() const override { return true; }
  27. };
  28. }