| 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 6254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6265 } | 6265 } |
| 6266 | 6266 |
| 6267 | 6267 |
| 6268 Local<Array> Map::AsArray() const { | 6268 Local<Array> Map::AsArray() const { |
| 6269 i::Handle<i::JSMap> obj = Utils::OpenHandle(this); | 6269 i::Handle<i::JSMap> obj = Utils::OpenHandle(this); |
| 6270 i::Isolate* isolate = obj->GetIsolate(); | 6270 i::Isolate* isolate = obj->GetIsolate(); |
| 6271 i::Factory* factory = isolate->factory(); | 6271 i::Factory* factory = isolate->factory(); |
| 6272 LOG_API(isolate, "Map::AsArray"); | 6272 LOG_API(isolate, "Map::AsArray"); |
| 6273 ENTER_V8(isolate); | 6273 ENTER_V8(isolate); |
| 6274 i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table())); | 6274 i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table())); |
| 6275 int length = table->NumberOfElements(); | 6275 int size = table->NumberOfElements(); |
| 6276 int length = size * 2; |
| 6276 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); | 6277 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); |
| 6277 for (int i = 0; i < length; ++i) { | 6278 for (int i = 0; i < size; ++i) { |
| 6278 if (table->KeyAt(i)->IsTheHole()) continue; | 6279 if (table->KeyAt(i)->IsTheHole()) continue; |
| 6279 i::HandleScope handle_scope(isolate); | 6280 result->set(i * 2, table->KeyAt(i)); |
| 6280 i::Handle<i::FixedArray> entry = factory->NewFixedArray(2); | 6281 result->set(i * 2 + 1, table->ValueAt(i)); |
| 6281 entry->set(0, table->KeyAt(i)); | |
| 6282 entry->set(1, table->ValueAt(i)); | |
| 6283 i::Handle<i::JSArray> entry_array = | |
| 6284 factory->NewJSArrayWithElements(entry, i::FAST_ELEMENTS, 2); | |
| 6285 result->set(i, *entry_array); | |
| 6286 } | 6282 } |
| 6287 i::Handle<i::JSArray> result_array = | 6283 i::Handle<i::JSArray> result_array = |
| 6288 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); | 6284 factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length); |
| 6289 return Utils::ToLocal(result_array); | 6285 return Utils::ToLocal(result_array); |
| 6290 } | 6286 } |
| 6291 | 6287 |
| 6292 | 6288 |
| 6293 MaybeLocal<Map> Map::FromArray(Local<Context> context, Local<Array> array) { | 6289 MaybeLocal<Map> Map::FromArray(Local<Context> context, Local<Array> array) { |
| 6294 PREPARE_FOR_EXECUTION(context, "Map::FromArray", Map); | 6290 PREPARE_FOR_EXECUTION(context, "Map::FromArray", Map); |
| 6295 i::Handle<i::Object> result; | 6291 i::Handle<i::Object> result; |
| (...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8362 Address callback_address = | 8358 Address callback_address = |
| 8363 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8359 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8364 VMState<EXTERNAL> state(isolate); | 8360 VMState<EXTERNAL> state(isolate); |
| 8365 ExternalCallbackScope call_scope(isolate, callback_address); | 8361 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8366 callback(info); | 8362 callback(info); |
| 8367 } | 8363 } |
| 8368 | 8364 |
| 8369 | 8365 |
| 8370 } // namespace internal | 8366 } // namespace internal |
| 8371 } // namespace v8 | 8367 } // namespace v8 |
| OLD | NEW |