Chromium Code Reviews| Index: src/builtins/builtins-async-iterator.cc |
| diff --git a/src/builtins/builtins-async-iterator.cc b/src/builtins/builtins-async-iterator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c02cf8cb4e758edbfd6e727ef92afbe7af10b064 |
| --- /dev/null |
| +++ b/src/builtins/builtins-async-iterator.cc |
| @@ -0,0 +1,552 @@ |
| +// Copyright 2016 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. |
| + |
| +#include "src/builtins/builtins-async.h" |
| +#include "src/builtins/builtins-utils.h" |
| +#include "src/builtins/builtins.h" |
| +#include "src/code-factory.h" |
| +#include "src/code-stub-assembler.h" |
| +#include "src/frames-inl.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| +// Describe fields of Context associated with the AsyncIterator unwrap closure. |
| +class ValueUnwrapContext { |
| + public: |
| + enum Fields { kDoneSlot = Context::MIN_CONTEXT_SLOTS, kLength }; |
| +}; |
| + |
| +// https://tc39.github.io/proposal-async-iteration/ |
| +// Section #sec-%asyncfromsynciteratorprototype%.next |
| +TF_BUILTIN(AsyncFromSyncIteratorPrototypeNext, AsyncBuiltinsAssembler) { |
| + const char* method_str = "[Async-from-Sync Iterator].prototype.next"; |
| + Handle<String> method_name = factory()->NewStringFromAsciiChecked(method_str); |
| + |
| + Node* const iterator = Parameter(0); |
| + Node* const value = Parameter(1); |
| + Node* const context = Parameter(4); |
| + |
| + Node* const native_context = LoadNativeContext(context); |
| + Node* const promise = AllocateAndInitJSPromise(context); |
| + |
| + Variable var_parent(this, MachineRepresentation::kTagged); |
| + Variable var_exception(this, MachineRepresentation::kTagged); |
| + var_exception.Bind(UndefinedConstant()); |
| + Label reject_promise(this, Label::kDeferred); |
| + Label if_receiverisincompatible(this, Label::kDeferred); |
| + |
| + GotoIf(TaggedIsSmi(iterator), &if_receiverisincompatible); |
| + GotoUnless(HasInstanceType(iterator, JS_ASYNC_FROM_SYNC_ITERATOR_TYPE), |
| + &if_receiverisincompatible); |
| + |
| + Node* const sync_iterator = |
| + LoadObjectField(iterator, JSAsyncFromSyncIterator::kSyncIteratorOffset); |
| + |
| + // Let nextResult be IteratorNext(syncIterator, value). |
| + // IfAbruptRejectPromise(nextResult, promiseCapability). |
| + Node* next_method = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, sync_iterator, |
| + HeapConstant(factory()->next_string())); |
| + Node* const iter_result = CallJS(CodeFactory::Call(isolate()), context, |
| + next_method, sync_iterator, value); |
| + GotoIfException(iter_result, &reject_promise, &var_exception); |
| + |
| + Label if_fastpath(this), if_slowpath(this), merge(this); |
| + GotoIf(TaggedIsSmi(iter_result), &if_slowpath); |
| + |
| + Node* const fast_iter_result_map = |
|
jgruber
2017/01/24 16:48:39
This is used a couple of times in this file, can w
caitp
2017/02/15 22:18:00
I've moved the "Load IteratorResult properties" in
|
| + LoadContextElement(native_context, Context::ITERATOR_RESULT_MAP_INDEX); |
| + Node* const iter_result_map = LoadMap(iter_result); |
| + |
| + Variable var_value(this, MachineRepresentation::kTagged); |
| + Variable var_done(this, MachineRepresentation::kTagged); |
| + Branch(WordEqual(iter_result_map, fast_iter_result_map), &if_fastpath, |
| + &if_slowpath); |
| + |
| + Bind(&if_fastpath); |
| + { |
| + var_value.Bind( |
| + LoadObjectField(iter_result, JSIteratorResult::kValueOffset)); |
| + var_done.Bind(LoadObjectField(iter_result, JSIteratorResult::kDoneOffset)); |
| + Goto(&merge); |
| + } |
| + |
| + Bind(&if_slowpath); |
| + { |
| + Label if_exception(this, Label::kDeferred); |
| + |
| + // Let nextValue be IteratorValue(nextResult). |
| + // IfAbruptRejectPromise(nextValue, promiseCapability). |
| + Node* const value = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, iter_result, |
| + HeapConstant(factory()->value_string())); |
| + GotoIfException(value, &reject_promise, &var_exception); |
| + |
| + // Let nextDone be IteratorComplete(nextResult). |
| + // IfAbruptRejectPromise(nextDone, promiseCapability). |
| + Node* const done = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, iter_result, |
| + HeapConstant(factory()->done_string())); |
| + GotoIfException(done, &reject_promise, &var_exception); |
| + |
| + var_value.Bind(value); |
| + var_done.Bind(done); |
| + Goto(&merge); |
| + } |
| + |
| + Bind(&merge); |
| + |
| + // Convert `done` status to a Boolean value if needed. |
| + Label to_boolean(this, Label::kDeferred), wrap(this); |
| + GotoIf(TaggedIsSmi(var_done.value()), &to_boolean); |
|
jgruber
2017/01/24 16:48:39
Can this ever be needed for the fast path?
caitp
2017/01/24 16:58:36
I'm not sure. Does each ObjectLiteral in source co
caitp
2017/02/15 22:18:00
I'm pretty sure it's safe to trust that the map wi
|
| + Branch(IsBooleanMap(LoadMap(var_done.value())), &wrap, &to_boolean); |
| + |
| + Bind(&to_boolean); |
| + { |
| + var_done.Bind( |
| + CallStub(CodeFactory::ToBoolean(isolate()), context, var_done.value())); |
| + Goto(&wrap); |
| + } |
| + |
| + Bind(&wrap); |
| + { |
| + Node* const value = var_value.value(); |
| + Node* const done = var_done.value(); |
| + |
| + // Let valueWrapperCapability be ! NewPromiseCapability(%Promise%). |
| + Node* const wrapper = AllocateAndInitJSPromise(context); |
| + |
| + // Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, |
| + // « nextValue »). |
| + InternalResolvePromise(context, wrapper, value); |
| + |
| + // Let onFulfilled be a new built-in function object as defined in |
| + // Async Iterator Value Unwrap Functions. |
| + // Set onFulfilled.[[Done]] to nextDone. |
| + Node* const map = LoadContextElement( |
|
jgruber
2017/01/24 16:48:39
Same here, can we extract creation of the closure?
caitp
2017/02/15 22:18:00
Done
|
| + native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); |
| + Node* const on_resolve_shared = LoadContextElement( |
| + native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN); |
| + CSA_ASSERT(this, |
| + HasInstanceType(on_resolve_shared, SHARED_FUNCTION_INFO_TYPE)); |
| + Node* const closure_context = |
| + AllocateAsyncIteratorValueUnwrapContext(native_context, done); |
| + Node* const on_resolve = AllocateFunctionWithMapAndContext( |
| + map, on_resolve_shared, closure_context); |
| + |
| + // Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], |
| + // onFulfilled, undefined, promiseCapability). |
| + Node* const undefined = UndefinedConstant(); |
| + InternalPerformPromiseThen(context, wrapper, on_resolve, undefined, promise, |
| + undefined, undefined); |
| + |
| + // TODO(caitp): Use TailCallStub once it's possible for a JS-linkage builtin |
| + // to tailcall a CS-linkage builtin when an arguments adaptor frame is used. |
| + Return(promise); |
| + } |
| + |
| + Bind(&if_receiverisincompatible); |
| + { |
| + // If Type(O) is not Object, or if O does not have a [[SyncIterator]] |
| + // internal slot, then |
| + |
| + // Let badIteratorError be a new TypeError exception. |
| + Node* const make_type_error = |
| + LoadContextElement(native_context, Context::MAKE_TYPE_ERROR_INDEX); |
|
jgruber
2017/01/24 16:48:39
This is starting to pop up in several places, mayb
caitp
2017/02/15 22:18:00
I've added one to this CL, I don't think it's too
|
| + Node* const error = |
| + CallJS(CodeFactory::Call(isolate()), context, make_type_error, |
| + UndefinedConstant(), |
| + SmiConstant(MessageTemplate::kIncompatibleMethodReceiver), |
| + HeapConstant(method_name), iterator); |
|
jgruber
2017/01/24 16:48:39
Maybe move method_name and method_str into this sc
caitp
2017/02/15 22:18:00
I'm keeping the c-string near the top of the funct
|
| + |
| + // Perform ! Call(promiseCapability.[[Reject]], undefined, |
| + // « badIteratorError »). |
| + var_exception.Bind(error); |
| + Goto(&reject_promise); |
| + } |
| + |
| + Bind(&reject_promise); |
| + { |
| + Node* const promise = AllocateAndInitJSPromise(context); |
| + Node* const exception = var_exception.value(); |
| + InternalPromiseReject(context, promise, exception, TrueConstant()); |
| + |
| + // Return promiseCapability.[[Promise]]. |
| + Return(promise); |
| + } |
| +} |
| + |
| +// https://tc39.github.io/proposal-async-iteration/ |
| +// Section #sec-%asyncfromsynciteratorprototype%.return |
| +TF_BUILTIN(AsyncFromSyncIteratorPrototypeReturn, AsyncBuiltinsAssembler) { |
|
jgruber
2017/01/24 16:48:39
These 3 functions seem to have very similar struct
caitp
2017/02/15 22:18:00
Maybe, I've made them more concise with the helper
|
| + const char* method_str = "[Async-from-Sync Iterator].prototype.return"; |
| + Handle<String> method_name = factory()->NewStringFromAsciiChecked(method_str); |
| + |
| + Node* const iterator = Parameter(0); |
| + Node* const value = Parameter(1); |
| + Node* const context = Parameter(4); |
| + |
| + Node* const native_context = LoadNativeContext(context); |
| + Node* const promise = AllocateAndInitJSPromise(context); |
| + |
| + Variable var_exception(this, MachineRepresentation::kTagged); |
| + var_exception.Bind(UndefinedConstant()); |
| + Label reject_promise(this, Label::kDeferred); |
| + Label if_receiverisincompatible(this, Label::kDeferred); |
| + |
| + GotoIf(TaggedIsSmi(iterator), &if_receiverisincompatible); |
| + GotoUnless(HasInstanceType(iterator, JS_ASYNC_FROM_SYNC_ITERATOR_TYPE), |
| + &if_receiverisincompatible); |
| + |
| + Node* const sync_iterator = |
| + LoadObjectField(iterator, JSAsyncFromSyncIterator::kSyncIteratorOffset); |
| + |
| + // Let return be GetMethod(syncIterator, "return"). |
| + // IfAbruptRejectPromise(return, promiseCapability). |
| + Node* const return_method = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, sync_iterator, |
| + HeapConstant(factory()->return_string())); |
| + GotoIfException(return_method, &reject_promise, &var_exception); |
| + |
| + Variable var_value(this, MachineRepresentation::kTagged); |
| + Variable var_done(this, MachineRepresentation::kTagged); |
| + |
| + Label if_isundefined(this), if_isnotundefined(this), resolve_promise(this); |
| + |
| + Branch(IsUndefined(return_method), &if_isundefined, &if_isnotundefined); |
| + Bind(&if_isundefined); |
| + { |
| + // If return is undefined, then |
| + // Let iterResult be ! CreateIterResultObject(value, true) |
| + Node* const iter_result = |
| + CallStub(CodeFactory::CreateIterResultObject(isolate()), context, value, |
| + TrueConstant()); |
| + |
| + // Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »). |
| + // IfAbruptRejectPromise(nextDone, promiseCapability). |
| + // Return promiseCapability.[[Promise]]. |
| + PromiseFulfill(context, promise, iter_result, v8::Promise::kFulfilled); |
| + Return(promise); |
| + } |
| + |
| + Bind(&if_isnotundefined); |
| + { |
| + // Let returnResult be Call(return, syncIterator, « value »). |
| + Node* const iter_result = CallJS(CodeFactory::Call(isolate()), context, |
| + return_method, sync_iterator, value); |
| + // IfAbruptRejectPromise(returnResult, promiseCapability). |
| + GotoIfException(iter_result, &reject_promise, &var_exception); |
| + Label if_fastpath(this), if_slowpath(this), merge(this); |
| + |
| + GotoIf(TaggedIsSmi(iter_result), &if_slowpath); |
| + |
| + Node* const fast_iter_result_map = |
| + LoadContextElement(native_context, Context::ITERATOR_RESULT_MAP_INDEX); |
| + Node* const iter_result_map = LoadMap(iter_result); |
| + |
| + Branch(WordEqual(iter_result_map, fast_iter_result_map), &if_fastpath, |
| + &if_slowpath); |
| + |
| + Bind(&if_fastpath); |
| + { |
| + var_value.Bind( |
| + LoadObjectField(iter_result, JSIteratorResult::kValueOffset)); |
| + var_done.Bind( |
| + LoadObjectField(iter_result, JSIteratorResult::kDoneOffset)); |
| + Goto(&merge); |
| + } |
| + |
| + Bind(&if_slowpath); |
| + { |
| + // Let returnValue be IteratorValue(nextResult). |
| + // IfAbruptRejectPromise(returnValue, promiseCapability). |
| + Node* const value = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, iter_result, |
| + HeapConstant(factory()->value_string())); |
| + GotoIfException(value, &reject_promise, &var_exception); |
| + |
| + // Let returnDone be IteratorComplete(nextResult). |
| + // IfAbruptRejectPromise(returnDone, promiseCapability). |
| + Node* const done = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, iter_result, |
| + HeapConstant(factory()->done_string())); |
| + GotoIfException(done, &reject_promise, &var_exception); |
| + |
| + var_value.Bind(value); |
| + var_done.Bind(done); |
| + Goto(&merge); |
| + } |
| + |
| + Bind(&merge); |
| + { |
| + Label to_boolean(this), done(this); |
| + GotoIf(TaggedIsSmi(var_done.value()), &to_boolean); |
| + Branch(IsBooleanMap(LoadMap(var_done.value())), &done, &to_boolean); |
| + |
| + Bind(&to_boolean); |
| + { |
| + Node* const result = CallStub(CodeFactory::ToBoolean(isolate()), |
| + context, var_done.value()); |
| + var_done.Bind(result); |
| + Goto(&done); |
| + } |
| + |
| + Bind(&done); |
| + Goto(&resolve_promise); |
| + } |
| + } |
| + |
| + Bind(&resolve_promise); |
| + { |
| + // Let valueWrapperCapability be ! NewPromiseCapability(%Promise%). |
| + Node* const wrapper = AllocateAndInitJSPromise(context); |
| + Node* const value = var_value.value(); |
| + Node* const done = var_done.value(); |
| + |
| + // Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, |
| + // « nextValue »). |
| + InternalResolvePromise(context, wrapper, value); |
| + |
| + // Let onFulfilled be a new built-in function object as defined in |
| + // Async Iterator Value Unwrap Functions. |
| + // Set onFulfilled.[[Done]] to nextDone. |
| + Node* const map = LoadContextElement( |
| + native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); |
| + Node* const on_resolve_shared = LoadContextElement( |
| + native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN); |
| + CSA_ASSERT(this, |
| + HasInstanceType(on_resolve_shared, SHARED_FUNCTION_INFO_TYPE)); |
| + Node* const closure_context = |
| + AllocateAsyncIteratorValueUnwrapContext(native_context, done); |
| + Node* const on_resolve = AllocateFunctionWithMapAndContext( |
| + map, on_resolve_shared, closure_context); |
| + |
| + // Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], |
| + // onFulfilled, undefined, promiseCapability). |
| + Node* const undefined = UndefinedConstant(); |
| + InternalPerformPromiseThen(context, wrapper, on_resolve, undefined, promise, |
| + undefined, undefined); |
| + Return(promise); |
| + } |
| + |
| + Bind(&if_receiverisincompatible); |
| + { |
| + // If Type(O) is not Object, or if O does not have a [[SyncIterator]] |
| + // internal slot, then |
| + |
| + // Let badIteratorError be a new TypeError exception. |
| + Node* const make_type_error = |
| + LoadContextElement(native_context, Context::MAKE_TYPE_ERROR_INDEX); |
| + Node* const error = |
| + CallJS(CodeFactory::Call(isolate()), context, make_type_error, |
| + UndefinedConstant(), |
| + SmiConstant(MessageTemplate::kIncompatibleMethodReceiver), |
| + HeapConstant(method_name), iterator); |
| + |
| + // Perform ! Call(promiseCapability.[[Reject]], undefined, |
| + // « badIteratorError »). |
| + var_exception.Bind(error); |
| + Goto(&reject_promise); |
| + } |
| + |
| + Bind(&reject_promise); |
| + { |
| + Node* const exception = var_exception.value(); |
| + InternalPromiseReject(context, promise, exception, TrueConstant()); |
| + |
| + // Return promiseCapability.[[Promise]]. |
| + Return(promise); |
| + } |
| +} |
| + |
| +// https://tc39.github.io/proposal-async-iteration/ |
| +// Section #sec-%asyncfromsynciteratorprototype%.throw |
| +TF_BUILTIN(AsyncFromSyncIteratorPrototypeThrow, AsyncBuiltinsAssembler) { |
| + const char* method_str = "[Async-from-Sync Iterator].prototype.throw"; |
| + Handle<String> method_name = factory()->NewStringFromAsciiChecked(method_str); |
| + |
| + Node* const iterator = Parameter(0); |
| + Node* const value = Parameter(1); |
| + Node* const context = Parameter(4); |
| + |
| + Node* const native_context = LoadNativeContext(context); |
| + Node* const promise = AllocateAndInitJSPromise(context); |
| + |
| + Variable var_exception(this, MachineRepresentation::kTagged); |
| + var_exception.Bind(value); |
| + Variable var_value(this, MachineRepresentation::kTagged); |
| + Variable var_done(this, MachineRepresentation::kTagged); |
| + Label reject_promise(this, Label::kDeferred); |
| + Label if_receiverisincompatible(this, Label::kDeferred); |
| + |
| + GotoIf(TaggedIsSmi(iterator), &if_receiverisincompatible); |
| + GotoUnless(HasInstanceType(iterator, JS_ASYNC_FROM_SYNC_ITERATOR_TYPE), |
| + &if_receiverisincompatible); |
| + |
| + Node* const sync_iterator = |
| + LoadObjectField(iterator, JSAsyncFromSyncIterator::kSyncIteratorOffset); |
| + |
| + // Let throw be GetMethod(syncIterator, "throw"). |
| + // IfAbruptRejectPromise(nextResult, promiseCapability). |
| + // IfAbruptRejectPromise(throw, promiseCapability). |
| + Node* const throw_method = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, sync_iterator, |
| + HeapConstant(factory()->throw_string())); |
| + GotoIfException(throw_method, &reject_promise, &var_exception); |
| + |
| + Label if_isnotundefined(this), resolve_promise(this); |
| + |
| + // If throw is undefined, then |
| + // Perform ! Call(promiseCapability.[[Reject]], undefined, « value »). |
| + Branch(IsUndefined(throw_method), &reject_promise, &if_isnotundefined); |
| + |
| + Bind(&if_isnotundefined); |
| + { |
| + // Let throwResult be Call(throw, syncIterator, « value »). |
| + Node* const iter_result = CallJS(CodeFactory::Call(isolate()), context, |
| + throw_method, sync_iterator, value); |
| + GotoIfException(iter_result, &reject_promise, &var_exception); |
| + |
| + Label if_fastpath(this), if_slowpath(this), merge(this); |
| + |
| + GotoIf(TaggedIsSmi(iter_result), &if_slowpath); |
| + |
| + Node* const fast_iter_result_map = |
| + LoadContextElement(native_context, Context::ITERATOR_RESULT_MAP_INDEX); |
| + Node* const iter_result_map = LoadMap(iter_result); |
| + |
| + Branch(WordEqual(iter_result_map, fast_iter_result_map), &if_fastpath, |
| + &if_slowpath); |
| + |
| + Bind(&if_fastpath); |
| + { |
| + var_value.Bind( |
| + LoadObjectField(iter_result, JSIteratorResult::kValueOffset)); |
| + var_done.Bind( |
| + LoadObjectField(iter_result, JSIteratorResult::kDoneOffset)); |
| + Goto(&merge); |
| + } |
| + |
| + Bind(&if_slowpath); |
| + { |
| + // Let throwValue be IteratorValue(nextResult). |
| + // IfAbruptRejectPromise(throwValue, promiseCapability). |
| + Node* const value = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, iter_result, |
| + HeapConstant(factory()->value_string())); |
| + GotoIfException(value, &reject_promise, &var_exception); |
| + |
| + // Let throwDone be IteratorComplete(nextResult). |
| + // IfAbruptRejectPromise(throwDone, promiseCapability). |
| + Node* const done = |
| + CallStub(CodeFactory::GetProperty(isolate()), context, iter_result, |
| + HeapConstant(factory()->done_string())); |
| + GotoIfException(done, &reject_promise, &var_exception); |
| + |
| + var_value.Bind(value); |
| + var_done.Bind(done); |
| + Goto(&merge); |
| + } |
| + |
| + Bind(&merge); |
| + |
| + // Convert `done` status to a Boolean value if needed. |
| + Label to_boolean(this, Label::kDeferred), wrap(this); |
| + GotoIf(TaggedIsSmi(var_done.value()), &to_boolean); |
| + Branch(IsBooleanMap(LoadMap(var_done.value())), &wrap, &to_boolean); |
| + |
| + Bind(&to_boolean); |
| + { |
| + var_done.Bind(CallStub(CodeFactory::ToBoolean(isolate()), context, |
| + var_done.value())); |
| + Goto(&wrap); |
| + } |
| + |
| + Bind(&wrap); |
| + { |
| + // Let valueWrapperCapability be ! NewPromiseCapability(%Promise%). |
| + Node* const wrapper = AllocateAndInitJSPromise(context); |
| + Node* const value = var_value.value(); |
| + Node* const done = var_done.value(); |
| + |
| + // Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « |
| + // throwValue »). |
| + InternalResolvePromise(context, wrapper, value); |
| + |
| + // Let onFulfilled be a new built-in function object as defined in |
| + // Async Iterator Value Unwrap Functions. |
| + // Set onFulfilled.[[Done]] to throwDone. |
| + Node* const map = LoadContextElement( |
| + native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); |
| + Node* const on_resolve_shared = LoadContextElement( |
| + native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN); |
| + CSA_ASSERT(this, |
| + HasInstanceType(on_resolve_shared, SHARED_FUNCTION_INFO_TYPE)); |
| + Node* const closure_context = |
| + AllocateAsyncIteratorValueUnwrapContext(native_context, done); |
| + Node* const on_resolve = AllocateFunctionWithMapAndContext( |
| + map, on_resolve_shared, closure_context); |
| + |
| + // Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], |
| + // onFulfilled, undefined, promiseCapability). |
| + Node* const undefined = UndefinedConstant(); |
| + InternalPerformPromiseThen(context, wrapper, on_resolve, undefined, |
| + promise, undefined, undefined); |
| + Return(promise); |
| + } |
| + } |
| + |
| + Bind(&if_receiverisincompatible); |
| + { |
| + // If Type(O) is not Object, or if O does not have a [[SyncIterator]] |
| + // internal slot, then |
| + |
| + // Let badIteratorError be a new TypeError exception. |
| + Node* const make_type_error = |
| + LoadContextElement(native_context, Context::MAKE_TYPE_ERROR_INDEX); |
| + Node* const error = |
| + CallJS(CodeFactory::Call(isolate()), context, make_type_error, |
| + UndefinedConstant(), |
| + SmiConstant(MessageTemplate::kIncompatibleMethodReceiver), |
| + HeapConstant(method_name), iterator); |
| + |
| + // Perform ! Call(promiseCapability.[[Reject]], undefined, |
| + // « badIteratorError »). |
| + var_exception.Bind(error); |
| + Goto(&reject_promise); |
| + } |
| + |
| + Bind(&reject_promise); |
| + { |
| + Node* const exception = var_exception.value(); |
| + InternalPromiseReject(context, promise, exception, TrueConstant()); |
| + |
| + // Return promiseCapability.[[Promise]]. |
| + Return(promise); |
| + } |
| +} |
| + |
| +TF_BUILTIN(AsyncIteratorValueUnwrap, AsyncBuiltinsAssembler) { |
| + Node* const value = Parameter(1); |
| + Node* const context = Parameter(4); |
| + |
| + Node* const done = LoadContextElement(context, ValueUnwrapContext::kDoneSlot); |
| + Node* const unwrapped_value = CallStub( |
| + CodeFactory::CreateIterResultObject(isolate()), context, value, done); |
| + |
| + Return(unwrapped_value); |
| +} |
| + |
| +Node* AsyncBuiltinsAssembler::AllocateAsyncIteratorValueUnwrapContext( |
| + Node* native_context, Node* done) { |
| + Node* const context = |
| + CreatePromiseContext(native_context, ValueUnwrapContext::kLength); |
| + StoreContextElementNoWriteBarrier(context, ValueUnwrapContext::kDoneSlot, |
| + done); |
| + return context; |
| +} |
| + |
| +} // namespace internal |
| +} // namespace v8 |