JSCell.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
  3. * Copyright (C) 2001 Peter Kelly (pmk@post.com)
  4. * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this library; see the file COPYING.LIB. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. *
  21. */
  22. #include "config.h"
  23. #include "JSCell.h"
  24. #include "JSFunction.h"
  25. #include "JSString.h"
  26. #include "JSObject.h"
  27. #include "NumberObject.h"
  28. #include "Operations.h"
  29. #include <wtf/MathExtras.h>
  30. namespace JSC {
  31. ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell);
  32. void JSCell::destroy(JSCell* cell)
  33. {
  34. cell->JSCell::~JSCell();
  35. }
  36. void JSCell::copyBackingStore(JSCell*, CopyVisitor&)
  37. {
  38. }
  39. bool JSCell::getString(ExecState* exec, String& stringValue) const
  40. {
  41. if (!isString())
  42. return false;
  43. stringValue = static_cast<const JSString*>(this)->value(exec);
  44. return true;
  45. }
  46. String JSCell::getString(ExecState* exec) const
  47. {
  48. return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
  49. }
  50. JSObject* JSCell::getObject()
  51. {
  52. return isObject() ? asObject(this) : 0;
  53. }
  54. const JSObject* JSCell::getObject() const
  55. {
  56. return isObject() ? static_cast<const JSObject*>(this) : 0;
  57. }
  58. CallType JSCell::getCallData(JSCell*, CallData& callData)
  59. {
  60. callData.js.functionExecutable = 0;
  61. callData.js.scope = 0;
  62. callData.native.function = 0;
  63. return CallTypeNone;
  64. }
  65. ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData)
  66. {
  67. constructData.js.functionExecutable = 0;
  68. constructData.js.scope = 0;
  69. constructData.native.function = 0;
  70. return ConstructTypeNone;
  71. }
  72. bool JSCell::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName identifier, PropertySlot& slot)
  73. {
  74. // This is not a general purpose implementation of getOwnPropertySlot.
  75. // It should only be called by JSValue::get.
  76. // It calls getPropertySlot, not getOwnPropertySlot.
  77. JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
  78. slot.setBase(object);
  79. if (!object->getPropertySlot(exec, identifier, slot))
  80. slot.setUndefined();
  81. return true;
  82. }
  83. bool JSCell::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned identifier, PropertySlot& slot)
  84. {
  85. // This is not a general purpose implementation of getOwnPropertySlot.
  86. // It should only be called by JSValue::get.
  87. // It calls getPropertySlot, not getOwnPropertySlot.
  88. JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
  89. slot.setBase(object);
  90. if (!object->getPropertySlot(exec, identifier, slot))
  91. slot.setUndefined();
  92. return true;
  93. }
  94. void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
  95. {
  96. if (cell->isString()) {
  97. JSValue(cell).putToPrimitive(exec, identifier, value, slot);
  98. return;
  99. }
  100. JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
  101. thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
  102. }
  103. void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
  104. {
  105. if (cell->isString()) {
  106. PutPropertySlot slot(shouldThrow);
  107. JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
  108. return;
  109. }
  110. JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
  111. thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow);
  112. }
  113. bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
  114. {
  115. JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
  116. return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
  117. }
  118. bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
  119. {
  120. JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
  121. return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
  122. }
  123. JSObject* JSCell::toThisObject(JSCell* cell, ExecState* exec)
  124. {
  125. return cell->toObject(exec, exec->lexicalGlobalObject());
  126. }
  127. JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
  128. {
  129. if (isString())
  130. return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
  131. return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
  132. }
  133. bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
  134. {
  135. if (isString())
  136. return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
  137. return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
  138. }
  139. double JSCell::toNumber(ExecState* exec) const
  140. {
  141. if (isString())
  142. return static_cast<const JSString*>(this)->toNumber(exec);
  143. return static_cast<const JSObject*>(this)->toNumber(exec);
  144. }
  145. JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
  146. {
  147. if (isString())
  148. return static_cast<const JSString*>(this)->toObject(exec, globalObject);
  149. ASSERT(isObject());
  150. return jsCast<JSObject*>(const_cast<JSCell*>(this));
  151. }
  152. void slowValidateCell(JSCell* cell)
  153. {
  154. ASSERT_GC_OBJECT_LOOKS_VALID(cell);
  155. }
  156. JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
  157. {
  158. RELEASE_ASSERT_NOT_REACHED();
  159. return jsUndefined();
  160. }
  161. void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
  162. {
  163. RELEASE_ASSERT_NOT_REACHED();
  164. }
  165. void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
  166. {
  167. RELEASE_ASSERT_NOT_REACHED();
  168. }
  169. String JSCell::className(const JSObject*)
  170. {
  171. RELEASE_ASSERT_NOT_REACHED();
  172. return String();
  173. }
  174. const char* JSCell::className()
  175. {
  176. return classInfo()->className;
  177. }
  178. void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
  179. {
  180. RELEASE_ASSERT_NOT_REACHED();
  181. }
  182. bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
  183. {
  184. RELEASE_ASSERT_NOT_REACHED();
  185. return false;
  186. }
  187. void JSCell::putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned)
  188. {
  189. RELEASE_ASSERT_NOT_REACHED();
  190. }
  191. bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool)
  192. {
  193. RELEASE_ASSERT_NOT_REACHED();
  194. return false;
  195. }
  196. bool JSCell::getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&)
  197. {
  198. RELEASE_ASSERT_NOT_REACHED();
  199. return false;
  200. }
  201. } // namespace JSC