| 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 "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "interface.h" | 7 #include "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 | |
| 21 Interface* Interface::Lookup(Handle<String> name, Zone* zone) { | 12 Interface* Interface::Lookup(Handle<String> name, Zone* zone) { |
| 22 ASSERT(IsModule()); | 13 ASSERT(IsModule()); |
| 23 ZoneHashMap* map = Chase()->exports_; | 14 ZoneHashMap* map = Chase()->exports_; |
| 24 if (map == NULL) return NULL; | 15 if (map == NULL) return NULL; |
| 25 ZoneAllocationPolicy allocator(zone); | 16 ZoneAllocationPolicy allocator(zone); |
| 26 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false, | 17 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false, |
| 27 allocator); | 18 allocator); |
| 28 if (p == NULL) return NULL; | 19 if (p == NULL) return NULL; |
| 29 ASSERT(*static_cast<String**>(p->key) == *name); | 20 ASSERT(*static_cast<String**>(p->key) == *name); |
| 30 ASSERT(p->value != NULL); | 21 ASSERT(p->value != NULL); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 void Interface::DoAdd( | 41 void Interface::DoAdd( |
| 51 void* name, uint32_t hash, Interface* interface, Zone* zone, bool* ok) { | 42 void* name, uint32_t hash, Interface* interface, Zone* zone, bool* ok) { |
| 52 MakeModule(ok); | 43 MakeModule(ok); |
| 53 if (!*ok) return; | 44 if (!*ok) return; |
| 54 | 45 |
| 55 #ifdef DEBUG | 46 #ifdef DEBUG |
| 56 if (FLAG_print_interface_details) { | 47 if (FLAG_print_interface_details) { |
| 57 PrintF("%*s# Adding...\n", Nesting::current(), ""); | 48 PrintF("%*s# Adding...\n", Nesting::current(), ""); |
| 58 PrintF("%*sthis = ", Nesting::current(), ""); | 49 PrintF("%*sthis = ", Nesting::current(), ""); |
| 59 this->Print(Nesting::current()); | 50 this->Print(Nesting::current()); |
| 60 PrintF("%*s%s : ", Nesting::current(), "", | 51 ParserSymbolTable::Symbol* symbol = |
| 61 (*static_cast<String**>(name))->ToAsciiArray()); | 52 static_cast<ParserSymbolTable::Symbol*>(name); |
| 53 PrintF("%*s%.*s : ", Nesting::current(), "", symbol->literal_bytes.length(), |
| 54 symbol->literal_bytes.start()); |
| 62 interface->Print(Nesting::current()); | 55 interface->Print(Nesting::current()); |
| 63 } | 56 } |
| 64 #endif | 57 #endif |
| 65 | 58 |
| 66 ZoneHashMap** map = &Chase()->exports_; | 59 ZoneHashMap** map = &Chase()->exports_; |
| 67 ZoneAllocationPolicy allocator(zone); | 60 ZoneAllocationPolicy allocator(zone); |
| 68 | 61 |
| 69 if (*map == NULL) { | 62 if (*map == NULL) { |
| 70 *map = new(zone->New(sizeof(ZoneHashMap))) | 63 *map = new(zone->New(sizeof(ZoneHashMap))) |
| 71 ZoneHashMap(Match, ZoneHashMap::kDefaultHashMapCapacity, allocator); | 64 ZoneHashMap(ZoneHashMap::PointersMatch, |
| 65 ZoneHashMap::kDefaultHashMapCapacity, allocator); |
| 72 } | 66 } |
| 73 | 67 |
| 74 ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen(), allocator); | 68 ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen(), allocator); |
| 75 if (p == NULL) { | 69 if (p == NULL) { |
| 76 // This didn't have name but was frozen already, that's an error. | 70 // This didn't have name but was frozen already, that's an error. |
| 77 *ok = false; | 71 *ok = false; |
| 78 } else if (p->value == NULL) { | 72 } else if (p->value == NULL) { |
| 79 p->value = interface; | 73 p->value = interface; |
| 80 } else { | 74 } else { |
| 81 #ifdef DEBUG | 75 #ifdef DEBUG |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); | 207 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); |
| 214 interface->Print(n0 + 2); | 208 interface->Print(n0 + 2); |
| 215 } | 209 } |
| 216 PrintF("%*s}\n", n0, ""); | 210 PrintF("%*s}\n", n0, ""); |
| 217 } | 211 } |
| 218 } | 212 } |
| 219 } | 213 } |
| 220 #endif | 214 #endif |
| 221 | 215 |
| 222 } } // namespace v8::internal | 216 } } // namespace v8::internal |
| OLD | NEW |