GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — deps: cherry-pick 88f8fe1 from upstream V8 · nodejs/node@0afcb9a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • common.gypi
  • deps/v8
    • src
      • api.cc
    • test/cctest
      • test-api.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Reset this number to 0 on major V8 upgrades.
3232
# Increment by one for each non-official patch applied to deps/v8.
33-
'v8_embedder_string': '-node.12',
33+
'v8_embedder_string': '-node.13',
3434

3535
# Enable disassembler for `--print-code` v8 options
3636
'v8_enable_disassembler': 1,
Collapse file

‎deps/v8/src/api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/api.cc
+27-25Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7103,30 +7103,30 @@ i::Handle<i::JSArray> MapAsArray(i::Isolate* isolate, i::Object* table_obj,
71037103
i::Factory* factory = isolate->factory();
71047104
i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(table_obj),
71057105
isolate);
7106-
if (offset >= table->NumberOfElements()) return factory->NewJSArray(0);
7107-
int length = (table->NumberOfElements() - offset) *
7108-
(kind == MapAsArrayKind::kEntries ? 2 : 1);
7109-
i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
7106+
const bool collect_keys =
7107+
kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys;
7108+
const bool collect_values =
7109+
kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues;
7110+
int capacity = table->UsedCapacity();
7111+
int max_length =
7112+
(capacity - offset) * ((collect_keys && collect_values) ? 2 : 1);
7113+
i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length);
71107114
int result_index = 0;
71117115
{
71127116
i::DisallowHeapAllocation no_gc;
7113-
int capacity = table->UsedCapacity();
71147117
i::Oddball* the_hole = i::ReadOnlyRoots(isolate).the_hole_value();
7115-
for (int i = 0; i < capacity; ++i) {
7118+
for (int i = offset; i < capacity; ++i) {
71167119
i::Object* key = table->KeyAt(i);
71177120
if (key == the_hole) continue;
7118-
if (offset-- > 0) continue;
7119-
if (kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys) {
7120-
result->set(result_index++, key);
7121-
}
7122-
if (kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues) {
7123-
result->set(result_index++, table->ValueAt(i));
7124-
}
7121+
if (collect_keys) result->set(result_index++, key);
7122+
if (collect_values) result->set(result_index++, table->ValueAt(i));
71257123
}
71267124
}
7127-
DCHECK_EQ(result_index, result->length());
7128-
DCHECK_EQ(result_index, length);
7129-
return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, length);
7125+
DCHECK_GE(max_length, result_index);
7126+
if (result_index == 0) return factory->NewJSArray(0);
7127+
result->Shrink(isolate, result_index);
7128+
return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
7129+
result_index);
71307130
}
71317131

71327132
} // namespace
@@ -7211,24 +7211,26 @@ i::Handle<i::JSArray> SetAsArray(i::Isolate* isolate, i::Object* table_obj,
72117211
i::Factory* factory = isolate->factory();
72127212
i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(table_obj),
72137213
isolate);
7214-
int length = table->NumberOfElements() - offset;
7215-
if (length <= 0) return factory->NewJSArray(0);
7216-
i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
7214+
// Elements skipped by |offset| may already be deleted.
7215+
int capacity = table->UsedCapacity();
7216+
int max_length = capacity - offset;
7217+
if (max_length == 0) return factory->NewJSArray(0);
7218+
i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length);
72177219
int result_index = 0;
72187220
{
72197221
i::DisallowHeapAllocation no_gc;
7220-
int capacity = table->UsedCapacity();
72217222
i::Oddball* the_hole = i::ReadOnlyRoots(isolate).the_hole_value();
7222-
for (int i = 0; i < capacity; ++i) {
7223+
for (int i = offset; i < capacity; ++i) {
72237224
i::Object* key = table->KeyAt(i);
72247225
if (key == the_hole) continue;
7225-
if (offset-- > 0) continue;
72267226
result->set(result_index++, key);
72277227
}
72287228
}
7229-
DCHECK_EQ(result_index, result->length());
7230-
DCHECK_EQ(result_index, length);
7231-
return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, length);
7229+
DCHECK_GE(max_length, result_index);
7230+
if (result_index == 0) return factory->NewJSArray(0);
7231+
result->Shrink(isolate, result_index);
7232+
return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
7233+
result_index);
72327234
}
72337235
} // namespace
72347236

Collapse file

‎deps/v8/test/cctest/test-api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/test/cctest/test-api.cc
+214Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28777,3 +28777,217 @@ TEST(TestSetWasmThreadsEnabledCallback) {
2877728777
i::FLAG_experimental_wasm_threads = false;
2877828778
CHECK(i_isolate->AreWasmThreadsEnabled(i_context));
2877928779
}
28780+
28781+
TEST(PreviewSetIteratorEntriesWithDeleted) {
28782+
LocalContext env;
28783+
v8::HandleScope handle_scope(env->GetIsolate());
28784+
v8::Local<v8::Context> context = env.local();
28785+
28786+
{
28787+
// Create set, delete entry, create iterator, preview.
28788+
v8::Local<v8::Object> iterator =
28789+
CompileRun("var set = new Set([1,2,3]); set.delete(1); set.keys()")
28790+
->ToObject(context)
28791+
.ToLocalChecked();
28792+
bool is_key;
28793+
v8::Local<v8::Array> entries =
28794+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28795+
CHECK(!is_key);
28796+
CHECK_EQ(2, entries->Length());
28797+
CHECK_EQ(2, entries->Get(context, 0)
28798+
.ToLocalChecked()
28799+
->Int32Value(context)
28800+
.FromJust());
28801+
CHECK_EQ(3, entries->Get(context, 1)
28802+
.ToLocalChecked()
28803+
->Int32Value(context)
28804+
.FromJust());
28805+
}
28806+
{
28807+
// Create set, create iterator, delete entry, preview.
28808+
v8::Local<v8::Object> iterator =
28809+
CompileRun("var set = new Set([1,2,3]); set.keys()")
28810+
->ToObject(context)
28811+
.ToLocalChecked();
28812+
CompileRun("set.delete(1);");
28813+
bool is_key;
28814+
v8::Local<v8::Array> entries =
28815+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28816+
CHECK(!is_key);
28817+
CHECK_EQ(2, entries->Length());
28818+
CHECK_EQ(2, entries->Get(context, 0)
28819+
.ToLocalChecked()
28820+
->Int32Value(context)
28821+
.FromJust());
28822+
CHECK_EQ(3, entries->Get(context, 1)
28823+
.ToLocalChecked()
28824+
->Int32Value(context)
28825+
.FromJust());
28826+
}
28827+
{
28828+
// Create set, create iterator, delete entry, iterate, preview.
28829+
v8::Local<v8::Object> iterator =
28830+
CompileRun("var set = new Set([1,2,3]); var it = set.keys(); it")
28831+
->ToObject(context)
28832+
.ToLocalChecked();
28833+
CompileRun("set.delete(1); it.next();");
28834+
bool is_key;
28835+
v8::Local<v8::Array> entries =
28836+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28837+
CHECK(!is_key);
28838+
CHECK_EQ(1, entries->Length());
28839+
CHECK_EQ(3, entries->Get(context, 0)
28840+
.ToLocalChecked()
28841+
->Int32Value(context)
28842+
.FromJust());
28843+
}
28844+
{
28845+
// Create set, create iterator, delete entry, iterate until empty, preview.
28846+
v8::Local<v8::Object> iterator =
28847+
CompileRun("var set = new Set([1,2,3]); var it = set.keys(); it")
28848+
->ToObject(context)
28849+
.ToLocalChecked();
28850+
CompileRun("set.delete(1); it.next(); it.next();");
28851+
bool is_key;
28852+
v8::Local<v8::Array> entries =
28853+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28854+
CHECK(!is_key);
28855+
CHECK_EQ(0, entries->Length());
28856+
}
28857+
{
28858+
// Create set, create iterator, delete entry, iterate, trigger rehash,
28859+
// preview.
28860+
v8::Local<v8::Object> iterator =
28861+
CompileRun("var set = new Set([1,2,3]); var it = set.keys(); it")
28862+
->ToObject(context)
28863+
.ToLocalChecked();
28864+
CompileRun("set.delete(1); it.next();");
28865+
CompileRun("for (var i = 4; i < 20; i++) set.add(i);");
28866+
bool is_key;
28867+
v8::Local<v8::Array> entries =
28868+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28869+
CHECK(!is_key);
28870+
CHECK_EQ(17, entries->Length());
28871+
for (uint32_t i = 0; i < 17; i++) {
28872+
CHECK_EQ(i + 3, entries->Get(context, i)
28873+
.ToLocalChecked()
28874+
->Int32Value(context)
28875+
.FromJust());
28876+
}
28877+
}
28878+
}
28879+
28880+
TEST(PreviewMapIteratorEntriesWithDeleted) {
28881+
LocalContext env;
28882+
v8::HandleScope handle_scope(env->GetIsolate());
28883+
v8::Local<v8::Context> context = env.local();
28884+
28885+
{
28886+
// Create map, delete entry, create iterator, preview.
28887+
v8::Local<v8::Object> iterator = CompileRun(
28888+
"var map = new Map();"
28889+
"var key = {}; map.set(key, 1);"
28890+
"map.set({}, 2); map.set({}, 3);"
28891+
"map.delete(key);"
28892+
"map.values()")
28893+
->ToObject(context)
28894+
.ToLocalChecked();
28895+
bool is_key;
28896+
v8::Local<v8::Array> entries =
28897+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28898+
CHECK(!is_key);
28899+
CHECK_EQ(2, entries->Length());
28900+
CHECK_EQ(2, entries->Get(context, 0)
28901+
.ToLocalChecked()
28902+
->Int32Value(context)
28903+
.FromJust());
28904+
CHECK_EQ(3, entries->Get(context, 1)
28905+
.ToLocalChecked()
28906+
->Int32Value(context)
28907+
.FromJust());
28908+
}
28909+
{
28910+
// Create map, create iterator, delete entry, preview.
28911+
v8::Local<v8::Object> iterator = CompileRun(
28912+
"var map = new Map();"
28913+
"var key = {}; map.set(key, 1);"
28914+
"map.set({}, 2); map.set({}, 3);"
28915+
"map.values()")
28916+
->ToObject(context)
28917+
.ToLocalChecked();
28918+
CompileRun("map.delete(key);");
28919+
bool is_key;
28920+
v8::Local<v8::Array> entries =
28921+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28922+
CHECK(!is_key);
28923+
CHECK_EQ(2, entries->Length());
28924+
CHECK_EQ(2, entries->Get(context, 0)
28925+
.ToLocalChecked()
28926+
->Int32Value(context)
28927+
.FromJust());
28928+
CHECK_EQ(3, entries->Get(context, 1)
28929+
.ToLocalChecked()
28930+
->Int32Value(context)
28931+
.FromJust());
28932+
}
28933+
{
28934+
// Create map, create iterator, delete entry, iterate, preview.
28935+
v8::Local<v8::Object> iterator = CompileRun(
28936+
"var map = new Map();"
28937+
"var key = {}; map.set(key, 1);"
28938+
"map.set({}, 2); map.set({}, 3);"
28939+
"var it = map.values(); it")
28940+
->ToObject(context)
28941+
.ToLocalChecked();
28942+
CompileRun("map.delete(key); it.next();");
28943+
bool is_key;
28944+
v8::Local<v8::Array> entries =
28945+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28946+
CHECK(!is_key);
28947+
CHECK_EQ(1, entries->Length());
28948+
CHECK_EQ(3, entries->Get(context, 0)
28949+
.ToLocalChecked()
28950+
->Int32Value(context)
28951+
.FromJust());
28952+
}
28953+
{
28954+
// Create map, create iterator, delete entry, iterate until empty, preview.
28955+
v8::Local<v8::Object> iterator = CompileRun(
28956+
"var map = new Map();"
28957+
"var key = {}; map.set(key, 1);"
28958+
"map.set({}, 2); map.set({}, 3);"
28959+
"var it = map.values(); it")
28960+
->ToObject(context)
28961+
.ToLocalChecked();
28962+
CompileRun("map.delete(key); it.next(); it.next();");
28963+
bool is_key;
28964+
v8::Local<v8::Array> entries =
28965+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28966+
CHECK(!is_key);
28967+
CHECK_EQ(0, entries->Length());
28968+
}
28969+
{
28970+
// Create map, create iterator, delete entry, iterate, trigger rehash,
28971+
// preview.
28972+
v8::Local<v8::Object> iterator = CompileRun(
28973+
"var map = new Map();"
28974+
"var key = {}; map.set(key, 1);"
28975+
"map.set({}, 2); map.set({}, 3);"
28976+
"var it = map.values(); it")
28977+
->ToObject(context)
28978+
.ToLocalChecked();
28979+
CompileRun("map.delete(key); it.next();");
28980+
CompileRun("for (var i = 4; i < 20; i++) map.set({}, i);");
28981+
bool is_key;
28982+
v8::Local<v8::Array> entries =
28983+
iterator->PreviewEntries(&is_key).ToLocalChecked();
28984+
CHECK(!is_key);
28985+
CHECK_EQ(17, entries->Length());
28986+
for (uint32_t i = 0; i < 17; i++) {
28987+
CHECK_EQ(i + 3, entries->Get(context, i)
28988+
.ToLocalChecked()
28989+
->Int32Value(context)
28990+
.FromJust());
28991+
}
28992+
}
28993+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.