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

Side by Side Diff: src/api.cc

Issue 1157843006: Flatten the Arrays returned and consumed by the v8::Map API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Reject FromArray args with odd lengths Created 5 years, 6 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 | « include/v8.h ('k') | src/collection.js » ('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 6254 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
jochen (gone - plz use gerrit) 2015/06/03 10:44:51 can this overflow?
adamk 2015/06/03 15:35:30 NumberOfElements is stored in a Smi and is guarant
Jakob Kummerow 2015/06/05 15:05:47 Uhm... I don't follow this reasoning. On 64-bit pl
adamk 2015/06/05 17:42:20 Sorry, my reason was indeed bogus (I must have bee
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);
6291 if (array->Length() % 2 != 0) {
6292 return MaybeLocal<Map>();
6293 }
6295 i::Handle<i::Object> result; 6294 i::Handle<i::Object> result;
6296 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*array)}; 6295 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*array)};
6297 has_pending_exception = 6296 has_pending_exception =
6298 !i::Execution::Call(isolate, isolate->map_from_array(), 6297 !i::Execution::Call(isolate, isolate->map_from_array(),
6299 isolate->factory()->undefined_value(), 6298 isolate->factory()->undefined_value(),
6300 arraysize(argv), argv, false).ToHandle(&result); 6299 arraysize(argv), argv, false).ToHandle(&result);
6301 RETURN_ON_FAILED_EXECUTION(Map); 6300 RETURN_ON_FAILED_EXECUTION(Map);
6302 RETURN_ESCAPED(Local<Map>::Cast(Utils::ToLocal(result))); 6301 RETURN_ESCAPED(Local<Map>::Cast(Utils::ToLocal(result)));
6303 } 6302 }
6304 6303
(...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after
8362 Address callback_address = 8361 Address callback_address =
8363 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8362 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8364 VMState<EXTERNAL> state(isolate); 8363 VMState<EXTERNAL> state(isolate);
8365 ExternalCallbackScope call_scope(isolate, callback_address); 8364 ExternalCallbackScope call_scope(isolate, callback_address);
8366 callback(info); 8365 callback(info);
8367 } 8366 }
8368 8367
8369 8368
8370 } // namespace internal 8369 } // namespace internal
8371 } // namespace v8 8370 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/collection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698