Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: src/api.cc

Issue 1965593002: Fix Map::AsArray to properly iterate over the backing store (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Micro-optimized Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 result_index = 0;
6374 if (table->KeyAt(i)->IsTheHole()) continue; 6373 {
6375 result->set(i * 2, table->KeyAt(i)); 6374 i::DisallowHeapAllocation no_gc;
6376 result->set(i * 2 + 1, table->ValueAt(i)); 6375 int capacity = table->UsedCapacity();
6376 i::Oddball* the_hole = isolate->heap()->the_hole_value();
6377 for (int i = 0; i < capacity; ++i) {
6378 i::Object* key = table->KeyAt(i);
6379 if (key == the_hole) continue;
6380 result->set(result_index++, key);
6381 result->set(result_index++, table->ValueAt(i));
6382 }
6377 } 6383 }
6384 DCHECK_EQ(result_index, result->length());
6385 DCHECK_EQ(result_index, length);
6378 i::Handle<i::JSArray> result_array = 6386 i::Handle<i::JSArray> result_array =
6379 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); 6387 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length);
6380 return Utils::ToLocal(result_array); 6388 return Utils::ToLocal(result_array);
6381 } 6389 }
6382 6390
6383 6391
6384 Local<v8::Set> v8::Set::New(Isolate* isolate) { 6392 Local<v8::Set> v8::Set::New(Isolate* isolate) {
6385 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6393 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6386 LOG_API(i_isolate, "Set::New"); 6394 LOG_API(i_isolate, "Set::New");
6387 ENTER_V8(i_isolate); 6395 ENTER_V8(i_isolate);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
6444 } 6452 }
6445 6453
6446 6454
6447 Local<Array> Set::AsArray() const { 6455 Local<Array> Set::AsArray() const {
6448 i::Handle<i::JSSet> obj = Utils::OpenHandle(this); 6456 i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
6449 i::Isolate* isolate = obj->GetIsolate(); 6457 i::Isolate* isolate = obj->GetIsolate();
6450 i::Factory* factory = isolate->factory(); 6458 i::Factory* factory = isolate->factory();
6451 LOG_API(isolate, "Set::AsArray"); 6459 LOG_API(isolate, "Set::AsArray");
6452 ENTER_V8(isolate); 6460 ENTER_V8(isolate);
6453 i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(obj->table())); 6461 i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(obj->table()));
6454 int capacity = table->UsedCapacity();
6455 int length = table->NumberOfElements(); 6462 int length = table->NumberOfElements();
6456 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); 6463 i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
6457 int result_index = 0; 6464 int result_index = 0;
6458 for (int i = 0; i < capacity; ++i) { 6465 {
6459 i::Object* key = table->KeyAt(i); 6466 i::DisallowHeapAllocation no_gc;
6460 if (!key->IsTheHole()) { 6467 int capacity = table->UsedCapacity();
6468 i::Oddball* the_hole = isolate->heap()->the_hole_value();
6469 for (int i = 0; i < capacity; ++i) {
6470 i::Object* key = table->KeyAt(i);
6471 if (key == the_hole) continue;
6461 result->set(result_index++, key); 6472 result->set(result_index++, key);
6462 } 6473 }
6463 } 6474 }
6464 DCHECK_EQ(result_index, result->length()); 6475 DCHECK_EQ(result_index, result->length());
6465 DCHECK_EQ(result_index, length); 6476 DCHECK_EQ(result_index, length);
6466 i::Handle<i::JSArray> result_array = 6477 i::Handle<i::JSArray> result_array =
6467 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); 6478 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length);
6468 return Utils::ToLocal(result_array); 6479 return Utils::ToLocal(result_array);
6469 } 6480 }
6470 6481
(...skipping 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after
8817 Address callback_address = 8828 Address callback_address =
8818 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8829 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8819 VMState<EXTERNAL> state(isolate); 8830 VMState<EXTERNAL> state(isolate);
8820 ExternalCallbackScope call_scope(isolate, callback_address); 8831 ExternalCallbackScope call_scope(isolate, callback_address);
8821 callback(info); 8832 callback(info);
8822 } 8833 }
8823 8834
8824 8835
8825 } // namespace internal 8836 } // namespace internal
8826 } // namespace v8 8837 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698