%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/iterator-from.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 iterator { macro NewJSValidIteratorWrapper( implicit context: Context)( underlying: IteratorRecord): JSValidIteratorWrapper { return new JSValidIteratorWrapper{ map: *NativeContextSlot(ContextSlot::VALID_ITERATOR_WRAPPER_MAP_INDEX), properties_or_hash: kEmptyFixedArray, elements: kEmptyFixedArray, underlying: underlying }; } // https://tc39.es/proposal-iterator-helpers/#sec-getiteratorflattenable transitioning macro GetIteratorFlattenable( implicit context: Context)(obj: JSReceiver|String): IteratorRecord { // 1. If obj is not an Object, then // a. If stringHandling is reject-strings or obj is not a String, throw a // TypeError exception. // (Done by caller.) let iterator: JSAny; try { // 2. Let method be ? GetMethod(obj, @@iterator). const method = GetMethod(obj, IteratorSymbolConstant()) otherwise IfNullOrUndefined; // 4. Else (method is not undefined), // a. Let iterator be ? Call(method, obj). iterator = Call(context, method, obj); } label IfNullOrUndefined { // 3. If method is undefined, then // a. Let iterator be obj. iterator = obj; } // 5. If iterator is not an Object, throw a TypeError exception. const iteratorObj = Cast<JSReceiver>(iterator) otherwise ThrowTypeError(MessageTemplate::kNotIterable, obj); // 6. Return ? GetIteratorDirect(iterator). return GetIteratorDirect(iteratorObj); } // https://tc39.es/proposal-iterator-helpers/#sec-iterator.from transitioning javascript builtin IteratorFrom( js-implicit context: NativeContext, receiver: JSAny)( objArg: JSAny): JSReceiver { // GetIteratorFlattenable below accepts either Objects or Strings (without // wrapping) with the iterate-strings parameter. The type checking is done by // the caller of GetIteratorFlattenable. let obj: JSReceiver|String; typeswitch (objArg) { case (o: String): { obj = o; } case (o: JSReceiver): { obj = o; } case (JSAny): { ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'Iterator.from'); } } // 1. Let iteratorRecord be ? GetIteratorFlattenable(O, iterate-strings). const iteratorRecord = GetIteratorFlattenable(obj); // 2. Let hasInstance be ? OrdinaryHasInstance(%Iterator%, // iteratorRecord.[[Iterator]]). const hasInstance = function::OrdinaryHasInstance( context, GetIteratorFunction(), iteratorRecord.object); // 3. If hasInstance is true, then if (hasInstance == True) { // a. Return iteratorRecord.[[Iterator]]. return iteratorRecord.object; } // 4. Let wrapper be OrdinaryObjectCreate(%WrapForValidIteratorPrototype%, « // [[Iterated]] »). // 5. Set wrapper.[[Iterated]] to iteratorRecord. // 6. Return wrapper. return NewJSValidIteratorWrapper(iteratorRecord); } // https://tc39.es/proposal-iterator-helpers/#sec-wrapforvaliditeratorprototype.next transitioning javascript builtin WrapForValidIteratorPrototypeNext( js-implicit context: NativeContext, receiver: JSAny)(): JSAny { // 1. Let O be this value. // 2. Perform ? RequireInternalSlot(O, [[Iterated]]). const o = Cast<JSValidIteratorWrapper>(receiver) otherwise ThrowTypeError( MessageTemplate::kIncompatibleMethodReceiver, '%WrapForValidIteratorPrototype%.next', receiver); // 3. Let iteratorRecord be O.[[Iterated]]. const iteratorRecord = o.underlying; // 4. Return ? Call(iteratorRecord.[[NextMethod]], // iteratorRecord.[[Iterator]]). return Call(context, iteratorRecord.next, iteratorRecord.object); } // https://tc39.es/proposal-iterator-helpers/#sec-wrapforvaliditeratorprototype.return transitioning javascript builtin WrapForValidIteratorPrototypeReturn( js-implicit context: NativeContext, receiver: JSAny)(): JSAny { try { // 1. Let O be this value. // 2. Perform ? RequireInternalSlot(O, [[Iterated]]). const o = Cast<JSValidIteratorWrapper>(receiver) otherwise ThrowTypeError( MessageTemplate::kIncompatibleMethodReceiver, '%WrapForValidIteratorPrototype%.return', receiver); // 3. Let iterator be O.[[Iterated]].[[Iterator]]. const iterator = o.underlying.object; // 4. Assert: iterator is an Object. // 5. Let returnMethod be ? GetMethod(iterator, "return"). const returnMethod = GetMethod(iterator, kReturnString) otherwise ReturnMethodUndefined; // 7. Return ? Call(returnMethod, iterator). return Call(context, returnMethod, iterator); } label ReturnMethodUndefined { // 6. If returnMethod is undefined, then // a. Return CreateIterResultObject(undefined, true). return AllocateJSIteratorResult(Undefined, True); } } } // namespace iterator