ErrorPrototype.cpp [plain text]
#include "config.h"
#include "ErrorPrototype.h"
#include "JSFunction.h"
#include "JSString.h"
#include "ObjectPrototype.h"
#include "PrototypeFunction.h"
#include "UString.h"
namespace JSC {
ASSERT_CLASS_FITS_IN_CELL(ErrorPrototype);
static JSValue JSC_HOST_CALL errorProtoFuncToString(ExecState*, JSObject*, JSValue, 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) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, errorProtoFuncToString), DontEnum);
}
JSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
JSObject* thisObj = thisValue.toThisObject(exec);
UString s = "Error";
JSValue 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);
}
}