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