]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/ErrorInstance.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / ErrorInstance.h
CommitLineData
b37bf2e1 1/*
9dae56ea
A
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2008 Apple Inc. All rights reserved.
b37bf2e1
A
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
9dae56ea
A
21#ifndef ErrorInstance_h
22#define ErrorInstance_h
b37bf2e1 23
81345200 24#include "Interpreter.h"
ed1e77d3 25#include "RuntimeType.h"
81345200 26#include "SourceProvider.h"
ed1e77d3 27#include <wtf/Vector.h>
b37bf2e1 28
9dae56ea 29namespace JSC {
b37bf2e1 30
ed1e77d3
A
31class ErrorInstance : public JSNonFinalObject {
32public:
33 typedef JSNonFinalObject Base;
6fe7ccc8 34
ed1e77d3
A
35 enum SourceTextWhereErrorOccurred { FoundExactSource, FoundApproximateSource };
36 typedef String (*SourceAppender) (const String& originalMessage, const String& sourceText, RuntimeType, SourceTextWhereErrorOccurred);
b37bf2e1 37
ed1e77d3 38 DECLARE_INFO;
14957cd0 39
ed1e77d3
A
40 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
41 {
42 return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), info());
43 }
14957cd0 44
ed1e77d3
A
45 static ErrorInstance* create(ExecState* exec, VM& vm, Structure* structure, const String& message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true)
46 {
47 ErrorInstance* instance = new (NotNull, allocateCell<ErrorInstance>(vm.heap)) ErrorInstance(vm, structure);
48 instance->m_sourceAppender = appender;
49 instance->m_runtimeTypeForCause = type;
50 instance->finishCreation(exec, vm, message, useCurrentFrame);
51 return instance;
52 }
14957cd0 53
ed1e77d3
A
54 static ErrorInstance* create(ExecState* exec, Structure* structure, JSValue message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true)
55 {
56 return create(exec, exec->vm(), structure, message.isUndefined() ? String() : message.toString(exec)->value(exec), appender, type, useCurrentFrame);
57 }
14957cd0 58
ed1e77d3 59 static void addErrorInfo(ExecState*, VM&, JSObject*, bool = true);
6fe7ccc8 60
ed1e77d3
A
61 bool hasSourceAppender() const { return !!m_sourceAppender; }
62 SourceAppender sourceAppender() const { return m_sourceAppender; }
63 void setSourceAppender(SourceAppender appender) { m_sourceAppender = appender; }
64 void clearSourceAppender() { m_sourceAppender = nullptr; }
65 void setRuntimeTypeForCause(RuntimeType type) { m_runtimeTypeForCause = type; }
66 RuntimeType runtimeTypeForCause() const { return m_runtimeTypeForCause; }
67 void clearRuntimeTypeForCause() { m_runtimeTypeForCause = TypeNothing; }
14957cd0 68
ed1e77d3
A
69protected:
70 explicit ErrorInstance(VM&, Structure*);
71
72 void finishCreation(ExecState*, VM&, const String&, bool useCurrentFrame = true);
73
74 SourceAppender m_sourceAppender { nullptr };
75 RuntimeType m_runtimeTypeForCause { TypeNothing };
76};
b37bf2e1 77
9dae56ea 78} // namespace JSC
b37bf2e1 79
9dae56ea 80#endif // ErrorInstance_h