X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..217a6308cd6a1dc049a0bb69263bd4c91f91c4d0:/runtime/ErrorConstructor.cpp diff --git a/runtime/ErrorConstructor.cpp b/runtime/ErrorConstructor.cpp index b9c3f58..b143f5a 100644 --- a/runtime/ErrorConstructor.cpp +++ b/runtime/ErrorConstructor.cpp @@ -24,47 +24,50 @@ #include "ErrorPrototype.h" #include "JSGlobalObject.h" #include "JSString.h" +#include "Operations.h" namespace JSC { -ASSERT_CLASS_FITS_IN_CELL(ErrorConstructor); +ASSERT_HAS_TRIVIAL_DESTRUCTOR(ErrorConstructor); -ErrorConstructor::ErrorConstructor(ExecState* exec, NonNullPassRefPtr structure, ErrorPrototype* errorPrototype) - : InternalFunction(&exec->globalData(), structure, Identifier(exec, errorPrototype->classInfo()->className)) +const ClassInfo ErrorConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ErrorConstructor) }; + +ErrorConstructor::ErrorConstructor(JSGlobalObject* globalObject, Structure* structure) + : InternalFunction(globalObject, structure) { - // ECMA 15.11.3.1 Error.prototype - putDirectWithoutTransition(exec->propertyNames().prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); - putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); } -// ECMA 15.9.3 -ErrorInstance* constructError(ExecState* exec, const ArgList& args) +void ErrorConstructor::finishCreation(ExecState* exec, ErrorPrototype* errorPrototype) { - ErrorInstance* obj = new (exec) ErrorInstance(exec->lexicalGlobalObject()->errorStructure()); - if (!args.at(0).isUndefined()) - obj->putDirect(exec->propertyNames().message, jsString(exec, args.at(0).toString(exec))); - return obj; + Base::finishCreation(exec->vm(), errorPrototype->classInfo()->className); + // ECMA 15.11.3.1 Error.prototype + putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); + putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(1), DontDelete | ReadOnly | DontEnum); } -static JSObject* constructWithErrorConstructor(ExecState* exec, JSObject*, const ArgList& args) +// ECMA 15.9.3 + +static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec) { - return constructError(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); } -ConstructType ErrorConstructor::getConstructData(ConstructData& constructData) +ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData) { constructData.native.function = constructWithErrorConstructor; return ConstructTypeHost; } -// ECMA 15.9.2 -static JSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec) { - // "Error()" gives the sames result as "new Error()" - return constructError(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); } -CallType ErrorConstructor::getCallData(CallData& callData) +CallType ErrorConstructor::getCallData(JSCell*, CallData& callData) { callData.native.function = callErrorConstructor; return CallTypeHost;