]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/NativeErrorConstructor.cpp
JavaScriptCore-721.26.tar.gz
[apple/javascriptcore.git] / runtime / NativeErrorConstructor.cpp
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, NonNullPassRefPtr<Structure> structure, NonNullPassRefPtr<Structure> prototypeStructure, const UString& nameAndMessage)
36 : InternalFunction(&exec->globalData(), structure, Identifier(exec, nameAndMessage))
37 {
38 NativeErrorPrototype* prototype = new (exec) NativeErrorPrototype(exec, prototypeStructure, nameAndMessage, this);
39
40 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
41 putDirect(exec->propertyNames().prototype, prototype, DontDelete | ReadOnly | DontEnum);
42 m_errorStructure = ErrorInstance::createStructure(prototype);
43 }
44
45
46 ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args)
47 {
48 ErrorInstance* object = new (exec) ErrorInstance(m_errorStructure);
49 if (!args.at(0).isUndefined())
50 object->putDirect(exec->propertyNames().message, jsString(exec, args.at(0).toString(exec)));
51 return object;
52 }
53
54 static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args)
55 {
56 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
57 }
58
59 ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData)
60 {
61 constructData.native.function = constructWithNativeErrorConstructor;
62 return ConstructTypeHost;
63 }
64
65 static JSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec, JSObject* constructor, JSValue, const ArgList& args)
66 {
67 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
68 }
69
70 CallType NativeErrorConstructor::getCallData(CallData& callData)
71 {
72 callData.native.function = callNativeErrorConstructor;
73 return CallTypeHost;
74 }
75
76 } // namespace JSC