Skip to content

Commit

Permalink
avoid extra promise creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 9, 2022
1 parent 361c111 commit d05ee98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/core-js/internals/async-iterator-create-proxy.js
@@ -1,5 +1,6 @@
'use strict';
var call = require('../internals/function-call');
var perform = require('../internals/perform');
var anObject = require('../internals/an-object');
var create = require('../internals/object-create');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
Expand Down Expand Up @@ -32,10 +33,11 @@ module.exports = function (nextHandler, IS_ITERATOR) {
AsyncIteratorProxy.prototype = defineBuiltIns(create(AsyncIteratorPrototype), {
next: function next() {
var that = this;
return new Promise(function (resolve) {
var result = perform(function () {
var state = getInternalState(that);
resolve(state.done ? { done: true, value: undefined } : anObject(call(nextHandler, state, Promise)));
return state.done ? { done: true, value: undefined } : anObject(call(nextHandler, state, Promise));
});
return result.error ? Promise.reject(result.value) : Promise.resolve(result.value);
},
'return': function (value) {
var that = this;
Expand Down
3 changes: 1 addition & 2 deletions packages/core-js/modules/esnext.async-iterator.from.js
@@ -1,7 +1,6 @@
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var call = require('../internals/function-call');
var anObject = require('../internals/an-object');
var toObject = require('../internals/to-object');
var isPrototypeOf = require('../internals/object-is-prototype-of');
var AsyncIteratorPrototype = require('../internals/async-iterator-prototype');
Expand All @@ -17,7 +16,7 @@ var AsyncFromSyncIterator = require('../internals/async-from-sync-iterator');
var ASYNC_ITERATOR = wellKnownSymbol('asyncIterator');

var AsyncIteratorProxy = createAsyncIteratorProxy(function () {
return anObject(call(this.next, this.iterator));
return call(this.next, this.iterator);
}, true);

$({ target: 'AsyncIterator', stat: true, forced: true }, {
Expand Down

0 comments on commit d05ee98

Please sign in to comment.