Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.7 KiB
73 lines
2.7 KiB
1 year ago
|
'use strict';
|
||
|
var call = require('../internals/function-call');
|
||
|
var aCallable = require('../internals/a-callable');
|
||
|
var anObject = require('../internals/an-object');
|
||
|
var create = require('../internals/object-create');
|
||
|
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
||
|
var redefineAll = require('../internals/redefine-all');
|
||
|
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||
|
var InternalStateModule = require('../internals/internal-state');
|
||
|
var getBuiltIn = require('../internals/get-built-in');
|
||
|
var getMethod = require('../internals/get-method');
|
||
|
var AsyncIteratorPrototype = require('../internals/async-iterator-prototype');
|
||
|
|
||
|
var Promise = getBuiltIn('Promise');
|
||
|
|
||
|
var setInternalState = InternalStateModule.set;
|
||
|
var getInternalState = InternalStateModule.get;
|
||
|
|
||
|
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
||
|
|
||
|
module.exports = function (nextHandler, IS_ITERATOR) {
|
||
|
var AsyncIteratorProxy = function AsyncIterator(state) {
|
||
|
state.next = aCallable(state.iterator.next);
|
||
|
state.done = false;
|
||
|
state.ignoreArgument = !IS_ITERATOR;
|
||
|
setInternalState(this, state);
|
||
|
};
|
||
|
|
||
|
AsyncIteratorProxy.prototype = redefineAll(create(AsyncIteratorPrototype), {
|
||
|
next: function next(arg) {
|
||
|
var that = this;
|
||
|
var hasArgument = !!arguments.length;
|
||
|
return new Promise(function (resolve) {
|
||
|
var state = getInternalState(that);
|
||
|
var args = hasArgument ? [state.ignoreArgument ? undefined : arg] : IS_ITERATOR ? [] : [undefined];
|
||
|
state.ignoreArgument = false;
|
||
|
resolve(state.done ? { done: true, value: undefined } : anObject(call(nextHandler, state, Promise, args)));
|
||
|
});
|
||
|
},
|
||
|
'return': function (value) {
|
||
|
var that = this;
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
var state = getInternalState(that);
|
||
|
var iterator = state.iterator;
|
||
|
state.done = true;
|
||
|
var $$return = getMethod(iterator, 'return');
|
||
|
if ($$return === undefined) return resolve({ done: true, value: value });
|
||
|
Promise.resolve(call($$return, iterator, value)).then(function (result) {
|
||
|
anObject(result);
|
||
|
resolve({ done: true, value: value });
|
||
|
}, reject);
|
||
|
});
|
||
|
},
|
||
|
'throw': function (value) {
|
||
|
var that = this;
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
var state = getInternalState(that);
|
||
|
var iterator = state.iterator;
|
||
|
state.done = true;
|
||
|
var $$throw = getMethod(iterator, 'throw');
|
||
|
if ($$throw === undefined) return reject(value);
|
||
|
resolve(call($$throw, iterator, value));
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (!IS_ITERATOR) {
|
||
|
createNonEnumerableProperty(AsyncIteratorProxy.prototype, TO_STRING_TAG, 'Generator');
|
||
|
}
|
||
|
|
||
|
return AsyncIteratorProxy;
|
||
|
};
|