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 "JSObject.h" 25 26namespace JSC { 27 28 class ErrorInstance : public JSNonFinalObject { 29 public: 30 typedef JSNonFinalObject Base; 31 32 static const ClassInfo s_info; 33 34 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 35 { 36 return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), &s_info); 37 } 38 39 static ErrorInstance* create(VM& vm, Structure* structure, const String& message) 40 { 41 ErrorInstance* instance = new (NotNull, allocateCell<ErrorInstance>(vm.heap)) ErrorInstance(vm, structure); 42 instance->finishCreation(vm, message); 43 return instance; 44 } 45 46 static ErrorInstance* create(ExecState* exec, Structure* structure, JSValue message) 47 { 48 return create(exec->vm(), structure, message.isUndefined() ? String() : message.toString(exec)->value(exec)); 49 } 50 51 bool appendSourceToMessage() { return m_appendSourceToMessage; } 52 void setAppendSourceToMessage() { m_appendSourceToMessage = true; } 53 void clearAppendSourceToMessage() { m_appendSourceToMessage = false; } 54 55 protected: 56 explicit ErrorInstance(VM&, Structure*); 57 58 void finishCreation(VM& vm, const String& message) 59 { 60 Base::finishCreation(vm); 61 ASSERT(inherits(&s_info)); 62 if (!message.isNull()) 63 putDirect(vm, vm.propertyNames->message, jsString(&vm, message), DontEnum); 64 } 65 66 bool m_appendSourceToMessage; 67 }; 68 69} // namespace JSC 70 71#endif // ErrorInstance_h 72