]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2008 Apple Inc. All rights reserved. | |
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 | ||
21 | #ifndef ErrorInstance_h | |
22 | #define ErrorInstance_h | |
23 | ||
24 | #include "Interpreter.h" | |
25 | #include "RuntimeType.h" | |
26 | #include "SourceProvider.h" | |
27 | #include <wtf/Vector.h> | |
28 | ||
29 | namespace JSC { | |
30 | ||
31 | class ErrorInstance : public JSNonFinalObject { | |
32 | public: | |
33 | typedef JSNonFinalObject Base; | |
34 | ||
35 | enum SourceTextWhereErrorOccurred { FoundExactSource, FoundApproximateSource }; | |
36 | typedef String (*SourceAppender) (const String& originalMessage, const String& sourceText, RuntimeType, SourceTextWhereErrorOccurred); | |
37 | ||
38 | DECLARE_INFO; | |
39 | ||
40 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) | |
41 | { | |
42 | return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), info()); | |
43 | } | |
44 | ||
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 | } | |
53 | ||
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 | } | |
58 | ||
59 | static void addErrorInfo(ExecState*, VM&, JSObject*, bool = true); | |
60 | ||
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; } | |
68 | ||
69 | protected: | |
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 | }; | |
77 | ||
78 | } // namespace JSC | |
79 | ||
80 | #endif // ErrorInstance_h |