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

Unified Diff: test/cctest/test-api.cc

Issue 1952093002: fix Set::AsArray to not leave undefined holes in output array (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a6d1de705aca385323251e0d3fd46f70fda25dde..fc36ca1c650a90b1ac664b4ea59e9e9603e87d36 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -24631,6 +24631,32 @@ TEST(Set) {
CHECK_EQ(0U, set->Size());
}
+TEST(SetDeleteThenAsArray) {
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4946
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope handle_scope(isolate);
+ LocalContext env;
+
+ // make an array
+ v8::Local<v8::Value> val = CompileRun("new Set([1, 2, 3])");
+ v8::Local<v8::Set> set = v8::Local<v8::Set>::Cast(val);
+ CHECK_EQ(3U, set->Size());
+
+ // delete the "middle" element (using AsArray to
+ // determine which element is the "middle" element)
+ v8::Local<v8::Array> array1 = set->AsArray();
+ CHECK_EQ(3U, array1->Length());
+ CHECK(set->Delete(env.local(), array1->Get(env.local(), 1).ToLocalChecked())
+ .FromJust());
+
+ // make sure there are no undefined values when we convert to an array again.
+ v8::Local<v8::Array> array2 = set->AsArray();
+ uint32_t length = array2->Length();
+ CHECK_EQ(2U, length);
+ for (uint32_t i = 0; i < length; i++) {
+ CHECK(!array2->Get(env.local(), i).ToLocalChecked()->IsUndefined());
+ }
+}
TEST(CompatibleReceiverCheckOnCachedICHandler) {
v8::Isolate* isolate = CcTest::isolate();
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698