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

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

Issue 1148383007: Add {Map,Set}::AsArray to the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased 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 | « src/api.cc ('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 21098 matching lines...) Expand 10 before | Expand all | Expand 10 after
21109 21109
21110 v8::Local<v8::Map> map = v8::Map::New(isolate); 21110 v8::Local<v8::Map> map = v8::Map::New(isolate);
21111 CHECK(map->IsObject()); 21111 CHECK(map->IsObject());
21112 CHECK(map->IsMap()); 21112 CHECK(map->IsMap());
21113 CHECK_EQ(0, map->Size()); 21113 CHECK_EQ(0, map->Size());
21114 21114
21115 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); 21115 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])");
21116 CHECK(val->IsMap()); 21116 CHECK(val->IsMap());
21117 map = v8::Local<v8::Map>::Cast(val); 21117 map = v8::Local<v8::Map>::Cast(val);
21118 CHECK_EQ(2, map->Size()); 21118 CHECK_EQ(2, map->Size());
21119
21120 v8::Local<v8::Array> entries = map->AsArray();
21121 CHECK_EQ(2, entries->Length());
21122 v8::Local<v8::Array> entry = entries->Get(0).As<v8::Array>();
21123 CHECK_EQ(2, entry->Length());
21124 CHECK_EQ(1, entry->Get(0).As<v8::Int32>()->Value());
21125 CHECK_EQ(2, entry->Get(1).As<v8::Int32>()->Value());
21126 entry = entries->Get(1).As<v8::Array>();
21127 CHECK_EQ(2, entry->Length());
21128 CHECK_EQ(3, entry->Get(0).As<v8::Int32>()->Value());
21129 CHECK_EQ(4, entry->Get(1).As<v8::Int32>()->Value());
21119 } 21130 }
21120 21131
21121 21132
21122 TEST(Set) { 21133 TEST(Set) {
21123 v8::Isolate* isolate = CcTest::isolate(); 21134 v8::Isolate* isolate = CcTest::isolate();
21124 v8::HandleScope handle_scope(isolate); 21135 v8::HandleScope handle_scope(isolate);
21125 LocalContext env; 21136 LocalContext env;
21126 21137
21127 v8::Local<v8::Set> set = v8::Set::New(isolate); 21138 v8::Local<v8::Set> set = v8::Set::New(isolate);
21128 CHECK(set->IsObject()); 21139 CHECK(set->IsObject());
21129 CHECK(set->IsSet()); 21140 CHECK(set->IsSet());
21130 CHECK_EQ(0, set->Size()); 21141 CHECK_EQ(0, set->Size());
21131 21142
21132 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); 21143 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])");
21133 CHECK(val->IsSet()); 21144 CHECK(val->IsSet());
21134 set = v8::Local<v8::Set>::Cast(val); 21145 set = v8::Local<v8::Set>::Cast(val);
21135 CHECK_EQ(2, set->Size()); 21146 CHECK_EQ(2, set->Size());
21147
21148 v8::Local<v8::Array> keys = set->AsArray();
21149 CHECK_EQ(2, keys->Length());
21150 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value());
21151 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value());
21136 } 21152 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698