]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
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" | |
81345200 | 25 | #include "Interpreter.h" |
9dae56ea A |
26 | #include "JSGlobalObject.h" |
27 | #include "JSString.h" | |
81345200 | 28 | #include "JSCInlines.h" |
9dae56ea A |
29 | |
30 | namespace JSC { | |
31 | ||
81345200 | 32 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorConstructor); |
9dae56ea | 33 | |
6fe7ccc8 A |
34 | const ClassInfo ErrorConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ErrorConstructor) }; |
35 | ||
81345200 A |
36 | ErrorConstructor::ErrorConstructor(VM& vm, Structure* structure) |
37 | : InternalFunction(vm, structure) | |
6fe7ccc8 A |
38 | { |
39 | } | |
40 | ||
81345200 | 41 | void ErrorConstructor::finishCreation(VM& vm, ErrorPrototype* errorPrototype) |
9dae56ea | 42 | { |
81345200 | 43 | Base::finishCreation(vm, errorPrototype->classInfo()->className); |
9dae56ea | 44 | // ECMA 15.11.3.1 Error.prototype |
81345200 A |
45 | putDirectWithoutTransition(vm, vm.propertyNames->prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); |
46 | putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), DontDelete | ReadOnly | DontEnum); | |
9dae56ea A |
47 | } |
48 | ||
49 | // ECMA 15.9.3 | |
9dae56ea | 50 | |
81345200 | 51 | EncodedJSValue JSC_HOST_CALL Interpreter::constructWithErrorConstructor(ExecState* exec) |
9dae56ea | 52 | { |
14957cd0 A |
53 | JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); |
54 | Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); | |
81345200 A |
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)); | |
9dae56ea A |
59 | } |
60 | ||
6fe7ccc8 | 61 | ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData) |
9dae56ea | 62 | { |
81345200 | 63 | constructData.native.function = Interpreter::constructWithErrorConstructor; |
9dae56ea A |
64 | return ConstructTypeHost; |
65 | } | |
66 | ||
81345200 | 67 | EncodedJSValue JSC_HOST_CALL Interpreter::callErrorConstructor(ExecState* exec) |
9dae56ea | 68 | { |
14957cd0 A |
69 | JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); |
70 | Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure(); | |
81345200 A |
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)); | |
9dae56ea A |
75 | } |
76 | ||
6fe7ccc8 | 77 | CallType ErrorConstructor::getCallData(JSCell*, CallData& callData) |
9dae56ea | 78 | { |
81345200 | 79 | callData.native.function = Interpreter::callErrorConstructor; |
9dae56ea A |
80 | return CallTypeHost; |
81 | } | |
82 | ||
83 | } // namespace JSC |