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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 6349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6360 } | 6360 } |
6361 | 6361 |
6362 | 6362 |
6363 Local<Array> Map::AsArray() const { | 6363 Local<Array> Map::AsArray() const { |
6364 i::Handle<i::JSMap> obj = Utils::OpenHandle(this); | 6364 i::Handle<i::JSMap> obj = Utils::OpenHandle(this); |
6365 i::Isolate* isolate = obj->GetIsolate(); | 6365 i::Isolate* isolate = obj->GetIsolate(); |
6366 i::Factory* factory = isolate->factory(); | 6366 i::Factory* factory = isolate->factory(); |
6367 LOG_API(isolate, "Map::AsArray"); | 6367 LOG_API(isolate, "Map::AsArray"); |
6368 ENTER_V8(isolate); | 6368 ENTER_V8(isolate); |
6369 i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table())); | 6369 i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table())); |
6370 int size = table->NumberOfElements(); | 6370 int length = table->NumberOfElements() * 2; |
6371 int length = size * 2; | |
6372 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); | 6371 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); |
6373 for (int i = 0; i < size; ++i) { | 6372 int capacity = table->UsedCapacity(); |
6374 if (table->KeyAt(i)->IsTheHole()) continue; | 6373 int result_index = 0; |
6375 result->set(i * 2, table->KeyAt(i)); | 6374 for (int i = 0; i < capacity; ++i) { |
6376 result->set(i * 2 + 1, table->ValueAt(i)); | 6375 i::Object* key = table->KeyAt(i); |
6376 if (key->IsTheHole()) continue; | |
Camillo Bruni
2016/05/10 06:50:59
nit: IsTheHole in a loop is rather slow, keep a lo
adamk
2016/05/10 17:19:24
Done, and added a DisallowHeapAllocation for good
| |
6377 result->set(result_index++, key); | |
6378 result->set(result_index++, table->ValueAt(i)); | |
6377 } | 6379 } |
6380 DCHECK_EQ(result_index, result->length()); | |
6381 DCHECK_EQ(result_index, length); | |
6378 i::Handle<i::JSArray> result_array = | 6382 i::Handle<i::JSArray> result_array = |
6379 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); | 6383 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); |
6380 return Utils::ToLocal(result_array); | 6384 return Utils::ToLocal(result_array); |
6381 } | 6385 } |
6382 | 6386 |
6383 | 6387 |
6384 Local<v8::Set> v8::Set::New(Isolate* isolate) { | 6388 Local<v8::Set> v8::Set::New(Isolate* isolate) { |
6385 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6389 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6386 LOG_API(i_isolate, "Set::New"); | 6390 LOG_API(i_isolate, "Set::New"); |
6387 ENTER_V8(i_isolate); | 6391 ENTER_V8(i_isolate); |
(...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8817 Address callback_address = | 8821 Address callback_address = |
8818 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8822 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8819 VMState<EXTERNAL> state(isolate); | 8823 VMState<EXTERNAL> state(isolate); |
8820 ExternalCallbackScope call_scope(isolate, callback_address); | 8824 ExternalCallbackScope call_scope(isolate, callback_address); |
8821 callback(info); | 8825 callback(info); |
8822 } | 8826 } |
8823 | 8827 |
8824 | 8828 |
8825 } // namespace internal | 8829 } // namespace internal |
8826 } // namespace v8 | 8830 } // namespace v8 |
OLD | NEW |