]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/Error.h
JavaScriptCore-1097.3.3.tar.gz
[apple/javascriptcore.git] / runtime / Error.h
CommitLineData
9dae56ea
A
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
6fe7ccc8
A
26#include "InternalFunction.h"
27#include "Interpreter.h"
14957cd0 28#include "JSObject.h"
9dae56ea
A
29#include <stdint.h>
30
31namespace JSC {
32
33 class ExecState;
14957cd0
A
34 class JSGlobalData;
35 class JSGlobalObject;
9dae56ea 36 class JSObject;
14957cd0
A
37 class SourceCode;
38 class Structure;
9dae56ea
A
39 class UString;
40
14957cd0
A
41 // Methods to create a range of internal errors.
42 JSObject* createError(JSGlobalObject*, const UString&);
43 JSObject* createEvalError(JSGlobalObject*, const UString&);
44 JSObject* createRangeError(JSGlobalObject*, const UString&);
45 JSObject* createReferenceError(JSGlobalObject*, const UString&);
46 JSObject* createSyntaxError(JSGlobalObject*, const UString&);
47 JSObject* createTypeError(JSGlobalObject*, const UString&);
6fe7ccc8 48 JSObject* createNotEnoughArgumentsError(JSGlobalObject*);
14957cd0
A
49 JSObject* createURIError(JSGlobalObject*, const UString&);
50 // ExecState wrappers.
6fe7ccc8 51 JS_EXPORT_PRIVATE JSObject* createError(ExecState*, const UString&);
14957cd0 52 JSObject* createEvalError(ExecState*, const UString&);
6fe7ccc8
A
53 JS_EXPORT_PRIVATE JSObject* createRangeError(ExecState*, const UString&);
54 JS_EXPORT_PRIVATE JSObject* createReferenceError(ExecState*, const UString&);
55 JS_EXPORT_PRIVATE JSObject* createSyntaxError(ExecState*, const UString&);
56 JS_EXPORT_PRIVATE JSObject* createTypeError(ExecState*, const UString&);
57 JS_EXPORT_PRIVATE JSObject* createNotEnoughArgumentsError(ExecState*);
14957cd0
A
58 JSObject* createURIError(ExecState*, const UString&);
59
60 // Methods to add
61 bool hasErrorInfo(ExecState*, JSObject* error);
14957cd0
A
62 // ExecState wrappers.
63 JSObject* addErrorInfo(ExecState*, JSObject* error, int line, const SourceCode&);
9dae56ea 64
14957cd0 65 // Methods to throw Errors.
6fe7ccc8
A
66 JS_EXPORT_PRIVATE JSValue throwError(ExecState*, JSValue);
67 JS_EXPORT_PRIVATE JSObject* throwError(ExecState*, JSObject*);
9dae56ea 68
14957cd0 69 // Convenience wrappers, create an throw an exception with a default message.
6fe7ccc8
A
70 JS_EXPORT_PRIVATE JSObject* throwTypeError(ExecState*);
71 JS_EXPORT_PRIVATE JSObject* throwSyntaxError(ExecState*);
14957cd0
A
72
73 // Convenience wrappers, wrap result as an EncodedJSValue.
74 inline EncodedJSValue throwVMError(ExecState* exec, JSValue error) { return JSValue::encode(throwError(exec, error)); }
75 inline EncodedJSValue throwVMTypeError(ExecState* exec) { return JSValue::encode(throwTypeError(exec)); }
76
6fe7ccc8
A
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 static void destroy(JSCell*);
86
87 public:
88 typedef InternalFunction Base;
89
90 static StrictModeTypeErrorFunction* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, const UString& message)
91 {
92 StrictModeTypeErrorFunction* function = new (NotNull, allocateCell<StrictModeTypeErrorFunction>(*exec->heap())) StrictModeTypeErrorFunction(globalObject, structure, message);
93 function->finishCreation(exec->globalData(), exec->globalData().propertyNames->emptyIdentifier);
94 return function;
95 }
96
97 static EncodedJSValue JSC_HOST_CALL constructThrowTypeError(ExecState* exec)
98 {
99 throwTypeError(exec, static_cast<StrictModeTypeErrorFunction*>(exec->callee())->m_message);
100 return JSValue::encode(jsNull());
101 }
102
103 static ConstructType getConstructData(JSCell*, ConstructData& constructData)
104 {
105 constructData.native.function = constructThrowTypeError;
106 return ConstructTypeHost;
107 }
14957cd0 108
6fe7ccc8
A
109 static EncodedJSValue JSC_HOST_CALL callThrowTypeError(ExecState* exec)
110 {
111 throwTypeError(exec, static_cast<StrictModeTypeErrorFunction*>(exec->callee())->m_message);
112 return JSValue::encode(jsNull());
113 }
114
115 static CallType getCallData(JSCell*, CallData& callData)
116 {
117 callData.native.function = callThrowTypeError;
118 return CallTypeHost;
119 }
120
121 static const ClassInfo s_info;
122
123 static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
124 {
125 return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
126 }
127
128 private:
129 UString m_message;
130 };
131
9dae56ea
A
132} // namespace JSC
133
134#endif // Error_h