await: rethrow error when there is no catch block, fixes #5129

pull/5149/head
Irshad P I 5 years ago
parent fc7e99e9f0
commit e29718243a

@ -59,6 +59,10 @@ export function handle_promise(promise, info) {
update(info.then, 1, info.value, value);
set_current_component(null);
}, error => {
if (info.current === info.catch && info.error === undefined) {
// when no catch block is present
throw error;
}
set_current_component(current_component);
update(info.catch, 2, info.error, error);
set_current_component(null);

@ -0,0 +1,44 @@
let fulfil;
let promise = new Promise(f => {
fulfil = f;
});
export default {
props: {
promise
},
html: `
<p>loading...</p>
`,
test({ assert, component, target }) {
fulfil(42);
return promise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>loaded</p>
`);
let reject;
promise = new Promise((f, r) => {
reject = r;
});
component.promise = promise;
assert.htmlEqual(target.innerHTML, `
<p>loading...</p>
`);
reject(new Error('this error should be thrown'));
return promise;
})
.catch((err) => {
assert.equal(err.message, 'this error should be thrown');
});
}
};

@ -0,0 +1,9 @@
<script>
export let promise;
</script>
{#await promise}
<p>loading...</p>
{:then value}
<p>loaded</p>
{/await}
Loading…
Cancel
Save