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