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