%PDF- %PDF-
Direktori : /home/vacivi36/vittasync.vacivitta.com.br/vittasync/node/deps/v8/src/builtins/ |
Current File : /home/vacivi36/vittasync.vacivitta.com.br/vittasync/node/deps/v8/src/builtins/set-union.tq |
// Copyright 2023 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. namespace collections { // https://tc39.es/proposal-set-methods/#sec-set.prototype.union transitioning javascript builtin SetPrototypeUnion( js-implicit context: NativeContext, receiver: JSAny)(other: JSAny): JSSet { const methodName: constexpr string = 'Set.prototype.union'; const fastIteratorResultMap = GetIteratorResultMap(); // 1. Let O be the this value. // 2. Perform ? RequireInternalSlot(O, [[SetData]]). const o = Cast<JSSet>(receiver) otherwise ThrowTypeError( MessageTemplate::kIncompatibleMethodReceiver, methodName, receiver); // 3. Let otherRec be ? GetSetRecord(other). let otherRec = GetSetRecord(other, methodName); const table = Cast<OrderedHashSet>(o.table) otherwise unreachable; // 5. Let resultSetData be a copy of O.[[SetData]]. let resultSetData = Cast<OrderedHashSet>(CloneFixedArray( table, ExtractFixedArrayFlag::kFixedArrays)) otherwise unreachable; try { typeswitch (other) { case (otherSet: JSSetWithNoCustomIteration): { CheckSetRecordHasJSSetMethods(otherRec) otherwise SlowPath; const otherTable = Cast<OrderedHashSet>(otherSet.table) otherwise unreachable; let otherIterator = collections::NewUnmodifiedOrderedHashSetIterator(otherTable); while (true) { const nextValue = otherIterator.Next() otherwise Done; resultSetData = AddToSetTable(resultSetData, nextValue, methodName); } } case (otherMap: JSMapWithNoCustomIteration): { CheckSetRecordHasJSMapMethods(otherRec) otherwise SlowPath; const otherTable = Cast<OrderedHashMap>(otherMap.table) otherwise unreachable; let otherIterator = collections::NewUnmodifiedOrderedHashMapIterator(otherTable); while (true) { const nextValue = otherIterator.Next() otherwise Done; resultSetData = AddToSetTable(resultSetData, nextValue.key, methodName); } } case (JSAny): { goto SlowPath; } } } label SlowPath { // 4. Let keysIter be ? GetKeysIterator(otherRec). let keysIter = GetKeysIterator(otherRec.object, UnsafeCast<Callable>(otherRec.keys)); // 6. Let next be true. let nextRecord: JSReceiver; // 7. Repeat, while next is not false, while (true) { // a. Set next to ? IteratorStep(keysIter). nextRecord = iterator::IteratorStep(keysIter, fastIteratorResultMap) otherwise Done; // b. If next is not false, then // i. Let nextValue be ? IteratorValue(next). const nextValue = iterator::IteratorValue(nextRecord, fastIteratorResultMap); // ii. If nextValue is -0𝔽, set nextValue to +0𝔽. // iii. If SetDataHas(resultSetData, nextValue) is false, then // 1. Append nextValue to resultSetData. resultSetData = AddToSetTable(resultSetData, nextValue, methodName); } } label Done { // 8. Let result be // OrdinaryObjectCreate(%Set.prototype%, « [[SetData]]»). // 9. Set result.[[SetData]] to resultSetData. // 10. Return result. return new JSSet{ map: *NativeContextSlot(ContextSlot::JS_SET_MAP_INDEX), properties_or_hash: kEmptyFixedArray, elements: kEmptyFixedArray, table: resultSetData }; } unreachable; } }