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

Side by Side Diff: src/api.cc

Issue 1204623002: Expose Map/Set methods through the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/bootstrapper.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 6241 matching lines...) Expand 10 before | Expand all | Expand 10 after
6252 return Utils::ToLocal(obj); 6252 return Utils::ToLocal(obj);
6253 } 6253 }
6254 6254
6255 6255
6256 size_t v8::Map::Size() const { 6256 size_t v8::Map::Size() const {
6257 i::Handle<i::JSMap> obj = Utils::OpenHandle(this); 6257 i::Handle<i::JSMap> obj = Utils::OpenHandle(this);
6258 return i::OrderedHashMap::cast(obj->table())->NumberOfElements(); 6258 return i::OrderedHashMap::cast(obj->table())->NumberOfElements();
6259 } 6259 }
6260 6260
6261 6261
6262 void Map::Clear() {
6263 auto self = Utils::OpenHandle(this);
6264 i::Isolate* isolate = self->GetIsolate();
6265 LOG_API(isolate, "Map::Clear");
6266 ENTER_V8(isolate);
6267 i::Runtime::JSMapClear(isolate, self);
6268 }
6269
6270
6271 MaybeLocal<Value> Map::Get(Local<Context> context, Local<Value> key) {
6272 PREPARE_FOR_EXECUTION(context, "Map::Get", Value);
6273 auto self = Utils::OpenHandle(this);
6274 Local<Value> result;
6275 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
6276 has_pending_exception =
6277 !ToLocal<Value>(i::Execution::Call(isolate, isolate->map_get(), self,
6278 arraysize(argv), argv, false),
6279 &result);
6280 RETURN_ON_FAILED_EXECUTION(Value);
6281 RETURN_ESCAPED(result);
6282 }
6283
6284
6285 MaybeLocal<Map> Map::Set(Local<Context> context, Local<Value> key,
6286 Local<Value> value) {
6287 PREPARE_FOR_EXECUTION(context, "Map::Set", Map);
6288 auto self = Utils::OpenHandle(this);
6289 i::Handle<i::Object> result;
6290 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
6291 Utils::OpenHandle(*value)};
6292 has_pending_exception =
6293 !i::Execution::Call(isolate, isolate->map_set(), self, arraysize(argv),
6294 argv, false).ToHandle(&result);
6295 RETURN_ON_FAILED_EXECUTION(Map);
6296 RETURN_ESCAPED(Local<Map>::Cast(Utils::ToLocal(result)));
6297 }
6298
6299
6300 Maybe<bool> Map::Has(Local<Context> context, Local<Value> key) {
6301 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Map::Has", bool);
6302 auto self = Utils::OpenHandle(this);
6303 i::Handle<i::Object> result;
6304 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
6305 has_pending_exception =
6306 !i::Execution::Call(isolate, isolate->map_has(), self, arraysize(argv),
6307 argv, false).ToHandle(&result);
6308 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
6309 return Just(result->IsTrue());
6310 }
6311
6312
6313 Maybe<bool> Map::Delete(Local<Context> context, Local<Value> key) {
6314 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Map::Delete", bool);
6315 auto self = Utils::OpenHandle(this);
6316 i::Handle<i::Object> result;
6317 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
6318 has_pending_exception =
6319 !i::Execution::Call(isolate, isolate->map_delete(), self, arraysize(argv),
6320 argv, false).ToHandle(&result);
6321 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
6322 return Just(result->IsTrue());
6323 }
6324
6325
6262 Local<Array> Map::AsArray() const { 6326 Local<Array> Map::AsArray() const {
6263 i::Handle<i::JSMap> obj = Utils::OpenHandle(this); 6327 i::Handle<i::JSMap> obj = Utils::OpenHandle(this);
6264 i::Isolate* isolate = obj->GetIsolate(); 6328 i::Isolate* isolate = obj->GetIsolate();
6265 i::Factory* factory = isolate->factory(); 6329 i::Factory* factory = isolate->factory();
6266 LOG_API(isolate, "Map::AsArray"); 6330 LOG_API(isolate, "Map::AsArray");
6267 ENTER_V8(isolate); 6331 ENTER_V8(isolate);
6268 i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table())); 6332 i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table()));
6269 int size = table->NumberOfElements(); 6333 int size = table->NumberOfElements();
6270 int length = size * 2; 6334 int length = size * 2;
6271 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); 6335 i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
6304 return Utils::ToLocal(obj); 6368 return Utils::ToLocal(obj);
6305 } 6369 }
6306 6370
6307 6371
6308 size_t v8::Set::Size() const { 6372 size_t v8::Set::Size() const {
6309 i::Handle<i::JSSet> obj = Utils::OpenHandle(this); 6373 i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
6310 return i::OrderedHashSet::cast(obj->table())->NumberOfElements(); 6374 return i::OrderedHashSet::cast(obj->table())->NumberOfElements();
6311 } 6375 }
6312 6376
6313 6377
6378 void Set::Clear() {
6379 auto self = Utils::OpenHandle(this);
6380 i::Isolate* isolate = self->GetIsolate();
6381 LOG_API(isolate, "Set::Clear");
6382 ENTER_V8(isolate);
6383 i::Runtime::JSSetClear(isolate, self);
6384 }
6385
6386
6387 MaybeLocal<Set> Set::Add(Local<Context> context, Local<Value> key) {
6388 PREPARE_FOR_EXECUTION(context, "Set::Add", Set);
6389 auto self = Utils::OpenHandle(this);
6390 i::Handle<i::Object> result;
6391 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
6392 has_pending_exception =
6393 !i::Execution::Call(isolate, isolate->set_add(), self, arraysize(argv),
6394 argv, false).ToHandle(&result);
6395 RETURN_ON_FAILED_EXECUTION(Set);
6396 RETURN_ESCAPED(Local<Set>::Cast(Utils::ToLocal(result)));
6397 }
6398
6399
6400 Maybe<bool> Set::Has(Local<Context> context, Local<Value> key) {
6401 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Set::Has", bool);
6402 auto self = Utils::OpenHandle(this);
6403 i::Handle<i::Object> result;
6404 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
6405 has_pending_exception =
6406 !i::Execution::Call(isolate, isolate->set_has(), self, arraysize(argv),
6407 argv, false).ToHandle(&result);
6408 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
6409 return Just(result->IsTrue());
6410 }
6411
6412
6413 Maybe<bool> Set::Delete(Local<Context> context, Local<Value> key) {
6414 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Set::Delete", bool);
6415 auto self = Utils::OpenHandle(this);
6416 i::Handle<i::Object> result;
6417 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
6418 has_pending_exception =
6419 !i::Execution::Call(isolate, isolate->set_delete(), self, arraysize(argv),
6420 argv, false).ToHandle(&result);
6421 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
6422 return Just(result->IsTrue());
6423 }
6424
6425
6314 Local<Array> Set::AsArray() const { 6426 Local<Array> Set::AsArray() const {
6315 i::Handle<i::JSSet> obj = Utils::OpenHandle(this); 6427 i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
6316 i::Isolate* isolate = obj->GetIsolate(); 6428 i::Isolate* isolate = obj->GetIsolate();
6317 i::Factory* factory = isolate->factory(); 6429 i::Factory* factory = isolate->factory();
6318 LOG_API(isolate, "Set::AsArray"); 6430 LOG_API(isolate, "Set::AsArray");
6319 ENTER_V8(isolate); 6431 ENTER_V8(isolate);
6320 i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(obj->table())); 6432 i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(obj->table()));
6321 int length = table->NumberOfElements(); 6433 int length = table->NumberOfElements();
6322 i::Handle<i::FixedArray> result = factory->NewFixedArray(length); 6434 i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
6323 for (int i = 0; i < length; ++i) { 6435 for (int i = 0; i < length; ++i) {
(...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after
8396 Address callback_address = 8508 Address callback_address =
8397 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8509 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8398 VMState<EXTERNAL> state(isolate); 8510 VMState<EXTERNAL> state(isolate);
8399 ExternalCallbackScope call_scope(isolate, callback_address); 8511 ExternalCallbackScope call_scope(isolate, callback_address);
8400 callback(info); 8512 callback(info);
8401 } 8513 }
8402 8514
8403 8515
8404 } // namespace internal 8516 } // namespace internal
8405 } // namespace v8 8517 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698