From f9ca142e982f27d91627758442e9b8fb8620c448 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 30 Nov 2024 16:47:05 -0800 Subject: [PATCH] [Refactor] `ES2015`+: `GetIterator`: hoist an object to module scope --- 2015/GetIterator.js | 15 +++++++-------- 2016/GetIterator.js | 15 +++++++-------- 2017/GetIterator.js | 15 +++++++-------- 2018/GetIterator.js | 15 +++++++-------- 2019/GetIterator.js | 15 +++++++-------- 2020/GetIterator.js | 15 +++++++-------- 2021/GetIterator.js | 15 +++++++-------- 2022/GetIterator.js | 15 +++++++-------- 2023/GetIterator.js | 15 +++++++-------- 2024/GetIterator.js | 15 +++++++-------- 10 files changed, 70 insertions(+), 80 deletions(-) diff --git a/2015/GetIterator.js b/2015/GetIterator.js index b3df5a96..3581e3af 100644 --- a/2015/GetIterator.js +++ b/2015/GetIterator.js @@ -10,19 +10,18 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/6.0/#sec-getiterator module.exports = function GetIterator(obj, method) { var actualMethod = method; if (arguments.length < 2) { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } var iterator = Call(actualMethod, obj); if (!isObject(iterator)) { diff --git a/2016/GetIterator.js b/2016/GetIterator.js index b3df5a96..3581e3af 100644 --- a/2016/GetIterator.js +++ b/2016/GetIterator.js @@ -10,19 +10,18 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/6.0/#sec-getiterator module.exports = function GetIterator(obj, method) { var actualMethod = method; if (arguments.length < 2) { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } var iterator = Call(actualMethod, obj); if (!isObject(iterator)) { diff --git a/2017/GetIterator.js b/2017/GetIterator.js index b3df5a96..3581e3af 100644 --- a/2017/GetIterator.js +++ b/2017/GetIterator.js @@ -10,19 +10,18 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/6.0/#sec-getiterator module.exports = function GetIterator(obj, method) { var actualMethod = method; if (arguments.length < 2) { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } var iterator = Call(actualMethod, obj); if (!isObject(iterator)) { diff --git a/2018/GetIterator.js b/2018/GetIterator.js index b3df5a96..3581e3af 100644 --- a/2018/GetIterator.js +++ b/2018/GetIterator.js @@ -10,19 +10,18 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/6.0/#sec-getiterator module.exports = function GetIterator(obj, method) { var actualMethod = method; if (arguments.length < 2) { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } var iterator = Call(actualMethod, obj); if (!isObject(iterator)) { diff --git a/2019/GetIterator.js b/2019/GetIterator.js index b3df5a96..3581e3af 100644 --- a/2019/GetIterator.js +++ b/2019/GetIterator.js @@ -10,19 +10,18 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/6.0/#sec-getiterator module.exports = function GetIterator(obj, method) { var actualMethod = method; if (arguments.length < 2) { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } var iterator = Call(actualMethod, obj); if (!isObject(iterator)) { diff --git a/2020/GetIterator.js b/2020/GetIterator.js index e95cf97f..1fd93442 100644 --- a/2020/GetIterator.js +++ b/2020/GetIterator.js @@ -17,6 +17,12 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/11.0/#sec-getiterator module.exports = function GetIterator(obj, hint, method) { @@ -38,14 +44,7 @@ module.exports = function GetIterator(obj, hint, method) { throw new $SyntaxError("async from sync iterators aren't currently supported"); } } else { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } } var iterator = Call(actualMethod, obj); diff --git a/2021/GetIterator.js b/2021/GetIterator.js index e95cf97f..1fd93442 100644 --- a/2021/GetIterator.js +++ b/2021/GetIterator.js @@ -17,6 +17,12 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/11.0/#sec-getiterator module.exports = function GetIterator(obj, hint, method) { @@ -38,14 +44,7 @@ module.exports = function GetIterator(obj, hint, method) { throw new $SyntaxError("async from sync iterators aren't currently supported"); } } else { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } } var iterator = Call(actualMethod, obj); diff --git a/2022/GetIterator.js b/2022/GetIterator.js index e95cf97f..1fd93442 100644 --- a/2022/GetIterator.js +++ b/2022/GetIterator.js @@ -17,6 +17,12 @@ var IsArray = require('./IsArray'); var isObject = require('../helpers/isObject'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/11.0/#sec-getiterator module.exports = function GetIterator(obj, hint, method) { @@ -38,14 +44,7 @@ module.exports = function GetIterator(obj, hint, method) { throw new $SyntaxError("async from sync iterators aren't currently supported"); } } else { - actualMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + actualMethod = getIteratorMethod(ES, obj); } } var iterator = Call(actualMethod, obj); diff --git a/2023/GetIterator.js b/2023/GetIterator.js index a8de0416..893e7128 100644 --- a/2023/GetIterator.js +++ b/2023/GetIterator.js @@ -16,6 +16,12 @@ var IsArray = require('./IsArray'); var getIteratorMethod = require('../helpers/getIteratorMethod'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + // https://262.ecma-international.org/14.0/#sec-getiterator module.exports = function GetIterator(obj, kind) { @@ -31,14 +37,7 @@ module.exports = function GetIterator(obj, kind) { } if (typeof method === 'undefined') { // step 1.b // var syncMethod = GetMethod(obj, $iterator); // step 1.b.i - var syncMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + var syncMethod = getIteratorMethod(ES, obj); if (kind === 'async') { if (typeof syncMethod === 'undefined') { throw new $TypeError('iterator method is `undefined`'); // step 1.b.ii diff --git a/2024/GetIterator.js b/2024/GetIterator.js index eb48bdda..9a2c4dac 100644 --- a/2024/GetIterator.js +++ b/2024/GetIterator.js @@ -14,6 +14,12 @@ var GetIteratorFromMethod = require('./GetIteratorFromMethod'); var GetMethod = require('./GetMethod'); var IsArray = require('./IsArray'); +var ES = { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray +}; + var getIteratorMethod = require('../helpers/getIteratorMethod'); // https://262.ecma-international.org/14.0/#sec-getiterator @@ -31,14 +37,7 @@ module.exports = function GetIterator(obj, kind) { } if (typeof method === 'undefined') { // step 1.b // var syncMethod = GetMethod(obj, $iterator); // step 1.b.i - var syncMethod = getIteratorMethod( - { - AdvanceStringIndex: AdvanceStringIndex, - GetMethod: GetMethod, - IsArray: IsArray - }, - obj - ); + var syncMethod = getIteratorMethod(ES, obj); if (kind === 'ASYNC') { if (typeof syncMethod === 'undefined') { throw new $TypeError('iterator method is `undefined`'); // step 1.b.ii