'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
 
var $SyntaxError = require('es-errors/syntax');
 
var SLOT = require('internal-slot');
 
// https://262.ecma-international.org/7.0/#sec-completion-record-specification-type
 
var CompletionRecord = function CompletionRecord(type, value) {
    if (!(this instanceof CompletionRecord)) {
        return new CompletionRecord(type, value);
    }
    if (type !== 'normal' && type !== 'break' && type !== 'continue' && type !== 'return' && type !== 'throw') {
        throw new $SyntaxError('Assertion failed: `type` must be one of "normal", "break", "continue", "return", or "throw"');
    }
    SLOT.set(this, '[[Type]]', type);
    SLOT.set(this, '[[Value]]', value);
    // [[Target]] slot?
};
 
CompletionRecord.prototype.type = function Type() {
    return SLOT.get(this, '[[Type]]');
};
 
CompletionRecord.prototype.value = function Value() {
    return SLOT.get(this, '[[Value]]');
};
 
CompletionRecord.prototype['?'] = function ReturnIfAbrupt() {
    var type = SLOT.get(this, '[[Type]]');
    var value = SLOT.get(this, '[[Value]]');
 
    if (type === 'normal') {
        return value;
    }
    if (type === 'throw') {
        throw value;
    }
    throw new $SyntaxError('Completion Record is not of type "normal" or "throw": other types not supported');
};
 
CompletionRecord.prototype['!'] = function assert() {
    var type = SLOT.get(this, '[[Type]]');
 
    if (type !== 'normal') {
        throw new $SyntaxError('Assertion failed: Completion Record is not of type "normal"');
    }
    return SLOT.get(this, '[[Value]]');
};
 
module.exports = CompletionRecord;