JSNativeStdFunction.cpp [plain text]
#include "config.h"
#include "JSNativeStdFunction.h"
#include "JSCInlines.h"
#include "JSFunction.h"
#include "JSFunctionInlines.h"
#include "JSObject.h"
#include "VM.h"
namespace JSC {
const ClassInfo JSNativeStdFunction::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNativeStdFunction) };
JSNativeStdFunction::JSNativeStdFunction(VM& vm, NativeExecutable* executable, JSGlobalObject* globalObject, Structure* structure, NativeStdFunction&& function)
: Base(vm, executable, globalObject, structure)
, m_function(WTFMove(function))
{
}
void JSNativeStdFunction::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
JSNativeStdFunction* thisObject = jsCast<JSNativeStdFunction*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
}
void JSNativeStdFunction::finishCreation(VM& vm, NativeExecutable* executable, int length, const String& name)
{
Base::finishCreation(vm, executable, length, name);
ASSERT(inherits(vm, info()));
}
static EncodedJSValue JSC_HOST_CALL runStdFunction(JSGlobalObject* globalObject, CallFrame* callFrame)
{
JSNativeStdFunction* function = jsCast<JSNativeStdFunction*>(callFrame->jsCallee());
ASSERT(function);
return function->function()(globalObject, callFrame);
}
JSNativeStdFunction* JSNativeStdFunction::create(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeStdFunction&& nativeStdFunction, Intrinsic intrinsic, NativeFunction nativeConstructor)
{
NativeExecutable* executable = vm.getHostFunction(runStdFunction, intrinsic, nativeConstructor, nullptr, name);
Structure* structure = globalObject->nativeStdFunctionStructure();
JSNativeStdFunction* function = new (NotNull, allocateCell<JSNativeStdFunction>(vm.heap)) JSNativeStdFunction(vm, executable, globalObject, structure, WTFMove(nativeStdFunction));
function->finishCreation(vm, executable, length, name);
return function;
}
}