]>
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 | ||
33 | const ClassInfo NativeErrorConstructor::info = { "Function", &InternalFunction::info, 0, 0 }; | |
34 | ||
35 | NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, PassRefPtr<Structure> structure, NativeErrorPrototype* nativeErrorPrototype) | |
36 | : InternalFunction(&exec->globalData(), structure, Identifier(exec, nativeErrorPrototype->getDirect(exec->propertyNames().name).getString())) | |
37 | , m_errorStructure(ErrorInstance::createStructure(nativeErrorPrototype)) | |
38 | { | |
39 | putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5 | |
40 | putDirect(exec->propertyNames().prototype, nativeErrorPrototype, DontDelete | ReadOnly | DontEnum); | |
41 | } | |
42 | ||
43 | ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args) | |
44 | { | |
45 | ErrorInstance* object = new (exec) ErrorInstance(m_errorStructure); | |
46 | if (!args.at(exec, 0).isUndefined()) | |
47 | object->putDirect(exec->propertyNames().message, jsString(exec, args.at(exec, 0).toString(exec))); | |
48 | return object; | |
49 | } | |
50 | ||
51 | static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args) | |
52 | { | |
53 | return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args); | |
54 | } | |
55 | ||
56 | ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData) | |
57 | { | |
58 | constructData.native.function = constructWithNativeErrorConstructor; | |
59 | return ConstructTypeHost; | |
60 | } | |
61 | ||
62 | static JSValuePtr callNativeErrorConstructor(ExecState* exec, JSObject* constructor, JSValuePtr, const ArgList& args) | |
63 | { | |
64 | return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args); | |
65 | } | |
66 | ||
67 | CallType NativeErrorConstructor::getCallData(CallData& callData) | |
68 | { | |
69 | callData.native.function = callNativeErrorConstructor; | |
70 | return CallTypeHost; | |
71 | } | |
72 | ||
73 | } // namespace JSC |