aboutsummaryrefslogtreecommitdiff
path: root/tests/emscripten_api_browser_infloop.cpp
blob: 0fd419225c7824feca2566082810d64a3a96f7a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#include <emscripten.h>

struct Class {
  static Class *instance;

  int x;

  Class() : x(0) {}

  void print() {
    char buf[18];
    memset(buf, 0, 18); // clear stack. if we did not simulate infinite loop, this clears x and is a bug!
    x += buf[7];

    printf("waka %d\n", x++);

    if (x == 7) {
      int result = x;
      REPORT_RESULT();
    }
  }

  static void callback() {
    instance->print();
  }

  void start() {
    instance = this;
    emscripten_set_main_loop(Class::callback, 3, 1); // important if we simulate an infinite loop here or not
  }
};

Class *Class::instance = NULL;

int main() {
  Class().start();
  return 1;
}