Skip to content

Commit

Permalink
[New] ES2015+ (CompletionRecord, NormalCompletion), ES2018+ (Thro…
Browse files Browse the repository at this point in the history
…wCompletion): add new AOs
  • Loading branch information
ljharb committed Dec 14, 2022
1 parent 72bc480 commit 4917083
Show file tree
Hide file tree
Showing 49 changed files with 688 additions and 16 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
/2016/MakeTime.js spackled linguist-generated=true
/2016/MinFromTime.js spackled linguist-generated=true
/2016/MonthFromTime.js spackled linguist-generated=true
/2016/NormalCompletion.js spackled linguist-generated=true
/2016/ObjectCreate.js spackled linguist-generated=true
/2016/ObjectDefineProperties.js spackled linguist-generated=true
/2016/OrdinaryCreateFromConstructor.js spackled linguist-generated=true
Expand Down Expand Up @@ -165,6 +166,7 @@
/2017/CanonicalNumericIndexString.js spackled linguist-generated=true
/2017/CharacterRange.js spackled linguist-generated=true
/2017/CompletePropertyDescriptor.js spackled linguist-generated=true
/2017/CompletionRecord.js spackled linguist-generated=true
/2017/CreateDataProperty.js spackled linguist-generated=true
/2017/CreateDataPropertyOrThrow.js spackled linguist-generated=true
/2017/CreateHTML.js spackled linguist-generated=true
Expand Down Expand Up @@ -216,6 +218,7 @@
/2017/MakeTime.js spackled linguist-generated=true
/2017/MinFromTime.js spackled linguist-generated=true
/2017/MonthFromTime.js spackled linguist-generated=true
/2017/NormalCompletion.js spackled linguist-generated=true
/2017/ObjectCreate.js spackled linguist-generated=true
/2017/ObjectDefineProperties.js spackled linguist-generated=true
/2017/OrdinaryCreateFromConstructor.js spackled linguist-generated=true
Expand Down Expand Up @@ -285,6 +288,7 @@
/2018/CanonicalNumericIndexString.js spackled linguist-generated=true
/2018/CharacterRange.js spackled linguist-generated=true
/2018/CompletePropertyDescriptor.js spackled linguist-generated=true
/2018/CompletionRecord.js spackled linguist-generated=true
/2018/CreateDataProperty.js spackled linguist-generated=true
/2018/CreateDataPropertyOrThrow.js spackled linguist-generated=true
/2018/CreateHTML.js spackled linguist-generated=true
Expand Down Expand Up @@ -336,6 +340,7 @@
/2018/MakeTime.js spackled linguist-generated=true
/2018/MinFromTime.js spackled linguist-generated=true
/2018/MonthFromTime.js spackled linguist-generated=true
/2018/NormalCompletion.js spackled linguist-generated=true
/2018/ObjectCreate.js spackled linguist-generated=true
/2018/ObjectDefineProperties.js spackled linguist-generated=true
/2018/OrdinaryCreateFromConstructor.js spackled linguist-generated=true
Expand Down Expand Up @@ -408,6 +413,7 @@
/2019/CanonicalNumericIndexString.js spackled linguist-generated=true
/2019/CharacterRange.js spackled linguist-generated=true
/2019/CompletePropertyDescriptor.js spackled linguist-generated=true
/2019/CompletionRecord.js spackled linguist-generated=true
/2019/CopyDataProperties.js spackled linguist-generated=true
/2019/CreateDataProperty.js spackled linguist-generated=true
/2019/CreateDataPropertyOrThrow.js spackled linguist-generated=true
Expand Down Expand Up @@ -464,6 +470,7 @@
/2019/MakeTime.js spackled linguist-generated=true
/2019/MinFromTime.js spackled linguist-generated=true
/2019/MonthFromTime.js spackled linguist-generated=true
/2019/NormalCompletion.js spackled linguist-generated=true
/2019/NumberToString.js spackled linguist-generated=true
/2019/ObjectCreate.js spackled linguist-generated=true
/2019/ObjectDefineProperties.js spackled linguist-generated=true
Expand Down Expand Up @@ -494,6 +501,7 @@
/2019/StringGetOwnProperty.js spackled linguist-generated=true
/2019/SymbolDescriptiveString.js spackled linguist-generated=true
/2019/TestIntegrityLevel.js spackled linguist-generated=true
/2019/ThrowCompletion.js spackled linguist-generated=true
/2019/TimeClip.js spackled linguist-generated=true
/2019/TimeFromYear.js spackled linguist-generated=true
/2019/TimeString.js spackled linguist-generated=true
Expand Down Expand Up @@ -539,6 +547,7 @@
/2020/CanonicalNumericIndexString.js spackled linguist-generated=true
/2020/CharacterRange.js spackled linguist-generated=true
/2020/CompletePropertyDescriptor.js spackled linguist-generated=true
/2020/CompletionRecord.js spackled linguist-generated=true
/2020/CreateDataProperty.js spackled linguist-generated=true
/2020/CreateDataPropertyOrThrow.js spackled linguist-generated=true
/2020/CreateHTML.js spackled linguist-generated=true
Expand Down Expand Up @@ -591,6 +600,7 @@
/2020/MakeTime.js spackled linguist-generated=true
/2020/MinFromTime.js spackled linguist-generated=true
/2020/MonthFromTime.js spackled linguist-generated=true
/2020/NormalCompletion.js spackled linguist-generated=true
/2020/ObjectDefineProperties.js spackled linguist-generated=true
/2020/OrdinaryDefineOwnProperty.js spackled linguist-generated=true
/2020/OrdinaryGetOwnProperty.js spackled linguist-generated=true
Expand All @@ -616,6 +626,7 @@
/2020/StringGetOwnProperty.js spackled linguist-generated=true
/2020/SymbolDescriptiveString.js spackled linguist-generated=true
/2020/TestIntegrityLevel.js spackled linguist-generated=true
/2020/ThrowCompletion.js spackled linguist-generated=true
/2020/TimeClip.js spackled linguist-generated=true
/2020/TimeFromYear.js spackled linguist-generated=true
/2020/TimeString.js spackled linguist-generated=true
Expand Down Expand Up @@ -680,6 +691,7 @@
/2021/CanonicalNumericIndexString.js spackled linguist-generated=true
/2021/CharacterRange.js spackled linguist-generated=true
/2021/CompletePropertyDescriptor.js spackled linguist-generated=true
/2021/CompletionRecord.js spackled linguist-generated=true
/2021/CreateAsyncFromSyncIterator.js spackled linguist-generated=true
/2021/CreateDataProperty.js spackled linguist-generated=true
/2021/CreateDataPropertyOrThrow.js spackled linguist-generated=true
Expand Down Expand Up @@ -738,6 +750,7 @@
/2021/MakeDate.js spackled linguist-generated=true
/2021/MinFromTime.js spackled linguist-generated=true
/2021/MonthFromTime.js spackled linguist-generated=true
/2021/NormalCompletion.js spackled linguist-generated=true
/2021/Number/bitwiseAND.js spackled linguist-generated=true
/2021/Number/bitwiseNOT.js spackled linguist-generated=true
/2021/Number/bitwiseOR.js spackled linguist-generated=true
Expand Down Expand Up @@ -781,6 +794,7 @@
/2021/StringToBigInt.js spackled linguist-generated=true
/2021/SymbolDescriptiveString.js spackled linguist-generated=true
/2021/TestIntegrityLevel.js spackled linguist-generated=true
/2021/ThrowCompletion.js spackled linguist-generated=true
/2021/TimeClip.js spackled linguist-generated=true
/2021/TimeFromYear.js spackled linguist-generated=true
/2021/TimeString.js spackled linguist-generated=true
Expand Down Expand Up @@ -860,6 +874,7 @@
/2022/CodePointAt.js spackled linguist-generated=true
/2022/CodePointsToString.js spackled linguist-generated=true
/2022/CompletePropertyDescriptor.js spackled linguist-generated=true
/2022/CompletionRecord.js spackled linguist-generated=true
/2022/CopyDataProperties.js spackled linguist-generated=true
/2022/CreateAsyncFromSyncIterator.js spackled linguist-generated=true
/2022/CreateDataProperty.js spackled linguist-generated=true
Expand Down Expand Up @@ -923,6 +938,7 @@
/2022/MakeTime.js spackled linguist-generated=true
/2022/MinFromTime.js spackled linguist-generated=true
/2022/MonthFromTime.js spackled linguist-generated=true
/2022/NormalCompletion.js spackled linguist-generated=true
/2022/Number/add.js spackled linguist-generated=true
/2022/Number/bitwiseAND.js spackled linguist-generated=true
/2022/Number/bitwiseNOT.js spackled linguist-generated=true
Expand Down Expand Up @@ -977,6 +993,7 @@
/2022/StringToCodePoints.js spackled linguist-generated=true
/2022/SymbolDescriptiveString.js spackled linguist-generated=true
/2022/TestIntegrityLevel.js spackled linguist-generated=true
/2022/ThrowCompletion.js spackled linguist-generated=true
/2022/TimeClip.js spackled linguist-generated=true
/2022/TimeFromYear.js spackled linguist-generated=true
/2022/TimeString.js spackled linguist-generated=true
Expand Down
53 changes: 53 additions & 0 deletions 2015/CompletionRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

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

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

var SLOT = require('internal-slot');

// https://262.ecma-international.org/6.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;
9 changes: 9 additions & 0 deletions 2015/NormalCompletion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

var CompletionRecord = require('./CompletionRecord');

// https://262.ecma-international.org/6.0/#sec-normalcompletion

module.exports = function NormalCompletion(value) {
return new CompletionRecord('normal', value);
};
53 changes: 53 additions & 0 deletions 2016/CompletionRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'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;
9 changes: 9 additions & 0 deletions 2016/NormalCompletion.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions 2017/CompletionRecord.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions 2017/NormalCompletion.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions 2018/CompletionRecord.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions 2018/NormalCompletion.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4917083

Please sign in to comment.