2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2008 Apple Inc. All rights reserved.
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.
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.
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
21 #ifndef ErrorInstance_h
22 #define ErrorInstance_h
24 #include "Interpreter.h"
25 #include "RuntimeType.h"
26 #include "SourceProvider.h"
27 #include <wtf/Vector.h>
31 class ErrorInstance
: public JSNonFinalObject
{
33 typedef JSNonFinalObject Base
;
35 enum SourceTextWhereErrorOccurred
{ FoundExactSource
, FoundApproximateSource
};
36 typedef String (*SourceAppender
) (const String
& originalMessage
, const String
& sourceText
, RuntimeType
, SourceTextWhereErrorOccurred
);
40 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
42 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(ErrorInstanceType
, StructureFlags
), info());
45 static ErrorInstance
* create(ExecState
* exec
, VM
& vm
, Structure
* structure
, const String
& message
, SourceAppender appender
= nullptr, RuntimeType type
= TypeNothing
, bool useCurrentFrame
= true)
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
);
54 static ErrorInstance
* create(ExecState
* exec
, Structure
* structure
, JSValue message
, SourceAppender appender
= nullptr, RuntimeType type
= TypeNothing
, bool useCurrentFrame
= true)
56 return create(exec
, exec
->vm(), structure
, message
.isUndefined() ? String() : message
.toString(exec
)->value(exec
), appender
, type
, useCurrentFrame
);
59 static void addErrorInfo(ExecState
*, VM
&, JSObject
*, bool = true);
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
; }
70 explicit ErrorInstance(VM
&, Structure
*);
72 void finishCreation(ExecState
*, VM
&, const String
&, bool useCurrentFrame
= true);
74 SourceAppender m_sourceAppender
{ nullptr };
75 RuntimeType m_runtimeTypeForCause
{ TypeNothing
};
80 #endif // ErrorInstance_h