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