NativeFunction.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/GlobalObject.h>
  7. #include <LibJS/Runtime/NativeFunction.h>
  8. #include <LibJS/Runtime/Value.h>
  9. namespace JS {
  10. NativeFunction* NativeFunction::create(GlobalObject& global_object, const FlyString& name, Function<Value(VM&, GlobalObject&)> function)
  11. {
  12. return global_object.heap().allocate<NativeFunction>(global_object, name, move(function), *global_object.function_prototype());
  13. }
  14. NativeFunction::NativeFunction(Object& prototype)
  15. : FunctionObject(prototype)
  16. {
  17. }
  18. NativeFunction::NativeFunction(FlyString name, Function<Value(VM&, GlobalObject&)> native_function, Object& prototype)
  19. : FunctionObject(prototype)
  20. , m_name(move(name))
  21. , m_native_function(move(native_function))
  22. {
  23. }
  24. NativeFunction::NativeFunction(FlyString name, Object& prototype)
  25. : FunctionObject(prototype)
  26. , m_name(move(name))
  27. {
  28. }
  29. NativeFunction::~NativeFunction()
  30. {
  31. }
  32. Value NativeFunction::call()
  33. {
  34. return m_native_function(vm(), global_object());
  35. }
  36. Value NativeFunction::construct(FunctionObject&)
  37. {
  38. return {};
  39. }
  40. FunctionEnvironment* NativeFunction::create_environment(FunctionObject&)
  41. {
  42. return nullptr;
  43. }
  44. bool NativeFunction::is_strict_mode() const
  45. {
  46. return vm().in_strict_mode();
  47. }
  48. }