ErrorConstructor.cpp [plain text]
#include "config.h"
#include "ErrorConstructor.h"
#include "ErrorPrototype.h"
#include "Interpreter.h"
#include "JSGlobalObject.h"
#include "JSString.h"
#include "JSCInlines.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorConstructor);
const ClassInfo ErrorConstructor::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(ErrorConstructor) };
ErrorConstructor::ErrorConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure)
{
}
void ErrorConstructor::finishCreation(VM& vm, ErrorPrototype* errorPrototype)
{
Base::finishCreation(vm, ASCIILiteral("Error"));
putDirectWithoutTransition(vm, vm.propertyNames->prototype, errorPrototype, DontEnum | DontDelete | ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), DontEnum | ReadOnly);
unsigned defaultStackTraceLimit = Options::defaultErrorStackTraceLimit();
m_stackTraceLimit = defaultStackTraceLimit;
putDirectWithoutTransition(vm, vm.propertyNames->stackTraceLimit, jsNumber(defaultStackTraceLimit), None);
}
EncodedJSValue JSC_HOST_CALL Interpreter::constructWithErrorConstructor(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue message = exec->argument(0);
Structure* errorStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), asInternalFunction(exec->jsCallee())->globalObject()->errorStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
scope.release();
return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
}
ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
constructData.native.function = Interpreter::constructWithErrorConstructor;
return ConstructType::Host;
}
EncodedJSValue JSC_HOST_CALL Interpreter::callErrorConstructor(ExecState* exec)
{
JSValue message = exec->argument(0);
Structure* errorStructure = asInternalFunction(exec->jsCallee())->globalObject()->errorStructure();
return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
}
CallType ErrorConstructor::getCallData(JSCell*, CallData& callData)
{
callData.native.function = Interpreter::callErrorConstructor;
return CallType::Host;
}
bool ErrorConstructor::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
{
VM& vm = exec->vm();
ErrorConstructor* thisObject = jsCast<ErrorConstructor*>(cell);
if (propertyName == vm.propertyNames->stackTraceLimit) {
if (value.isNumber()) {
double effectiveLimit = value.asNumber();
effectiveLimit = std::max(0., effectiveLimit);
effectiveLimit = std::min(effectiveLimit, static_cast<double>(std::numeric_limits<unsigned>::max()));
thisObject->m_stackTraceLimit = static_cast<unsigned>(effectiveLimit);
} else
thisObject->m_stackTraceLimit = { };
}
return Base::put(thisObject, exec, propertyName, value, slot);
}
bool ErrorConstructor::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
VM& vm = exec->vm();
ErrorConstructor* thisObject = jsCast<ErrorConstructor*>(cell);
if (propertyName == vm.propertyNames->stackTraceLimit)
thisObject->m_stackTraceLimit = { };
return Base::deleteProperty(thisObject, exec, propertyName);
}
}