X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..2656c66b5b30d5597e842a751c7f19ad6c2fe31a:/runtime/ErrorConstructor.cpp diff --git a/runtime/ErrorConstructor.cpp b/runtime/ErrorConstructor.cpp index 5cc0df0..9acbc4c 100644 --- a/runtime/ErrorConstructor.cpp +++ b/runtime/ErrorConstructor.cpp @@ -22,51 +22,61 @@ #include "ErrorConstructor.h" #include "ErrorPrototype.h" +#include "Interpreter.h" #include "JSGlobalObject.h" #include "JSString.h" +#include "JSCInlines.h" namespace JSC { -ASSERT_CLASS_FITS_IN_CELL(ErrorConstructor); +STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorConstructor); -ErrorConstructor::ErrorConstructor(ExecState* exec, PassRefPtr 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(VM& vm, Structure* structure) + : InternalFunction(vm, 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(VM& vm, ErrorPrototype* errorPrototype) { - ErrorInstance* obj = new (exec) ErrorInstance(exec->lexicalGlobalObject()->errorStructure()); - if (!args.at(exec, 0).isUndefined()) - obj->putDirect(exec->propertyNames().message, jsString(exec, args.at(exec, 0).toString(exec))); - return obj; + Base::finishCreation(vm, errorPrototype->classInfo()->className); + // ECMA 15.11.3.1 Error.prototype + putDirectWithoutTransition(vm, vm.propertyNames->prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); + putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), DontDelete | ReadOnly | DontEnum); } -static JSObject* constructWithErrorConstructor(ExecState* exec, JSObject*, const ArgList& args) +// ECMA 15.9.3 + +EncodedJSValue JSC_HOST_CALL Interpreter::constructWithErrorConstructor(ExecState* exec) { - return constructError(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); + Vector stackTrace; + exec->vm().interpreter->getStackTrace(stackTrace, std::numeric_limits::max()); + stackTrace.remove(0); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace)); } -ConstructType ErrorConstructor::getConstructData(ConstructData& constructData) +ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData) { - constructData.native.function = constructWithErrorConstructor; + constructData.native.function = Interpreter::constructWithErrorConstructor; return ConstructTypeHost; } -// ECMA 15.9.2 -static JSValuePtr callErrorConstructor(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args) +EncodedJSValue JSC_HOST_CALL Interpreter::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(); + Vector stackTrace; + exec->vm().interpreter->getStackTrace(stackTrace, std::numeric_limits::max()); + stackTrace.remove(0); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace)); } -CallType ErrorConstructor::getCallData(CallData& callData) +CallType ErrorConstructor::getCallData(JSCell*, CallData& callData) { - callData.native.function = callErrorConstructor; + callData.native.function = Interpreter::callErrorConstructor; return CallTypeHost; }