forked from ljharb/es-abstract
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
653 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function clearBuffer(buffer) { | ||
new DataView(buffer).setFloat64(0, 0, true); // clear the buffer | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function getNamelessFunction() { | ||
var f = Object(function () {}); | ||
try { | ||
delete f.name; | ||
} catch (e) { /**/ } | ||
return f; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var assign = require('object.assign'); | ||
|
||
var hasLastIndex = 'lastIndex' in (/a/).exec('a'); // IE 8 | ||
var hasGroups = 'groups' in (/a/).exec('a'); // modern engines | ||
|
||
module.exports = function kludgeMatch(R, matchObject) { | ||
if (hasGroups) { | ||
assign(matchObject, { groups: matchObject.groups }); | ||
} | ||
if (hasLastIndex) { | ||
assign(matchObject, { lastIndex: matchObject.lastIndex || R.lastIndex }); | ||
} else { | ||
delete matchObject.lastIndex; // eslint-disable-line no-param-reassign | ||
} | ||
return matchObject; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
var makeIteratorRecord = require('./makeIteratorRecord'); | ||
|
||
module.exports = function makeAsyncFromSyncIterator(CreateAsyncFromSyncIterator, end, throwMethod, returnMethod) { | ||
var i = 0; | ||
var iterator = { | ||
next: function next() { | ||
try { | ||
return { | ||
done: i > end, | ||
value: i | ||
}; | ||
} finally { | ||
i += 1; | ||
} | ||
}, | ||
'return': returnMethod, | ||
'throw': throwMethod | ||
}; | ||
var syncIteratorRecord = makeIteratorRecord(iterator); | ||
|
||
return CreateAsyncFromSyncIterator(syncIteratorRecord); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function makeIteratorRecord(iterator) { | ||
return { | ||
'[[Iterator]]': iterator, | ||
'[[NextMethod]]': iterator.next, | ||
'[[Done]]': false | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
module.exports = function testAsyncIterator(t, asyncIterator, expected) { | ||
var results = arguments.length > 3 ? arguments[3] : []; | ||
|
||
var nextResult = asyncIterator.next(); | ||
|
||
return Promise.resolve(nextResult).then(function (result) { | ||
results.push(result); | ||
if (!result.done && results.length < expected.length) { | ||
t.deepEqual(result, { done: false, value: expected[results.length - 1] }, 'result ' + (results.length - 1)); | ||
return testAsyncIterator(t, asyncIterator, expected, results); | ||
} | ||
|
||
t.equal(results.length, expected.length, 'expected ' + expected.length + ', got ' + (result.done ? '' : 'more than ') + results.length); | ||
return results.length; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = function testIterator(t, iterator, expected) { | ||
var resultCount = 0; | ||
var result; | ||
while (result = iterator.next(), !result.done && resultCount < expected.length + 1) { // eslint-disable-line no-sequences | ||
t.deepEqual(result, { done: false, value: expected[resultCount] }, 'result ' + resultCount); | ||
resultCount += 1; | ||
} | ||
t.equal(resultCount, expected.length, 'expected ' + expected.length + ', got ' + (result.done ? '' : 'more than ') + resultCount); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var v = require('es-value-fixtures'); | ||
|
||
var testIterator = require('./testIterator'); | ||
|
||
module.exports = function testRegExpStringIterator(CreateRegExpStringIterator, t, regex, str, global, unicode, expected) { | ||
var iterator = CreateRegExpStringIterator(regex, str, global, unicode); | ||
t.equal(typeof iterator, 'object', 'iterator is an object'); | ||
t.equal(typeof iterator.next, 'function', '`.next` is a function'); | ||
|
||
t.test('has symbols', { skip: !v.hasSymbols }, function (st) { | ||
st.equal(typeof iterator[Symbol.iterator], 'function', '[`Symbol.iterator`] is a function'); | ||
st.end(); | ||
}); | ||
|
||
testIterator(t, iterator, expected); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = function throwsSentinel(fn, sentinel, message) { | ||
try { | ||
fn(); | ||
this.fail('did not throw: ' + message); | ||
} catch (e) { | ||
this.equal(e, sentinel, message); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
'use strict'; | ||
|
||
var v = require('es-value-fixtures'); | ||
var hasBigInts = require('has-bigints')(); | ||
var isCore = require('is-core-module'); | ||
|
||
var leadingPoo = '\uD83D'; | ||
var trailingPoo = '\uDCA9'; | ||
var wholePoo = leadingPoo + trailingPoo; | ||
|
||
var msPerSecond = 1e3; | ||
var msPerMinute = 60 * msPerSecond; | ||
var msPerHour = 60 * msPerMinute; | ||
var msPerDay = 24 * msPerHour; | ||
|
||
var unknowns = [].concat( | ||
v.primitives, | ||
v.objects | ||
); | ||
var allButSyms = [].concat( | ||
v.objects, | ||
v.nonSymbolPrimitives | ||
); | ||
var invalidTATypes = [].concat( | ||
v.nonStrings, | ||
'not a valid type' | ||
); | ||
var nonFiniteNumbers = [].concat( | ||
v.infinities, | ||
NaN | ||
); | ||
var notInts = [].concat( | ||
v.nonNumbers, | ||
v.nonIntegerNumbers, | ||
nonFiniteNumbers, | ||
[], | ||
new Date() | ||
); | ||
|
||
var elementSizes = { | ||
__proto__: null, | ||
$Int8Array: 1, | ||
$Uint8Array: 1, | ||
$Uint8ClampedArray: 1, | ||
$Int16Array: 2, | ||
$Uint16Array: 2, | ||
$Int32Array: 4, | ||
$Uint32Array: 4, | ||
$BigInt64Array: 8, | ||
$BigUint64Array: 8, | ||
$Float32Array: 4, | ||
$Float64Array: 8 | ||
}; | ||
|
||
var unclampedUnsignedIntegerTypes = [ | ||
'Int8', | ||
'Int16', | ||
'Int32' | ||
]; | ||
var clampedTypes = [ | ||
'Uint8C' | ||
]; | ||
var unclampedSignedIntegerTypes = [ | ||
'Uint8', | ||
'Uint16', | ||
'Uint32' | ||
]; | ||
var unclampedIntegerTypes = [].concat( | ||
unclampedUnsignedIntegerTypes, | ||
unclampedSignedIntegerTypes | ||
); | ||
var floatTypes = [ | ||
'Float32', | ||
'Float64' | ||
]; | ||
var integerTypes = [].concat( | ||
unclampedIntegerTypes, | ||
clampedTypes | ||
); | ||
var bigIntTypes = [ | ||
'BigInt64', | ||
'BigUint64' | ||
]; | ||
var numberTypes = [].concat( | ||
floatTypes, | ||
integerTypes | ||
); | ||
var nonUnclampedIntegerTypes = [].concat( | ||
floatTypes, | ||
bigIntTypes | ||
); | ||
var unsignedElementTypes = [].concat( | ||
unclampedSignedIntegerTypes, | ||
hasBigInts ? 'BigUint64' : [] | ||
); | ||
var signedElementTypes = [].concat( | ||
unclampedUnsignedIntegerTypes, | ||
floatTypes, | ||
hasBigInts ? 'BigInt64' : [] | ||
); | ||
var allTypes = [].concat( | ||
numberTypes, | ||
hasBigInts ? bigIntTypes : [] | ||
); | ||
var nonTATypes = [].concat( | ||
v.nonStrings, | ||
'', | ||
'Byte' | ||
); | ||
|
||
var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false | ||
|
||
// IE 9 does not throw in strict mode when writability/configurability/extensibility is violated | ||
var noThrowOnStrictViolation = (function () { | ||
try { | ||
delete [].length; | ||
return true; | ||
} catch (e) { | ||
} | ||
return false; | ||
}()); | ||
|
||
var isBigIntTAType = function isBigIntTAType(type) { | ||
return type.slice(0, 3) === 'Big'; | ||
}; | ||
|
||
/* globals postMessage */ | ||
var canDetach = typeof structuredClone === 'function' || typeof postMessage === 'function' || isCore('worker_threads'); | ||
|
||
module.exports = { | ||
poo: { | ||
leading: leadingPoo, | ||
trailing: trailingPoo, | ||
whole: wholePoo | ||
}, | ||
hasBigInts: hasBigInts, | ||
msPerSecond: msPerSecond, | ||
msPerMinute: msPerMinute, | ||
msPerHour: msPerHour, | ||
msPerDay: msPerDay, | ||
unknowns: unknowns, | ||
allButSyms: allButSyms, | ||
invalidTATypes: invalidTATypes, | ||
nonFiniteNumbers: nonFiniteNumbers, | ||
notInts: notInts, | ||
elementSizes: elementSizes, | ||
unclampedUnsignedIntegerTypes: unclampedUnsignedIntegerTypes, | ||
clampedTypes: clampedTypes, | ||
unclampedSignedIntegerTypes: unclampedSignedIntegerTypes, | ||
unclampedIntegerTypes: unclampedIntegerTypes, | ||
floatTypes: floatTypes, | ||
integerTypes: integerTypes, | ||
bigIntTypes: bigIntTypes, | ||
numberTypes: numberTypes, | ||
nonUnclampedIntegerTypes: nonUnclampedIntegerTypes, | ||
unsignedElementTypes: unsignedElementTypes, | ||
signedElementTypes: signedElementTypes, | ||
allTypes: allTypes, | ||
nonTATypes: nonTATypes, | ||
canDistinguishSparseFromUndefined: canDistinguishSparseFromUndefined, | ||
noThrowOnStrictViolation: noThrowOnStrictViolation, | ||
isBigIntTAType: isBigIntTAType, | ||
canDetach: canDetach | ||
}; |
Oops, something went wrong.