| 13 | bool sawCalls[] = { false, false, false, false }; |
| 14 | |
| 15 | void c1(char *data, int size, void *arg) { |
| 16 | assert((long)arg == 97); |
| 17 | assert(size >= sizeof(int)); |
| 18 | |
| 19 | int *x = (int*)data; |
| 20 | printf("c1: %d\n", x[0]); |
| 21 | |
| 22 | if (*x >= 0 && *x < 4) { |
| 23 | // Calls should have happened in order. |
| 24 | sawCalls[*x] = true; // Note the call with current param was made |
| 25 | for (int i = 0; i < *x - 1; ++i) { |
| 26 | if (!sawCalls[i]) { |
| 27 | // If we were called out of order, fail this and all following calls. |
| 28 | sawCalls[*x] = false; |
| 29 | break; |
| 30 | } |
| 31 | } |
| 32 | } else { |
| 33 | assert(*x == 4); |
| 34 | // This is the last call. All prior calls should have occurred. |
| 35 | int result = 1; // Final call occurred. |
| 36 | for (int i = 0; i < 4; ++i) |
| 37 | if (sawCalls[i]) result++; |
| 38 | REPORT_RESULT(result); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | int main() { |
| 43 | w1 = emscripten_create_worker("worker.js"); |