Lookup.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2008, 2012 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 Lesser 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. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. *
  18. */
  19. #include "config.h"
  20. #include "Lookup.h"
  21. #include "Executable.h"
  22. #include "JSFunction.h"
  23. #include "Operations.h"
  24. namespace JSC {
  25. void HashTable::createTable(VM* vm) const
  26. {
  27. ASSERT(!table);
  28. int linkIndex = compactHashSizeMask + 1;
  29. HashEntry* entries = new HashEntry[compactSize];
  30. for (int i = 0; i < compactSize; ++i)
  31. entries[i].setKey(0);
  32. for (int i = 0; values[i].key; ++i) {
  33. StringImpl* identifier = Identifier::add(vm, values[i].key).leakRef();
  34. int hashIndex = identifier->existingHash() & compactHashSizeMask;
  35. HashEntry* entry = &entries[hashIndex];
  36. if (entry->key()) {
  37. while (entry->next()) {
  38. entry = entry->next();
  39. }
  40. ASSERT(linkIndex < compactSize);
  41. entry->setNext(&entries[linkIndex++]);
  42. entry = entry->next();
  43. }
  44. entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2, values[i].intrinsic);
  45. }
  46. table = entries;
  47. }
  48. void HashTable::deleteTable() const
  49. {
  50. if (table) {
  51. int max = compactSize;
  52. for (int i = 0; i != max; ++i) {
  53. if (StringImpl* key = table[i].key())
  54. key->deref();
  55. }
  56. delete [] table;
  57. table = 0;
  58. }
  59. }
  60. bool setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, PropertyName propertyName, PropertySlot& slot)
  61. {
  62. ASSERT(thisObj->globalObject());
  63. ASSERT(entry->attributes() & Function);
  64. PropertyOffset offset = thisObj->getDirectOffset(exec->vm(), propertyName);
  65. if (!isValidOffset(offset)) {
  66. // If a property is ever deleted from an object with a static table, then we reify
  67. // all static functions at that time - after this we shouldn't be re-adding anything.
  68. if (thisObj->staticFunctionsReified())
  69. return false;
  70. thisObj->putDirectNativeFunction(
  71. exec, thisObj->globalObject(), propertyName, entry->functionLength(),
  72. entry->function(), entry->intrinsic(), entry->attributes());
  73. offset = thisObj->getDirectOffset(exec->vm(), propertyName);
  74. ASSERT(isValidOffset(offset));
  75. }
  76. slot.setValue(thisObj, thisObj->getDirect(offset), offset);
  77. return true;
  78. }
  79. } // namespace JSC