ErrorPrototype.cpp [plain text]
#include "config.h"
#include "ErrorPrototype.h"
#include "IntegrityInlines.h"
#include "JSCInlines.h"
#include "StringRecursionChecker.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorPrototypeBase);
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorPrototype);
static JSC_DECLARE_HOST_FUNCTION(errorProtoFuncToString);
}
#include "ErrorPrototype.lut.h"
namespace JSC {
const ClassInfo ErrorPrototype::s_info = { "Object", &Base::s_info, &errorPrototypeTable, nullptr, CREATE_METHOD_TABLE(ErrorPrototype) };
ErrorPrototypeBase::ErrorPrototypeBase(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void ErrorPrototypeBase::finishCreation(VM& vm, const String& name)
{
Base::finishCreation(vm);
ASSERT(inherits(vm, info()));
putDirectWithoutTransition(vm, vm.propertyNames->name, jsString(vm, name), static_cast<unsigned>(PropertyAttribute::DontEnum));
putDirectWithoutTransition(vm, vm.propertyNames->message, jsEmptyString(vm), static_cast<unsigned>(PropertyAttribute::DontEnum));
}
ErrorPrototype::ErrorPrototype(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
JSC_DEFINE_HOST_FUNCTION(errorProtoFuncToString, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue thisValue = callFrame->thisValue().toThis(globalObject, ECMAMode::strict());
if (!thisValue.isObject())
return throwVMTypeError(globalObject, scope);
JSObject* thisObj = asObject(thisValue);
Integrity::auditStructureID(vm, thisObj->structureID());
StringRecursionChecker checker(globalObject, thisObj);
EXCEPTION_ASSERT(!scope.exception() || checker.earlyReturnValue());
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
JSValue name = thisObj->get(globalObject, vm.propertyNames->name);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
String nameString;
if (name.isUndefined())
nameString = "Error"_s;
else {
nameString = name.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
JSValue message = thisObj->get(globalObject, vm.propertyNames->message);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
String messageString;
if (message.isUndefined())
messageString = String();
else {
messageString = message.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
if (!nameString.length())
return JSValue::encode(message.isString() ? message : jsString(vm, messageString));
if (!messageString.length())
return JSValue::encode(name.isString() ? name : jsString(vm, nameString));
RELEASE_AND_RETURN(scope, JSValue::encode(jsMakeNontrivialString(globalObject, nameString, ": ", messageString)));
}
}