tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / runtime / Error.h
1 /*
2  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
4  *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public License
17  *  along with this library; see the file COPYING.LIB.  If not, write to
18  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #ifndef Error_h
24 #define Error_h
25
26 #include "InternalFunction.h"
27 #include "JSObject.h"
28 #include <stdint.h>
29
30 namespace JSC {
31
32     class ExecState;
33     class JSGlobalData;
34     class JSGlobalObject;
35     class JSObject;
36     class SourceCode;
37     class Structure;
38     class UString;
39
40     // Methods to create a range of internal errors.
41     JSObject* createError(JSGlobalObject*, const UString&);
42     JSObject* createEvalError(JSGlobalObject*, const UString&);
43     JSObject* createRangeError(JSGlobalObject*, const UString&);
44     JSObject* createReferenceError(JSGlobalObject*, const UString&);
45     JSObject* createSyntaxError(JSGlobalObject*, const UString&);
46     JSObject* createTypeError(JSGlobalObject*, const UString&);
47     JSObject* createURIError(JSGlobalObject*, const UString&);
48     // ExecState wrappers.
49     JSObject* createError(ExecState*, const UString&);
50     JSObject* createEvalError(ExecState*, const UString&);
51     JSObject* createRangeError(ExecState*, const UString&);
52     JSObject* createReferenceError(ExecState*, const UString&);
53     JSObject* createSyntaxError(ExecState*, const UString&);
54     JSObject* createTypeError(ExecState*, const UString&);
55     JSObject* createURIError(ExecState*, const UString&);
56
57     // Methods to add 
58     bool hasErrorInfo(ExecState*, JSObject* error);
59     JSObject* addErrorInfo(JSGlobalData*, JSObject* error, int line, const SourceCode&);
60     // ExecState wrappers.
61     JSObject* addErrorInfo(ExecState*, JSObject* error, int line, const SourceCode&);
62
63     // Methods to throw Errors.
64     JSValue throwError(ExecState*, JSValue);
65     JSObject* throwError(ExecState*, JSObject*);
66
67     // Convenience wrappers, create an throw an exception with a default message.
68     JSObject* throwTypeError(ExecState*);
69     JSObject* throwSyntaxError(ExecState*);
70
71     // Convenience wrappers, wrap result as an EncodedJSValue.
72     inline EncodedJSValue throwVMError(ExecState* exec, JSValue error) { return JSValue::encode(throwError(exec, error)); }
73     inline EncodedJSValue throwVMTypeError(ExecState* exec) { return JSValue::encode(throwTypeError(exec)); }
74
75     JSValue createTypeErrorFunction(ExecState* exec, const UString& message);
76     
77     class StrictModeTypeErrorFunction : public InternalFunction {
78     private:
79         StrictModeTypeErrorFunction(JSGlobalObject* globalObject, Structure* structure, const UString& message)
80             : InternalFunction(globalObject, structure)
81             , m_message(message)
82         {
83         }
84
85     public:
86         typedef InternalFunction Base;
87
88         static StrictModeTypeErrorFunction* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, const UString& message)
89         {
90             StrictModeTypeErrorFunction* function = new (allocateCell<StrictModeTypeErrorFunction>(*exec->heap())) StrictModeTypeErrorFunction(globalObject, structure, message);
91             function->finishCreation(exec->globalData(), exec->globalData().propertyNames->emptyIdentifier);
92             return function;
93         }
94     
95         static EncodedJSValue JSC_HOST_CALL constructThrowTypeError(ExecState* exec)
96         {
97             throwTypeError(exec, static_cast<StrictModeTypeErrorFunction*>(exec->callee())->m_message);
98             return JSValue::encode(jsNull());
99         }
100     
101         static ConstructType getConstructData(JSCell*, ConstructData& constructData)
102         {
103             constructData.native.function = constructThrowTypeError;
104             return ConstructTypeHost;
105         }
106     
107         static EncodedJSValue JSC_HOST_CALL callThrowTypeError(ExecState* exec)
108         {
109             throwTypeError(exec, static_cast<StrictModeTypeErrorFunction*>(exec->callee())->m_message);
110             return JSValue::encode(jsNull());
111         }
112
113         static CallType getCallData(JSCell*, CallData& callData)
114         {
115             callData.native.function = callThrowTypeError;
116             return CallTypeHost;
117         }
118
119         static const ClassInfo s_info;
120
121         static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype) 
122         { 
123             return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info); 
124         }
125
126     private:
127         UString m_message;
128     };
129
130 } // namespace JSC
131
132 #endif // Error_h