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
|
|
|
*/
|
|
|
|
|
|
2020-04-17 14:59:32 -03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-03-16 10:20:30 -03:00
|
|
|
#include <LibJS/Runtime/NativeFunction.h>
|
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
2020-03-12 15:53:31 -03:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
2020-09-27 13:36:49 -03:00
|
|
|
NativeFunction* NativeFunction::create(GlobalObject& global_object, const FlyString& name, AK::Function<Value(VM&, GlobalObject&)> function)
|
2020-04-17 14:59:32 -03:00
|
|
|
{
|
2020-06-20 10:40:48 -03:00
|
|
|
return global_object.heap().allocate<NativeFunction>(global_object, name, move(function), *global_object.function_prototype());
|
2020-04-17 14:59:32 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NativeFunction::NativeFunction(Object& prototype)
|
|
|
|
|
: Function(prototype)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 13:36:49 -03:00
|
|
|
NativeFunction::NativeFunction(const FlyString& name, AK::Function<Value(VM&, GlobalObject&)> native_function, Object& prototype)
|
2020-04-17 14:59:32 -03:00
|
|
|
: Function(prototype)
|
|
|
|
|
, m_name(name)
|
2020-04-11 08:56:20 -03:00
|
|
|
, m_native_function(move(native_function))
|
2020-03-12 15:53:31 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 14:59:32 -03:00
|
|
|
NativeFunction::NativeFunction(const FlyString& name, Object& prototype)
|
|
|
|
|
: Function(prototype)
|
|
|
|
|
, m_name(name)
|
2020-04-12 20:07:31 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 15:53:31 -03:00
|
|
|
NativeFunction::~NativeFunction()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 12:24:14 -03:00
|
|
|
Value NativeFunction::call()
|
2020-03-13 06:08:52 -03:00
|
|
|
{
|
2020-09-27 13:36:49 -03:00
|
|
|
return m_native_function(vm(), global_object());
|
2020-03-13 06:08:52 -03:00
|
|
|
}
|
|
|
|
|
|
2020-09-27 13:45:21 -03:00
|
|
|
Value NativeFunction::construct(Function&)
|
2020-04-01 14:31:24 -03:00
|
|
|
{
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 15:31:21 -03:00
|
|
|
LexicalEnvironment* NativeFunction::create_environment()
|
|
|
|
|
{
|
2021-06-09 15:52:35 -03:00
|
|
|
return nullptr;
|
2020-06-08 15:31:21 -03:00
|
|
|
}
|
|
|
|
|
|
2020-10-04 08:54:44 -03:00
|
|
|
bool NativeFunction::is_strict_mode() const
|
|
|
|
|
{
|
|
|
|
|
return vm().in_strict_mode();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 15:53:31 -03:00
|
|
|
}
|