ErrorPrototype.cpp [plain text]
#include "config.h"
#include "ErrorPrototype.h"
#include "Error.h"
#include "JSFunction.h"
#include "JSString.h"
#include "JSStringBuilder.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 = { "Error", &ErrorInstance::s_info, 0, ExecState::errorPrototypeTable, CREATE_METHOD_TABLE(ErrorPrototype) };
ErrorPrototype::ErrorPrototype(VM& vm, Structure* structure)
: ErrorInstance(vm, structure)
{
}
void ErrorPrototype::finishCreation(VM& vm, JSGlobalObject*)
{
Base::finishCreation(vm, "");
ASSERT(inherits(info()));
putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("Error"))), DontEnum);
}
bool ErrorPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
{
return getStaticFunctionSlot<ErrorInstance>(exec, ExecState::errorPrototypeTable(exec->vm()), jsCast<ErrorPrototype*>(object), propertyName, slot);
}
EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.isObject())
return throwVMTypeError(exec);
JSObject* thisObj = asObject(thisValue);
StringRecursionChecker checker(exec, thisObj);
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
JSValue name = thisObj->get(exec, exec->propertyNames().name);
if (exec->hadException())
return JSValue::encode(jsUndefined());
String nameString;
if (name.isUndefined())
nameString = ASCIILiteral("Error");
else {
nameString = name.toString(exec)->value(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
}
JSValue message = thisObj->get(exec, exec->propertyNames().message);
if (exec->hadException())
return JSValue::encode(jsUndefined());
String messageString;
if (message.isUndefined())
messageString = String();
else {
messageString = message.toString(exec)->value(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
}
if (!nameString.length())
return JSValue::encode(message.isString() ? message : jsString(exec, messageString));
if (!messageString.length())
return JSValue::encode(name.isString() ? name : jsNontrivialString(exec, nameString));
return JSValue::encode(jsMakeNontrivialString(exec, nameString, ": ", messageString));
}
}