1 | 'use strict';
|
---|
2 |
|
---|
3 | // TODO, semver-major: delete this
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 | var $SyntaxError = require('es-errors/syntax');
|
---|
7 |
|
---|
8 | var isMatchRecord = require('./records/match-record');
|
---|
9 | var isPropertyDescriptor = require('./records/property-descriptor');
|
---|
10 | var isIteratorRecord = require('./records/iterator-record');
|
---|
11 | var isPromiseCapabilityRecord = require('./records/promise-capability-record');
|
---|
12 | var isAsyncGeneratorRequestRecord = require('./records/async-generator-request-record');
|
---|
13 | var isRegExpRecord = require('./records/regexp-record');
|
---|
14 |
|
---|
15 | var predicates = {
|
---|
16 | 'Property Descriptor': isPropertyDescriptor,
|
---|
17 | 'Match Record': isMatchRecord,
|
---|
18 | 'Iterator Record': isIteratorRecord,
|
---|
19 | 'PromiseCapability Record': isPromiseCapabilityRecord,
|
---|
20 | 'AsyncGeneratorRequest Record': isAsyncGeneratorRequestRecord,
|
---|
21 | 'RegExp Record': isRegExpRecord
|
---|
22 | };
|
---|
23 |
|
---|
24 | module.exports = function assertRecord(Type, recordType, argumentName, value) {
|
---|
25 | var predicate = predicates[recordType];
|
---|
26 | if (typeof predicate !== 'function') {
|
---|
27 | throw new $SyntaxError('unknown record type: ' + recordType);
|
---|
28 | }
|
---|
29 | if (!predicate(value)) {
|
---|
30 | throw new $TypeError(argumentName + ' must be a ' + recordType);
|
---|
31 | }
|
---|
32 | };
|
---|