Skip to content

Commit 2a01546

Browse files
committed
test promise error handled
1 parent c153f10 commit 2a01546

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2017 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
#include <emscripten.h>
7+
#include <stdio.h>
8+
// pthread
9+
#include <pthread.h>
10+
11+
int main()
12+
{
13+
// start new thread
14+
pthread_t thread;
15+
pthread_create(&thread, NULL, [](void*) -> void* {
16+
printf("Before MAIN_THREAD_EM_ASM_PROMISE_AWAIT\n");
17+
int res = MAIN_THREAD_EM_ASM_PROMISE_AWAIT({
18+
out('Inside MAIN_THREAD_EM_ASM_PROMISE_AWAIT: ' + $0 + ' ' + $1);
19+
const asyncOp = new Promise((resolve,reject) => {
20+
setTimeout(() => {
21+
out('Inside asyncOp');
22+
reject(2);
23+
}, 1000);
24+
});
25+
return asyncOp;
26+
}, 42, 3.5);
27+
printf("After MAIN_THREAD_EM_ASM_PROMISE_AWAIT rejected\n");
28+
printf("result: %d\n", res);
29+
return NULL;
30+
}, NULL);
31+
32+
// wait for thread to finish
33+
pthread_join(thread, NULL);
34+
return 0;
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Before MAIN_THREAD_EM_ASM_PROMISE_AWAIT
2+
Inside MAIN_THREAD_EM_ASM_PROMISE_AWAIT: 42 3.5
3+
Inside asyncOp
4+
After MAIN_THREAD_EM_ASM_PROMISE_AWAIT rejected
5+
result: 2

test/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,13 @@ def test_main_thread_async_em_asm_promise_await(self, args, force_c=False):
19081908
self.assertContained('call to emscripten_asm_const_int_await_promise_on_main_thread is only supported from pthread (but was called from main thread)', output)
19091909
else:
19101910
self.do_core_test('test_main_thread_async_em_asm_promise_await.cpp', emcc_args=args, force_c=force_c)
1911+
1912+
@needs_dylink
1913+
@parameterized({
1914+
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], False),
1915+
})
1916+
def test_main_thread_async_em_asm_promise_await_reject(self, args, force_c=False):
1917+
self.do_core_test('test_main_thread_async_em_asm_promise_await_reject.cpp', emcc_args=args, force_c=force_c)
19111918

19121919
# Tests MAIN_THREAD_EM_ASM_INT() function call with different signatures.
19131920
def test_main_thread_em_asm_signatures(self):

0 commit comments

Comments
 (0)