Path: blob/main/test/emscripten_api_browser_infloop.cpp
6172 views
// Copyright 2012 The Emscripten Authors. All rights reserved.1// Emscripten is available under two separate licenses, the MIT license and the2// University of Illinois/NCSA Open Source License. Both these licenses can be3// found in the LICENSE file.45#include <assert.h>6#include <stdio.h>7#include <stdlib.h>8#include <string.h>9#include <emscripten.h>1011struct Class {12static Class *instance;1314int x;1516Class() : x(0) {}17~Class() {18// Destructor should never be called.19assert(false);20x = -9999;21}2223void print() {24printf("waka %d\n", x++);2526if (x == 7 || x < 0) {27emscripten_cancel_main_loop();28exit(x == 7 ? 0 : 1);29}30}3132static void callback() {33instance->print();34}3536void start() {37instance = this;3839EM_ASM({40var initial = stackSave();41out('seeing initial stack of ' + initial);42setTimeout(function() {43var current = stackSave();44out('seeing later stack of ' + current);45assert(current === initial);46}, 0);47});4849// important if we simulate an infinite loop here or not. With an infinite loop, the50// destructor should *NOT* have been called51emscripten_set_main_loop(Class::callback, 3, 1);52}53};5455Class *Class::instance = NULL;5657int main() {58Class().start();59return 99;60}61626364