2020-03-12 19:53:31 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-12 19:53:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2020-03-16 14:20:30 +01:00
|
|
|
#include <LibJS/Runtime/Function.h>
|
2020-03-12 19:53:31 +01:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2020-03-28 17:23:54 +01:00
|
|
|
class NativeFunction : public Function {
|
2020-06-21 15:14:02 +02:00
|
|
|
JS_OBJECT(NativeFunction, Function);
|
|
|
|
|
2020-03-12 19:53:31 +01:00
|
|
|
public:
|
2020-09-27 18:36:49 +02:00
|
|
|
static NativeFunction* create(GlobalObject&, const FlyString& name, AK::Function<Value(VM&, GlobalObject&)>);
|
2020-04-17 19:59:32 +02:00
|
|
|
|
2020-09-27 18:36:49 +02:00
|
|
|
explicit NativeFunction(const FlyString& name, AK::Function<Value(VM&, GlobalObject&)>, Object& prototype);
|
2020-07-22 17:50:18 +02:00
|
|
|
virtual void initialize(GlobalObject&) override { }
|
2020-03-12 19:53:31 +01:00
|
|
|
virtual ~NativeFunction() override;
|
|
|
|
|
2020-09-27 17:24:14 +02:00
|
|
|
virtual Value call() override;
|
2020-09-27 18:45:21 +02:00
|
|
|
virtual Value construct(Function& new_target) override;
|
2020-04-01 18:31:24 +01:00
|
|
|
|
2020-04-11 12:56:20 +01:00
|
|
|
virtual const FlyString& name() const override { return m_name; };
|
2020-04-01 18:31:24 +01:00
|
|
|
virtual bool has_constructor() const { return false; }
|
2020-03-12 19:53:31 +01:00
|
|
|
|
2020-10-04 13:54:44 +02:00
|
|
|
virtual bool is_strict_mode() const override;
|
|
|
|
|
2020-03-28 17:23:54 +01:00
|
|
|
protected:
|
2020-04-17 19:59:32 +02:00
|
|
|
NativeFunction(const FlyString& name, Object& prototype);
|
|
|
|
explicit NativeFunction(Object& prototype);
|
2020-03-28 17:23:54 +01:00
|
|
|
|
2020-03-12 19:53:31 +01:00
|
|
|
private:
|
2020-06-08 13:31:21 -05:00
|
|
|
virtual LexicalEnvironment* create_environment() override final;
|
2020-03-12 19:53:31 +01:00
|
|
|
|
2020-04-11 12:56:20 +01:00
|
|
|
FlyString m_name;
|
2020-09-27 18:36:49 +02:00
|
|
|
AK::Function<Value(VM&, GlobalObject&)> m_native_function;
|
2020-03-12 19:53:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|