ErrorPrototype.cpp [plain text]
#include "config.h"
#include "ErrorPrototype.h"
#include "JSString.h"
#include "ObjectPrototype.h"
#include "PrototypeFunction.h"
#include "UString.h"
namespace JSC {
ASSERT_CLASS_FITS_IN_CELL(ErrorPrototype);
static JSValuePtr errorProtoFuncToString(ExecState*, JSObject*, JSValuePtr, const ArgList&);
ErrorPrototype::ErrorPrototype(ExecState* exec, PassRefPtr<Structure> structure, Structure* prototypeFunctionStructure)
: ErrorInstance(structure)
{
putDirectWithoutTransition(exec->propertyNames().name, jsNontrivialString(exec, "Error"), DontEnum);
putDirectWithoutTransition(exec->propertyNames().message, jsNontrivialString(exec, "Unknown error"), DontEnum);
putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, errorProtoFuncToString), DontEnum);
}
JSValuePtr errorProtoFuncToString(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&)
{
JSObject* thisObj = thisValue.toThisObject(exec);
UString s = "Error";
JSValuePtr v = thisObj->get(exec, exec->propertyNames().name);
if (!v.isUndefined())
s = v.toString(exec);
v = thisObj->get(exec, exec->propertyNames().message);
if (!v.isUndefined()) {
s += ": ";
s += v.toString(exec);
}
return jsNontrivialString(exec, s);
}
}