mirror of https://github.com/tc39/test262.git
completion values of try-catch-finally
This commit is contained in:
parent
5de16292fd
commit
536ecd08a9
|
@ -0,0 +1,79 @@
|
|||
// Copyright (C) 2020 Salesforce.com. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-try-statement-runtime-semantics-evaluation
|
||||
description: >
|
||||
Returns the correct completion values of try-catch-finally(Abrupt) in functions
|
||||
info: |
|
||||
TryStatement : try Block Catch Finally
|
||||
|
||||
Let B be the result of evaluating Block.
|
||||
If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]].
|
||||
Else, let C be B.
|
||||
Let F be the result of evaluating Finally.
|
||||
If F.[[Type]] is normal, set F to C.
|
||||
Return Completion(UpdateEmpty(F, undefined)).
|
||||
---*/
|
||||
|
||||
var fn, count = {};
|
||||
|
||||
// 1: try Abrupt, catch Abrupt, finally Abrupt; Completion: finally
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
throw 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
throw 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C.
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, fn, '1: try Abrupt, catch Abrupt, finally Abrupt; Completion: finally');
|
||||
assert.sameValue(count.catch, 1, '1: catch count');
|
||||
assert.sameValue(count.finally, 1, '1: fiinally count');
|
||||
|
||||
// 2: try Abrupt, catch Return, finally Abrupt; Completion: finally
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
throw 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
return 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C.
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, fn, '2: try Abrupt, catch Return, finally Abrupt; Completion: finally');
|
||||
assert.sameValue(count.catch, 1, '2: catch count');
|
||||
assert.sameValue(count.finally, 1, '2: fiinally count');
|
||||
|
||||
// 3: try Return, catch Return, finally Abrupt; Completion: finally
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
return 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
return 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C.
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, fn, '3: try Normal, catch Normal, finally Abrupt; Completion: finally');
|
||||
assert.sameValue(count.catch, 0, '3: catch count');
|
||||
assert.sameValue(count.finally, 1, '3: fiinally count');
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (C) 2020 Salesforce.com. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-try-statement-runtime-semantics-evaluation
|
||||
description: >
|
||||
Returns the correct completion values of try-catch-finally(Normal) in functions
|
||||
info: |
|
||||
TryStatement : try Block Catch Finally
|
||||
|
||||
Let B be the result of evaluating Block.
|
||||
If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]].
|
||||
Else, let C be B.
|
||||
Let F be the result of evaluating Finally.
|
||||
If F.[[Type]] is normal, set F to C.
|
||||
Return Completion(UpdateEmpty(F, undefined)).
|
||||
---*/
|
||||
|
||||
// 1: try Return, catch Return, finally Normal; Completion: try
|
||||
var count = {
|
||||
catch: 0,
|
||||
finally: 0
|
||||
};
|
||||
|
||||
var fn = function() {
|
||||
try {
|
||||
return 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
return 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
'normal';
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.sameValue(fn(), 'try', '1: try Return, catch Return, finally Normal; Completion: try');
|
||||
assert.sameValue(count.catch, 0, '1');
|
||||
assert.sameValue(count.finally, 1, '1');
|
||||
|
||||
// 2: try Abrupt, catch Return, finally Normal; Completion: catch
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
throw 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
return 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
'finally';
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.sameValue(fn(), 'catch', '2: try Abrupt, catch Return, finally Normal; Completion: catch');
|
||||
assert.sameValue(count.catch, 1, '2: catch count');
|
||||
assert.sameValue(count.finally, 1, '2: fiinally count');
|
||||
|
||||
// 3: try Abrupt, catch Abrupt, finally Normal; Completion: catch
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
throw 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
throw new Test262Error('catch');
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
'finally';
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, fn, '3: try Abrupt, catch Abrupt, finally Normal; Completion: catch');
|
||||
assert.sameValue(count.catch, 1, '3: catch count');
|
||||
assert.sameValue(count.finally, 1, '3: fiinally count');
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (C) 2020 Salesforce.com. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-try-statement-runtime-semantics-evaluation
|
||||
description: >
|
||||
Returns the correct completion values of try-catch-finally(Return) in functions
|
||||
info: |
|
||||
TryStatement : try Block Catch Finally
|
||||
|
||||
Let B be the result of evaluating Block.
|
||||
If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]].
|
||||
Else, let C be B.
|
||||
Let F be the result of evaluating Finally.
|
||||
If F.[[Type]] is normal, set F to C.
|
||||
Return Completion(UpdateEmpty(F, undefined)).
|
||||
---*/
|
||||
|
||||
// 1: try Return, catch Return, finally Return; Completion: finally
|
||||
var count = {
|
||||
catch: 0,
|
||||
finally: 0
|
||||
};
|
||||
|
||||
var fn = function() {
|
||||
try {
|
||||
return 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
return 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
return 'finally';
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.sameValue(fn(), 'finally', '1: try Return, catch Return, finally Return; Completion: finally');
|
||||
assert.sameValue(count.catch, 0, '1');
|
||||
assert.sameValue(count.finally, 1, '1');
|
||||
|
||||
// 2: try Abrupt, catch Return, finally Return; Completion: finally
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
throw 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
return 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
return 'finally';
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.sameValue(fn(), 'finally', '2: try Abrupt, catch Return, finally Return; Completion: finally');
|
||||
assert.sameValue(count.catch, 1, '2: catch count');
|
||||
assert.sameValue(count.finally, 1, '2: fiinally count');
|
||||
|
||||
// 3: try Abrupt, catch Abrupt, finally Normal; Completion: finally
|
||||
count.catch = 0;
|
||||
count.finally = 0;
|
||||
fn = function() {
|
||||
try {
|
||||
throw 'try';
|
||||
} catch(e) {
|
||||
count.catch += 1;
|
||||
throw 'catch';
|
||||
} finally {
|
||||
count.finally += 1;
|
||||
return 'finally';
|
||||
}
|
||||
return 'wat';
|
||||
};
|
||||
|
||||
assert.sameValue(fn(), 'finally', fn, '3: try Abrupt, catch Abrupt, finally Normal; Completion: finally');
|
||||
assert.sameValue(count.catch, 1, '3: catch count');
|
||||
assert.sameValue(count.finally, 1, '3: fiinally count');
|
|
@ -1,40 +1,65 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-try-statement-runtime-semantics-evaluation
|
||||
description: >
|
||||
Direct eval try/catch/finally for completion value
|
||||
esid: sec-performeval
|
||||
Direct eval try/catch/finally for completion value
|
||||
info: |
|
||||
TryStatement : try Block Catch Finally
|
||||
|
||||
Let B be the result of evaluating Block.
|
||||
If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]].
|
||||
Else, let C be B.
|
||||
Let F be the result of evaluating Finally.
|
||||
If F.[[Type]] is normal, set F to C.
|
||||
Return Completion(UpdateEmpty(F, undefined)).
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { 42 } catch (e) { -1 } finally { -2; break; -3 }; } while (false);'),
|
||||
eval('99; do { -99; try { 39 } catch (e) { -1 } finally { 42; break; -2 }; } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { 42; } finally { -2; break; -3 }; } while (false);'),
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { -1; } finally { 42; break; -3 }; } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { 42 } catch (e) { -1 } finally { -2; break; -3 }; -77 } while (false);'),
|
||||
eval('99; do { -99; try { 39 } catch (e) { -1 } finally { break; -2 }; } while (false);'),
|
||||
undefined
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { -1; } finally { break; -3 }; } while (false);'),
|
||||
undefined
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { 39 } catch (e) { -1 } finally { 42; break; -3 }; -77 } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { 42; } finally { -2; break; -3 }; -77 } while (false);'),
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { -1; } finally { 42; break; -3 }; -77 } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { 42 } catch (e) { -1 } finally { -2; continue; -3 }; } while (false);'),
|
||||
eval('99; do { -99; try { 39 } catch (e) { -1 } finally { break; -3 }; -77 } while (false);'),
|
||||
undefined
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { -1; } finally { break; -3 }; -77 } while (false);'),
|
||||
undefined
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { 39 } catch (e) { -1 } finally { 42; continue; -3 }; } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { 42; } finally { -2; continue; -3 }; } while (false);'),
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { -1; } finally { 42; continue; -3 }; } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { 42 } catch (e) { -1 } finally { -2; continue; -3 }; -77 } while (false);'),
|
||||
eval('99; do { -99; try { 39 } catch (e) { -1 } finally { 42; continue; -3 }; -77 } while (false);'),
|
||||
42
|
||||
);
|
||||
assert.sameValue(
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { 42; } finally { -2; continue; -3 }; -77 } while (false);'),
|
||||
eval('99; do { -99; try { [].x.x } catch (e) { -1 } finally { 42; continue; -3 }; -77 } while (false);'),
|
||||
42
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue