| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/interface.h" | 7 #include "src/interface.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 | 11 |
| 12 static bool Match(void* key1, void* key2) { |
| 13 String* name1 = *static_cast<String**>(key1); |
| 14 String* name2 = *static_cast<String**>(key2); |
| 15 ASSERT(name1->IsInternalizedString()); |
| 16 ASSERT(name2->IsInternalizedString()); |
| 17 return name1 == name2; |
| 18 } |
| 19 |
| 20 |
| 12 Interface* Interface::Lookup(Handle<String> name, Zone* zone) { | 21 Interface* Interface::Lookup(Handle<String> name, Zone* zone) { |
| 13 ASSERT(IsModule()); | 22 ASSERT(IsModule()); |
| 14 ZoneHashMap* map = Chase()->exports_; | 23 ZoneHashMap* map = Chase()->exports_; |
| 15 if (map == NULL) return NULL; | 24 if (map == NULL) return NULL; |
| 16 ZoneAllocationPolicy allocator(zone); | 25 ZoneAllocationPolicy allocator(zone); |
| 17 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false, | 26 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false, |
| 18 allocator); | 27 allocator); |
| 19 if (p == NULL) return NULL; | 28 if (p == NULL) return NULL; |
| 20 ASSERT(*static_cast<String**>(p->key) == *name); | 29 ASSERT(*static_cast<String**>(p->key) == *name); |
| 21 ASSERT(p->value != NULL); | 30 ASSERT(p->value != NULL); |
| 22 return static_cast<Interface*>(p->value); | 31 return static_cast<Interface*>(p->value); |
| 23 } | 32 } |
| 24 | 33 |
| 25 | 34 |
| 26 #ifdef DEBUG | 35 #ifdef DEBUG |
| 27 // Current nesting depth for debug output. | 36 // Current nesting depth for debug output. |
| 28 class Nesting { | 37 class Nesting { |
| 29 public: | 38 public: |
| 30 Nesting() { current_ += 2; } | 39 Nesting() { current_ += 2; } |
| 31 ~Nesting() { current_ -= 2; } | 40 ~Nesting() { current_ -= 2; } |
| 32 static int current() { return current_; } | 41 static int current() { return current_; } |
| 33 private: | 42 private: |
| 34 static int current_; | 43 static int current_; |
| 35 }; | 44 }; |
| 36 | 45 |
| 37 int Nesting::current_ = 0; | 46 int Nesting::current_ = 0; |
| 38 #endif | 47 #endif |
| 39 | 48 |
| 40 | 49 |
| 41 void Interface::DoAdd(const void* name, uint32_t hash, Interface* interface, | 50 void Interface::DoAdd( |
| 42 Zone* zone, bool* ok) { | 51 void* name, uint32_t hash, Interface* interface, Zone* zone, bool* ok) { |
| 43 MakeModule(ok); | 52 MakeModule(ok); |
| 44 if (!*ok) return; | 53 if (!*ok) return; |
| 45 | 54 |
| 46 #ifdef DEBUG | 55 #ifdef DEBUG |
| 47 if (FLAG_print_interface_details) { | 56 if (FLAG_print_interface_details) { |
| 48 PrintF("%*s# Adding...\n", Nesting::current(), ""); | 57 PrintF("%*s# Adding...\n", Nesting::current(), ""); |
| 49 PrintF("%*sthis = ", Nesting::current(), ""); | 58 PrintF("%*sthis = ", Nesting::current(), ""); |
| 50 this->Print(Nesting::current()); | 59 this->Print(Nesting::current()); |
| 51 const AstString* symbol = static_cast<const AstString*>(name); | 60 PrintF("%*s%s : ", Nesting::current(), "", |
| 52 PrintF("%*s%.*s : ", Nesting::current(), "", symbol->length(), | 61 (*static_cast<String**>(name))->ToAsciiArray()); |
| 53 symbol->raw_data()); | |
| 54 interface->Print(Nesting::current()); | 62 interface->Print(Nesting::current()); |
| 55 } | 63 } |
| 56 #endif | 64 #endif |
| 57 | 65 |
| 58 ZoneHashMap** map = &Chase()->exports_; | 66 ZoneHashMap** map = &Chase()->exports_; |
| 59 ZoneAllocationPolicy allocator(zone); | 67 ZoneAllocationPolicy allocator(zone); |
| 60 | 68 |
| 61 if (*map == NULL) { | 69 if (*map == NULL) { |
| 62 *map = new(zone->New(sizeof(ZoneHashMap))) | 70 *map = new(zone->New(sizeof(ZoneHashMap))) |
| 63 ZoneHashMap(ZoneHashMap::PointersMatch, | 71 ZoneHashMap(Match, ZoneHashMap::kDefaultHashMapCapacity, allocator); |
| 64 ZoneHashMap::kDefaultHashMapCapacity, allocator); | |
| 65 } | 72 } |
| 66 | 73 |
| 67 ZoneHashMap::Entry* p = | 74 ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen(), allocator); |
| 68 (*map)->Lookup(const_cast<void*>(name), hash, !IsFrozen(), allocator); | |
| 69 if (p == NULL) { | 75 if (p == NULL) { |
| 70 // This didn't have name but was frozen already, that's an error. | 76 // This didn't have name but was frozen already, that's an error. |
| 71 *ok = false; | 77 *ok = false; |
| 72 } else if (p->value == NULL) { | 78 } else if (p->value == NULL) { |
| 73 p->value = interface; | 79 p->value = interface; |
| 74 } else { | 80 } else { |
| 75 #ifdef DEBUG | 81 #ifdef DEBUG |
| 76 Nesting nested; | 82 Nesting nested; |
| 77 #endif | 83 #endif |
| 78 static_cast<Interface*>(p->value)->Unify(interface, zone, ok); | 84 static_cast<Interface*>(p->value)->Unify(interface, zone, ok); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); | 213 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); |
| 208 interface->Print(n0 + 2); | 214 interface->Print(n0 + 2); |
| 209 } | 215 } |
| 210 PrintF("%*s}\n", n0, ""); | 216 PrintF("%*s}\n", n0, ""); |
| 211 } | 217 } |
| 212 } | 218 } |
| 213 } | 219 } |
| 214 #endif | 220 #endif |
| 215 | 221 |
| 216 } } // namespace v8::internal | 222 } } // namespace v8::internal |
| OLD | NEW |