]>
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 "NativeErrorConstructor.h" | |
23 | ||
24 | #include "ErrorInstance.h" | |
25 | #include "JSFunction.h" | |
26 | #include "JSString.h" | |
27 | #include "NativeErrorPrototype.h" | |
81345200 | 28 | #include "JSCInlines.h" |
9dae56ea A |
29 | |
30 | namespace JSC { | |
31 | ||
81345200 | 32 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NativeErrorConstructor); |
9dae56ea | 33 | |
6fe7ccc8 | 34 | const ClassInfo NativeErrorConstructor::s_info = { "Function", &InternalFunction::s_info, 0, 0, CREATE_METHOD_TABLE(NativeErrorConstructor) }; |
9dae56ea | 35 | |
81345200 A |
36 | NativeErrorConstructor::NativeErrorConstructor(VM& vm, Structure* structure) |
37 | : InternalFunction(vm, structure) | |
9dae56ea | 38 | { |
14957cd0 | 39 | } |
4e4e5a6f | 40 | |
81345200 A |
41 | void NativeErrorConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, Structure* prototypeStructure, const String& name) |
42 | { | |
43 | Base::finishCreation(vm, name); | |
44 | ASSERT(inherits(info())); | |
45 | ||
46 | NativeErrorPrototype* prototype = NativeErrorPrototype::create(vm, globalObject, prototypeStructure, name, this); | |
47 | ||
48 | putDirect(vm, vm.propertyNames->length, jsNumber(1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5 | |
49 | putDirect(vm, vm.propertyNames->prototype, prototype, DontDelete | ReadOnly | DontEnum); | |
50 | m_errorStructure.set(vm, this, ErrorInstance::createStructure(vm, globalObject, prototype)); | |
51 | ASSERT(m_errorStructure); | |
52 | ASSERT(m_errorStructure->isObject()); | |
53 | } | |
54 | ||
6fe7ccc8 | 55 | void NativeErrorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor) |
9dae56ea | 56 | { |
6fe7ccc8 | 57 | NativeErrorConstructor* thisObject = jsCast<NativeErrorConstructor*>(cell); |
81345200 | 58 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
14957cd0 | 59 | COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); |
6fe7ccc8 | 60 | ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); |
93a37866 | 61 | |
6fe7ccc8 | 62 | InternalFunction::visitChildren(thisObject, visitor); |
93a37866 | 63 | visitor.append(&thisObject->m_errorStructure); |
9dae56ea A |
64 | } |
65 | ||
81345200 | 66 | EncodedJSValue JSC_HOST_CALL Interpreter::constructWithNativeErrorConstructor(ExecState* exec) |
9dae56ea | 67 | { |
81345200 | 68 | JSValue message = exec->argument(0); |
14957cd0 A |
69 | Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); |
70 | ASSERT(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 | ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData) |
9dae56ea | 78 | { |
81345200 | 79 | constructData.native.function = Interpreter::constructWithNativeErrorConstructor; |
9dae56ea A |
80 | return ConstructTypeHost; |
81 | } | |
ba379fdc | 82 | |
81345200 | 83 | EncodedJSValue JSC_HOST_CALL Interpreter::callNativeErrorConstructor(ExecState* exec) |
9dae56ea | 84 | { |
81345200 | 85 | JSValue message = exec->argument(0); |
14957cd0 | 86 | Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); |
81345200 A |
87 | Vector<StackFrame> stackTrace; |
88 | exec->vm().interpreter->getStackTrace(stackTrace, std::numeric_limits<size_t>::max()); | |
89 | stackTrace.remove(0); | |
90 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace)); | |
9dae56ea A |
91 | } |
92 | ||
6fe7ccc8 | 93 | CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData) |
9dae56ea | 94 | { |
81345200 | 95 | callData.native.function = Interpreter::callNativeErrorConstructor; |
9dae56ea A |
96 | return CallTypeHost; |
97 | } | |
98 | ||
99 | } // namespace JSC |