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 "StringRecursionChecker.h"
#include "UString.h"
namespace JSC {
ASSERT_CLASS_FITS_IN_CELL(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) };
ASSERT_CLASS_FITS_IN_CELL(ErrorPrototype);
ErrorPrototype::ErrorPrototype(ExecState* exec, Structure* structure)
: ErrorInstance(exec->globalData(), structure)
{
}
void ErrorPrototype::finishCreation(ExecState* exec, JSGlobalObject*)
{
Base::finishCreation(exec->globalData(), "");
ASSERT(inherits(&s_info));
putDirect(exec->globalData(), exec->propertyNames().name, jsNontrivialString(exec, "Error"), DontEnum);
}
bool ErrorPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
{
return getStaticFunctionSlot<ErrorInstance>(exec, ExecState::errorPrototypeTable(exec), jsCast<ErrorPrototype*>(cell), propertyName, slot);
}
bool ErrorPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
return getStaticFunctionDescriptor<ErrorInstance>(exec, ExecState::errorPrototypeTable(exec), jsCast<ErrorPrototype*>(object), propertyName, descriptor);
}
EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
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());
UString nameString;
if (name.isUndefined())
nameString = "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());
UString messageString;
if (message.isUndefined())
messageString = "";
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));
}
}