]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. | |
4 | * | |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Lesser General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | * | |
19 | */ | |
20 | ||
21 | #include "config.h" | |
22 | #include "ErrorConstructor.h" | |
23 | ||
24 | #include "ErrorPrototype.h" | |
25 | #include "Interpreter.h" | |
26 | #include "JSGlobalObject.h" | |
27 | #include "JSString.h" | |
28 | #include "JSCInlines.h" | |
29 | ||
30 | namespace JSC { | |
31 | ||
32 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorConstructor); | |
33 | ||
34 | const ClassInfo ErrorConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ErrorConstructor) }; | |
35 | ||
36 | ErrorConstructor::ErrorConstructor(VM& vm, Structure* structure) | |
37 | : InternalFunction(vm, structure) | |
38 | { | |
39 | } | |
40 | ||
41 | void ErrorConstructor::finishCreation(VM& vm, ErrorPrototype* errorPrototype) | |
42 | { | |
43 | Base::finishCreation(vm, errorPrototype->classInfo()->className); | |
44 | // ECMA 15.11.3.1 Error.prototype | |
45 | putDirectWithoutTransition(vm, vm.propertyNames->prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); | |
46 | putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), DontDelete | ReadOnly | DontEnum); | |
47 | } | |
48 | ||
49 | // ECMA 15.9.3 | |
50 | ||
51 | EncodedJSValue JSC_HOST_CALL Interpreter::constructWithErrorConstructor(ExecState* exec) | |
52 | { | |
53 | JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); | |
54 | Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); | |
55 | Vector<StackFrame> stackTrace; | |
56 | exec->vm().interpreter->getStackTrace(stackTrace, std::numeric_limits<size_t>::max()); | |
57 | stackTrace.remove(0); | |
58 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace)); | |
59 | } | |
60 | ||
61 | ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData) | |
62 | { | |
63 | constructData.native.function = Interpreter::constructWithErrorConstructor; | |
64 | return ConstructTypeHost; | |
65 | } | |
66 | ||
67 | EncodedJSValue JSC_HOST_CALL Interpreter::callErrorConstructor(ExecState* exec) | |
68 | { | |
69 | JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); | |
70 | Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); | |
71 | Vector<StackFrame> stackTrace; | |
72 | exec->vm().interpreter->getStackTrace(stackTrace, std::numeric_limits<size_t>::max()); | |
73 | stackTrace.remove(0); | |
74 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace)); | |
75 | } | |
76 | ||
77 | CallType ErrorConstructor::getCallData(JSCell*, CallData& callData) | |
78 | { | |
79 | callData.native.function = Interpreter::callErrorConstructor; | |
80 | return CallTypeHost; | |
81 | } | |
82 | ||
83 | } // namespace JSC |