forked from ljharb/es-abstract
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New]
ES2015
+ (CompletionRecord, NormalCompletion), ES2018
+ (Thro…
…wCompletion): add new AOs
- Loading branch information
Showing
49 changed files
with
688 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.