ErrorInstance.h 2.6 KB

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