ArgList.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "config.h"
  21. #include "ArgList.h"
  22. #include "HeapRootVisitor.h"
  23. #include "JSCJSValue.h"
  24. #include "JSObject.h"
  25. #include "Operations.h"
  26. using std::min;
  27. namespace JSC {
  28. void ArgList::getSlice(int startIndex, ArgList& result) const
  29. {
  30. if (startIndex <= 0 || startIndex >= m_argCount) {
  31. result = ArgList();
  32. return;
  33. }
  34. result.m_args = m_args - startIndex;
  35. result.m_argCount = m_argCount - startIndex;
  36. }
  37. void MarkedArgumentBuffer::markLists(HeapRootVisitor& heapRootVisitor, ListSet& markSet)
  38. {
  39. ListSet::iterator end = markSet.end();
  40. for (ListSet::iterator it = markSet.begin(); it != end; ++it) {
  41. MarkedArgumentBuffer* list = *it;
  42. for (int i = 0; i < list->m_size; ++i)
  43. heapRootVisitor.visit(reinterpret_cast<JSValue*>(&list->slotFor(i)));
  44. }
  45. }
  46. void MarkedArgumentBuffer::slowAppend(JSValue v)
  47. {
  48. int newCapacity = m_capacity * 4;
  49. EncodedJSValue* newBuffer = &(new EncodedJSValue[newCapacity])[newCapacity - 1];
  50. for (int i = 0; i < m_capacity; ++i)
  51. newBuffer[-i] = m_buffer[-i];
  52. if (EncodedJSValue* base = mallocBase())
  53. delete [] base;
  54. m_buffer = newBuffer;
  55. m_capacity = newCapacity;
  56. slotFor(m_size) = JSValue::encode(v);
  57. ++m_size;
  58. if (m_markSet)
  59. return;
  60. // As long as our size stays within our Vector's inline
  61. // capacity, all our values are allocated on the stack, and
  62. // therefore don't need explicit marking. Once our size exceeds
  63. // our Vector's inline capacity, though, our values move to the
  64. // heap, where they do need explicit marking.
  65. for (int i = 0; i < m_size; ++i) {
  66. Heap* heap = Heap::heap(JSValue::decode(slotFor(i)));
  67. if (!heap)
  68. continue;
  69. m_markSet = &heap->markListSet();
  70. m_markSet->add(this);
  71. break;
  72. }
  73. }
  74. } // namespace JSC