tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / 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::s_info = { "Function", &InternalFunction::s_info, 0, 0, CREATE_METHOD_TABLE(NativeErrorConstructor) };
34
35 NativeErrorConstructor::NativeErrorConstructor(JSGlobalObject* globalObject, Structure* structure)
36     : InternalFunction(globalObject, structure)
37 {
38 }
39
40 void NativeErrorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
41 {
42     NativeErrorConstructor* thisObject = jsCast<NativeErrorConstructor*>(cell);
43     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
44     COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
45     ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
46     InternalFunction::visitChildren(thisObject, visitor);
47     if (thisObject->m_errorStructure)
48         visitor.append(&thisObject->m_errorStructure);
49 }
50
51 static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec)
52 {
53     JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
54     Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
55     ASSERT(errorStructure);
56     return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
57 }
58
59 ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
60 {
61     constructData.native.function = constructWithNativeErrorConstructor;
62     return ConstructTypeHost;
63 }
64     
65 static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec)
66 {
67     JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
68     Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
69     return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
70 }
71
72 CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData)
73 {
74     callData.native.function = callNativeErrorConstructor;
75     return CallTypeHost;
76 }
77
78 } // namespace JSC