NativeErrorConstructor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 NativeErrorConstructor_h
  21. #define NativeErrorConstructor_h
  22. #include "InternalFunction.h"
  23. #include "NativeErrorPrototype.h"
  24. namespace JSC {
  25. class ErrorInstance;
  26. class FunctionPrototype;
  27. class NativeErrorPrototype;
  28. class NativeErrorConstructor : public InternalFunction {
  29. public:
  30. typedef InternalFunction Base;
  31. static NativeErrorConstructor* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, Structure* prototypeStructure, const String& name)
  32. {
  33. NativeErrorConstructor* constructor = new (NotNull, allocateCell<NativeErrorConstructor>(*exec->heap())) NativeErrorConstructor(globalObject, structure);
  34. constructor->finishCreation(exec, globalObject, prototypeStructure, name);
  35. return constructor;
  36. }
  37. static const ClassInfo s_info;
  38. static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
  39. {
  40. return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
  41. }
  42. Structure* errorStructure() { return m_errorStructure.get(); }
  43. protected:
  44. void finishCreation(ExecState* exec, JSGlobalObject* globalObject, Structure* prototypeStructure, const String& name)
  45. {
  46. Base::finishCreation(exec->vm(), name);
  47. ASSERT(inherits(&s_info));
  48. NativeErrorPrototype* prototype = NativeErrorPrototype::create(exec, globalObject, prototypeStructure, name, this);
  49. putDirect(exec->vm(), exec->propertyNames().length, jsNumber(1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
  50. putDirect(exec->vm(), exec->propertyNames().prototype, prototype, DontDelete | ReadOnly | DontEnum);
  51. m_errorStructure.set(exec->vm(), this, ErrorInstance::createStructure(exec->vm(), globalObject, prototype));
  52. ASSERT(m_errorStructure);
  53. ASSERT(m_errorStructure->isObject());
  54. }
  55. private:
  56. NativeErrorConstructor(JSGlobalObject*, Structure*);
  57. static const unsigned StructureFlags = OverridesVisitChildren | InternalFunction::StructureFlags;
  58. static ConstructType getConstructData(JSCell*, ConstructData&);
  59. static CallType getCallData(JSCell*, CallData&);
  60. static void visitChildren(JSCell*, SlotVisitor&);
  61. WriteBarrier<Structure> m_errorStructure;
  62. };
  63. } // namespace JSC
  64. #endif // NativeErrorConstructor_h