]>
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" | |
28 | ||
29 | namespace JSC { | |
30 | ||
31 | ASSERT_CLASS_FITS_IN_CELL(NativeErrorConstructor); | |
32 | ||
14957cd0 | 33 | const ClassInfo NativeErrorConstructor::s_info = { "Function", &InternalFunction::s_info, 0, 0 }; |
9dae56ea | 34 | |
14957cd0 A |
35 | NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, Structure* prototypeStructure, const UString& nameAndMessage) |
36 | : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, nameAndMessage)) | |
9dae56ea | 37 | { |
14957cd0 | 38 | ASSERT(inherits(&s_info)); |
4e4e5a6f | 39 | |
14957cd0 | 40 | NativeErrorPrototype* prototype = new (exec) NativeErrorPrototype(exec, globalObject, prototypeStructure, nameAndMessage, this); |
9dae56ea | 41 | |
14957cd0 A |
42 | putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5 |
43 | putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | ReadOnly | DontEnum); | |
44 | m_errorStructure.set(exec->globalData(), this, ErrorInstance::createStructure(exec->globalData(), prototype)); | |
45 | ASSERT(m_errorStructure); | |
46 | ASSERT(m_errorStructure->typeInfo().type() == ObjectType); | |
47 | } | |
4e4e5a6f | 48 | |
14957cd0 | 49 | void NativeErrorConstructor::visitChildren(SlotVisitor& visitor) |
9dae56ea | 50 | { |
14957cd0 A |
51 | ASSERT_GC_OBJECT_INHERITS(this, &s_info); |
52 | COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); | |
53 | ASSERT(structure()->typeInfo().overridesVisitChildren()); | |
54 | InternalFunction::visitChildren(visitor); | |
55 | if (m_errorStructure) | |
56 | visitor.append(&m_errorStructure); | |
9dae56ea A |
57 | } |
58 | ||
14957cd0 | 59 | static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec) |
9dae56ea | 60 | { |
14957cd0 A |
61 | JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); |
62 | Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); | |
63 | ASSERT(errorStructure); | |
64 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); | |
9dae56ea A |
65 | } |
66 | ||
67 | ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData) | |
68 | { | |
69 | constructData.native.function = constructWithNativeErrorConstructor; | |
70 | return ConstructTypeHost; | |
71 | } | |
ba379fdc | 72 | |
14957cd0 | 73 | static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec) |
9dae56ea | 74 | { |
14957cd0 A |
75 | JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); |
76 | Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); | |
77 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); | |
9dae56ea A |
78 | } |
79 | ||
80 | CallType NativeErrorConstructor::getCallData(CallData& callData) | |
81 | { | |
82 | callData.native.function = callNativeErrorConstructor; | |
83 | return CallTypeHost; | |
84 | } | |
85 | ||
86 | } // namespace JSC |