Sha256: 9f6f95e81ef9c27bf4b4a8fa20ff86b911f1b007759ba9e5d1d92f1c20646457

Contents?: true

Size: 1.51 KB

Versions: 216

Compression:

Stored size: 1.51 KB

Contents

'use strict';

var GetIntrinsic = require('get-intrinsic');

var $SyntaxError = GetIntrinsic('%SyntaxError%');

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;

Version data entries

216 entries across 27 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.32 node_modules/es-abstract/2020/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2019/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2023/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2017/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2018/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2016/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2021/CompletionRecord.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2022/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2017/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2018/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2016/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2021/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2022/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2020/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2023/CompletionRecord.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2019/CompletionRecord.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2018/CompletionRecord.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2016/CompletionRecord.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2020/CompletionRecord.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2019/CompletionRecord.js