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

Side by Side Diff: test/cctest/test-api.cc

Issue 1155893003: Add {Map,Set}::FromArray to the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« src/collection.js ('K') | « src/contexts.h ('k') | no next file » | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21133 matching lines...) Expand 10 before | Expand all | Expand 10 after
21144 v8::Local<v8::Array> entries = map->AsArray(); 21144 v8::Local<v8::Array> entries = map->AsArray();
21145 CHECK_EQ(2, entries->Length()); 21145 CHECK_EQ(2, entries->Length());
21146 v8::Local<v8::Array> entry = entries->Get(0).As<v8::Array>(); 21146 v8::Local<v8::Array> entry = entries->Get(0).As<v8::Array>();
21147 CHECK_EQ(2, entry->Length()); 21147 CHECK_EQ(2, entry->Length());
21148 CHECK_EQ(1, entry->Get(0).As<v8::Int32>()->Value()); 21148 CHECK_EQ(1, entry->Get(0).As<v8::Int32>()->Value());
21149 CHECK_EQ(2, entry->Get(1).As<v8::Int32>()->Value()); 21149 CHECK_EQ(2, entry->Get(1).As<v8::Int32>()->Value());
21150 entry = entries->Get(1).As<v8::Array>(); 21150 entry = entries->Get(1).As<v8::Array>();
21151 CHECK_EQ(2, entry->Length()); 21151 CHECK_EQ(2, entry->Length());
21152 CHECK_EQ(3, entry->Get(0).As<v8::Int32>()->Value()); 21152 CHECK_EQ(3, entry->Get(0).As<v8::Int32>()->Value());
21153 CHECK_EQ(4, entry->Get(1).As<v8::Int32>()->Value()); 21153 CHECK_EQ(4, entry->Get(1).As<v8::Int32>()->Value());
21154
21155 map = v8::Map::FromArray(env.local(), entries).ToLocalChecked();
21156 CHECK_EQ(2, map->Size());
21154 } 21157 }
21155 21158
21156 21159
21157 TEST(Set) { 21160 TEST(Set) {
21158 v8::Isolate* isolate = CcTest::isolate(); 21161 v8::Isolate* isolate = CcTest::isolate();
21159 v8::HandleScope handle_scope(isolate); 21162 v8::HandleScope handle_scope(isolate);
21160 LocalContext env; 21163 LocalContext env;
21161 21164
21162 v8::Local<v8::Set> set = v8::Set::New(isolate); 21165 v8::Local<v8::Set> set = v8::Set::New(isolate);
21163 CHECK(set->IsObject()); 21166 CHECK(set->IsObject());
21164 CHECK(set->IsSet()); 21167 CHECK(set->IsSet());
21165 CHECK_EQ(0, set->Size()); 21168 CHECK_EQ(0, set->Size());
21166 21169
21167 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); 21170 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])");
21168 CHECK(val->IsSet()); 21171 CHECK(val->IsSet());
21169 set = v8::Local<v8::Set>::Cast(val); 21172 set = v8::Local<v8::Set>::Cast(val);
21170 CHECK_EQ(2, set->Size()); 21173 CHECK_EQ(2, set->Size());
21171 21174
21172 v8::Local<v8::Array> keys = set->AsArray(); 21175 v8::Local<v8::Array> keys = set->AsArray();
21173 CHECK_EQ(2, keys->Length()); 21176 CHECK_EQ(2, keys->Length());
21174 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); 21177 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value());
21175 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); 21178 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value());
21179
21180 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked();
21181 CHECK_EQ(2, set->Size());
21176 } 21182 }
OLDNEW
« src/collection.js ('K') | « src/contexts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698