weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 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 | |
commit-queue@webkit.org | 0fc0afa | 2013-07-30 04:33:35 +0000 | [diff] [blame] | 24 | #include "Interpreter.h" |
saambarati1@gmail.com | f6d4324 | 2015-03-24 07:30:05 +0000 | [diff] [blame] | 25 | #include "RuntimeType.h" |
commit-queue@webkit.org | 0fc0afa | 2013-07-30 04:33:35 +0000 | [diff] [blame] | 26 | #include "SourceProvider.h" |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 27 | #include <wtf/Vector.h> |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 28 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 29 | namespace JSC { |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 30 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 31 | class ErrorInstance : public JSNonFinalObject { |
| 32 | public: |
| 33 | typedef JSNonFinalObject Base; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 34 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 35 | enum SourceTextWhereErrorOccurred { FoundExactSource, FoundApproximateSource }; |
| 36 | typedef String (*SourceAppender) (const String& originalMessage, const String& sourceText, RuntimeType, SourceTextWhereErrorOccurred); |
| 37 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 38 | DECLARE_INFO; |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 39 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 40 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
| 41 | { |
| 42 | return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), info()); |
| 43 | } |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 44 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 45 | static ErrorInstance* create(ExecState* exec, VM& vm, Structure* structure, const String& message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 46 | { |
| 47 | ErrorInstance* instance = new (NotNull, allocateCell<ErrorInstance>(vm.heap)) ErrorInstance(vm, structure); |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 48 | instance->m_sourceAppender = appender; |
| 49 | instance->m_runtimeTypeForCause = type; |
| 50 | instance->finishCreation(exec, vm, message, useCurrentFrame); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 51 | return instance; |
| 52 | } |
ggaren@apple.com | 64be5e9 | 2012-01-24 07:34:10 +0000 | [diff] [blame] | 53 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 54 | static ErrorInstance* create(ExecState* exec, Structure* structure, JSValue message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 55 | { |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 56 | return create(exec, exec->vm(), structure, message.isUndefined() ? String() : message.toString(exec)->value(exec), appender, type, useCurrentFrame); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 57 | } |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 58 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 59 | static void addErrorInfo(ExecState*, VM&, JSObject*, bool = true); |
saambarati1@gmail.com | f6d4324 | 2015-03-24 07:30:05 +0000 | [diff] [blame] | 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; } |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 68 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 69 | protected: |
| 70 | explicit ErrorInstance(VM&, Structure*); |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 71 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 72 | void finishCreation(ExecState*, VM&, const String&, bool useCurrentFrame = true); |
commit-queue@webkit.org | 53aecd2 | 2011-08-19 00:58:34 +0000 | [diff] [blame] | 73 | |
saambarati1@gmail.com | f6d4324 | 2015-03-24 07:30:05 +0000 | [diff] [blame] | 74 | SourceAppender m_sourceAppender { nullptr }; |
| 75 | RuntimeType m_runtimeTypeForCause { TypeNothing }; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 76 | }; |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 77 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 78 | } // namespace JSC |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 79 | |
| 80 | #endif // ErrorInstance_h |