source: imaps-frontend/node_modules/es-abstract/2018/CompletionRecord.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var $SyntaxError = require('es-errors/syntax');
4
5var SLOT = require('internal-slot');
6
7// https://262.ecma-international.org/7.0/#sec-completion-record-specification-type
8
9var 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
21CompletionRecord.prototype.type = function Type() {
22 return SLOT.get(this, '[[Type]]');
23};
24
25CompletionRecord.prototype.value = function Value() {
26 return SLOT.get(this, '[[Value]]');
27};
28
29CompletionRecord.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
39CompletionRecord.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
48module.exports = CompletionRecord;
Note: See TracBrowser for help on using the repository browser.