Path: blob/main/test/browser/async_iostream.cpp
4150 views
// Copyright 2015 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 <stdio.h>6#include <iostream>7#include <emscripten.h>8#include <emscripten/html5.h>910using namespace std;1112int seen = 0;1314bool mouse_callback(int eventType, const EmscriptenMouseEvent *e, void* userData) {15cout << "mouse_callback+" << endl;16seen++;17return 0;18}1920void mainLoop() {21emscripten_sleep(100);22static int counter = 0;23counter++;24EM_ASM(25function sendEvent(type, data) {26setTimeout(function() {27var event = document.createEvent('Event');28event.initEvent(type, true, true);29for(var d in data) event[d] = data[d];30Module['canvas'].dispatchEvent(event);31}, Math.random()*100);32}33sendEvent('mousedown', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 1 });34);35cout << "sent event " << counter << "\n";36if (seen >= 10) {37emscripten_cancel_main_loop();38cout << "Success.\n";39REPORT_RESULT(1);40return;41}42if (counter >= 100) {43emscripten_cancel_main_loop();44cout << "FAIL\n";45REPORT_RESULT(9999);46return;47}48}4950int main() {51cout << "HelloWorld" << endl;52emscripten_set_mousedown_callback("#canvas", 0, 1, mouse_callback);53emscripten_set_main_loop(mainLoop, 0, 0);54return 0;55}56575859