ObjectConstructor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ObjectConstructor_h
  21. #define ObjectConstructor_h
  22. #include "InternalFunction.h"
  23. #include "JSGlobalObject.h"
  24. #include "ObjectPrototype.h"
  25. namespace JSC {
  26. class ObjectPrototype;
  27. class ObjectConstructor : public InternalFunction {
  28. public:
  29. typedef InternalFunction Base;
  30. static ObjectConstructor* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, ObjectPrototype* objectPrototype)
  31. {
  32. ObjectConstructor* constructor = new (NotNull, allocateCell<ObjectConstructor>(*exec->heap())) ObjectConstructor(globalObject, structure);
  33. constructor->finishCreation(exec, objectPrototype);
  34. return constructor;
  35. }
  36. static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
  37. static bool getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
  38. static const ClassInfo s_info;
  39. static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
  40. {
  41. return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
  42. }
  43. protected:
  44. void finishCreation(ExecState*, ObjectPrototype*);
  45. static const unsigned StructureFlags = OverridesGetOwnPropertySlot | InternalFunction::StructureFlags;
  46. private:
  47. ObjectConstructor(JSGlobalObject*, Structure*);
  48. static ConstructType getConstructData(JSCell*, ConstructData&);
  49. static CallType getCallData(JSCell*, CallData&);
  50. };
  51. inline JSObject* constructEmptyObject(ExecState* exec, Structure* structure)
  52. {
  53. return JSFinalObject::create(exec, structure);
  54. }
  55. inline JSObject* constructEmptyObject(ExecState* exec, JSObject* prototype, unsigned inlineCapacity)
  56. {
  57. JSGlobalObject* globalObject = exec->lexicalGlobalObject();
  58. PrototypeMap& prototypeMap = globalObject->vm().prototypeMap;
  59. Structure* structure = prototypeMap.emptyObjectStructureForPrototype(
  60. prototype, inlineCapacity);
  61. return constructEmptyObject(exec, structure);
  62. }
  63. inline JSObject* constructEmptyObject(ExecState* exec, JSObject* prototype)
  64. {
  65. return constructEmptyObject(exec, prototype, JSFinalObject::defaultInlineCapacity());
  66. }
  67. inline JSObject* constructEmptyObject(ExecState* exec)
  68. {
  69. return constructEmptyObject(exec, exec->lexicalGlobalObject()->objectPrototype());
  70. }
  71. } // namespace JSC
  72. #endif // ObjectConstructor_h