MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / Class

Class Class

test/emscripten_api_browser_infloop.cpp:12–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <emscripten.h>
11
12struct Class {
13 static Class *instance;
14
15 int x;
16
17 Class() : x(0) {}
18 ~Class() {
19 // Destructor should never be called.
20 assert(false);
21 x = -9999;
22 }
23
24 void print() {
25 printf("waka %d\n", x++);
26
27 if (x == 7 || x < 0) {
28 emscripten_cancel_main_loop();
29 exit(x == 7 ? 0 : 1);
30 }
31 }
32
33 static void callback() {
34 instance->print();
35 }
36
37 void start() {
38 instance = this;
39
40 EM_ASM({
41 var initial = stackSave();
42 out('seeing initial stack of ' + initial);
43 setTimeout(function() {
44 var current = stackSave();
45 out('seeing later stack of ' + current);
46 assert(current === initial);
47 }, 0);
48 });
49
50 // important if we simulate an infinite loop here or not. With an infinite loop, the
51 // destructor should *NOT* have been called
52 emscripten_set_main_loop(Class::callback, 3, 1);
53 }
54};
55
56Class *Class::instance = NULL;
57

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected