Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4389218
throw_expressions.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
throw_expressions.js
View Options
import
{
test
,
testThrows
,
summary
}
from
'./helpers.js'
;
console
.
log
(
'Throw Expression Tests\n'
);
const
must
=
value
=>
value
||
throw
new
Error
(
'missing'
);
test
(
'throw expression in arrow skip'
,
must
(
'ok'
),
'ok'
);
testThrows
(
'throw expression in arrow throws'
,
()
=>
must
(
''
));
function
fallback
(
value
)
{
return
value
??
throw
new
Error
(
'nullish'
);
}
test
(
'throw expression in nullish skip'
,
fallback
(
'value'
),
'value'
);
testThrows
(
'throw expression in nullish throws'
,
()
=>
fallback
(
null
));
function
choose
(
value
)
{
return
value
?
value
:
throw
new
Error
(
'bad'
);
}
test
(
'throw expression in conditional skip'
,
choose
(
7
),
7
);
testThrows
(
'throw expression in conditional throws'
,
()
=>
choose
(
0
));
function
defaultParam
(
value
=
throw
new
Error
(
'default'
))
{
return
value
;
}
test
(
'throw expression in parameter initializer skip'
,
defaultParam
(
3
),
3
);
testThrows
(
'throw expression in parameter initializer throws'
,
()
=>
defaultParam
());
let
caught
;
try
{
const
value
=
false
||
throw
'sentinel'
;
void
value
;
}
catch
(
e
)
{
caught
=
e
;
}
test
(
'throw expression throws raw value'
,
caught
,
'sentinel'
);
summary
();
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, May 1, 10:14 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
542819
Default Alt Text
throw_expressions.js (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment