Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/emscripten_api_browser_infloop.cpp
6172 views
1
// Copyright 2012 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 <assert.h>
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <string.h>
10
#include <emscripten.h>
11
12
struct 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
56
Class *Class::instance = NULL;
57
58
int main() {
59
Class().start();
60
return 99;
61
}
62
63
64