ErrorPrototype.cpp [plain text]
#include "config.h"
#include "ErrorPrototype.h"
#include "Error.h"
#include "JSFunction.h"
#include "JSStringInlines.h"
#include "ObjectPrototype.h"
#include "JSCInlines.h"
#include "StringRecursionChecker.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorPrototype);
static EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState*);
}
#include "ErrorPrototype.lut.h"
namespace JSC {
const ClassInfo ErrorPrototype::s_info = { "Object", &Base::s_info, &errorPrototypeTable, nullptr, CREATE_METHOD_TABLE(ErrorPrototype) };
ErrorPrototype::ErrorPrototype(VM& vm, Structure* structure)
: JSNonFinalObject(vm, structure)
{
}
void ErrorPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(vm, info()));
putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Error"_s)), static_cast<unsigned>(PropertyAttribute::DontEnum));
putDirect(vm, vm.propertyNames->message, jsEmptyString(&vm), static_cast<unsigned>(PropertyAttribute::DontEnum));
}
EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue thisValue = exec->thisValue();
if (!thisValue.isObject())
return throwVMTypeError(exec, scope);
JSObject* thisObj = asObject(thisValue);
StringRecursionChecker checker(exec, thisObj);
EXCEPTION_ASSERT(!scope.exception() || checker.earlyReturnValue());
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
JSValue name = thisObj->get(exec, vm.propertyNames->name);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
String nameString;
if (name.isUndefined())
nameString = "Error"_s;
else {
nameString = name.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
JSValue message = thisObj->get(exec, vm.propertyNames->message);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
String messageString;
if (message.isUndefined())
messageString = String();
else {
messageString = message.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
if (!nameString.length())
return JSValue::encode(message.isString() ? message : jsString(exec, messageString));
if (!messageString.length())
return JSValue::encode(name.isString() ? name : jsString(exec, nameString));
RELEASE_AND_RETURN(scope, JSValue::encode(jsMakeNontrivialString(exec, nameString, ": ", messageString)));
}
}