blob: 3f584a99f072e84d87c1a1a51ba030b15cf62e32 [file] [log] [blame]
weinig@apple.comfee62a72008-06-29 22:14:57 +00001/*
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
commit-queue@webkit.org0fc0afa2013-07-30 04:33:35 +000024#include "Interpreter.h"
saambarati1@gmail.comf6d43242015-03-24 07:30:05 +000025#include "RuntimeType.h"
commit-queue@webkit.org0fc0afa2013-07-30 04:33:35 +000026#include "SourceProvider.h"
mmirman@apple.comc35dac92015-04-07 21:34:05 +000027#include <wtf/Vector.h>
weinig@apple.comfee62a72008-06-29 22:14:57 +000028
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000029namespace JSC {
weinig@apple.comfee62a72008-06-29 22:14:57 +000030
mark.lam@apple.com188640e2014-09-04 19:10:36 +000031class ErrorInstance : public JSNonFinalObject {
32public:
33 typedef JSNonFinalObject Base;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000034
mmirman@apple.comc35dac92015-04-07 21:34:05 +000035 enum SourceTextWhereErrorOccurred { FoundExactSource, FoundApproximateSource };
36 typedef String (*SourceAppender) (const String& originalMessage, const String& sourceText, RuntimeType, SourceTextWhereErrorOccurred);
37
mark.lam@apple.com188640e2014-09-04 19:10:36 +000038 DECLARE_INFO;
weinig@apple.comfee62a72008-06-29 22:14:57 +000039
mark.lam@apple.com188640e2014-09-04 19:10:36 +000040 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
41 {
42 return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), info());
43 }
barraclough@apple.com9c099f92010-06-06 23:34:36 +000044
mmirman@apple.comc35dac92015-04-07 21:34:05 +000045 static ErrorInstance* create(ExecState* exec, VM& vm, Structure* structure, const String& message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000046 {
47 ErrorInstance* instance = new (NotNull, allocateCell<ErrorInstance>(vm.heap)) ErrorInstance(vm, structure);
mmirman@apple.comc35dac92015-04-07 21:34:05 +000048 instance->m_sourceAppender = appender;
49 instance->m_runtimeTypeForCause = type;
50 instance->finishCreation(exec, vm, message, useCurrentFrame);
mark.lam@apple.com188640e2014-09-04 19:10:36 +000051 return instance;
52 }
ggaren@apple.com64be5e92012-01-24 07:34:10 +000053
mmirman@apple.comc35dac92015-04-07 21:34:05 +000054 static ErrorInstance* create(ExecState* exec, Structure* structure, JSValue message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000055 {
mmirman@apple.comc35dac92015-04-07 21:34:05 +000056 return create(exec, exec->vm(), structure, message.isUndefined() ? String() : message.toString(exec)->value(exec), appender, type, useCurrentFrame);
mark.lam@apple.com188640e2014-09-04 19:10:36 +000057 }
barraclough@apple.come979a652010-11-16 01:30:25 +000058
mmirman@apple.comc35dac92015-04-07 21:34:05 +000059 static void addErrorInfo(ExecState*, VM&, JSObject*, bool = true);
saambarati1@gmail.comf6d43242015-03-24 07:30:05 +000060
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; }
barraclough@apple.come979a652010-11-16 01:30:25 +000068
mark.lam@apple.com188640e2014-09-04 19:10:36 +000069protected:
70 explicit ErrorInstance(VM&, Structure*);
barraclough@apple.come979a652010-11-16 01:30:25 +000071
mmirman@apple.comc35dac92015-04-07 21:34:05 +000072 void finishCreation(ExecState*, VM&, const String&, bool useCurrentFrame = true);
commit-queue@webkit.org53aecd22011-08-19 00:58:34 +000073
saambarati1@gmail.comf6d43242015-03-24 07:30:05 +000074 SourceAppender m_sourceAppender { nullptr };
75 RuntimeType m_runtimeTypeForCause { TypeNothing };
mark.lam@apple.com188640e2014-09-04 19:10:36 +000076};
weinig@apple.comfee62a72008-06-29 22:14:57 +000077
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000078} // namespace JSC
weinig@apple.comfee62a72008-06-29 22:14:57 +000079
80#endif // ErrorInstance_h