2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
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.
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.
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
22 #include "NativeErrorConstructor.h"
24 #include "ErrorInstance.h"
25 #include "JSFunction.h"
27 #include "NativeErrorPrototype.h"
31 ASSERT_CLASS_FITS_IN_CELL(NativeErrorConstructor
);
33 const ClassInfo
NativeErrorConstructor::info
= { "Function", &InternalFunction::info
, 0, 0 };
35 NativeErrorConstructor::NativeErrorConstructor(ExecState
* exec
, NonNullPassRefPtr
<Structure
> structure
, NonNullPassRefPtr
<Structure
> prototypeStructure
, const UString
& nameAndMessage
)
36 : InternalFunction(&exec
->globalData(), structure
, Identifier(exec
, nameAndMessage
))
38 NativeErrorPrototype
* prototype
= new (exec
) NativeErrorPrototype(exec
, prototypeStructure
, nameAndMessage
, this);
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
);
46 ErrorInstance
* NativeErrorConstructor::construct(ExecState
* exec
, const ArgList
& args
)
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
)));
54 static JSObject
* constructWithNativeErrorConstructor(ExecState
* exec
, JSObject
* constructor
, const ArgList
& args
)
56 return static_cast<NativeErrorConstructor
*>(constructor
)->construct(exec
, args
);
59 ConstructType
NativeErrorConstructor::getConstructData(ConstructData
& constructData
)
61 constructData
.native
.function
= constructWithNativeErrorConstructor
;
62 return ConstructTypeHost
;
65 static JSValue JSC_HOST_CALL
callNativeErrorConstructor(ExecState
* exec
, JSObject
* constructor
, JSValue
, const ArgList
& args
)
67 return static_cast<NativeErrorConstructor
*>(constructor
)->construct(exec
, args
);
70 CallType
NativeErrorConstructor::getCallData(CallData
& callData
)
72 callData
.native
.function
= callNativeErrorConstructor
;