Path: blob/main/test/browser/async_virtual_2.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 <emscripten.h>6#include <stdio.h>78class DOS_Device {9int devnum;10public:11DOS_Device() { devnum = 0; }12virtual bool Read(unsigned char * data,unsigned short * size);13};1415DOS_Device *Devices[10];1617bool __attribute__((noinline)) DOS_Device::Read(unsigned char * data,unsigned short * size) {18printf("DOS_Device::Read (this = %ld)\n", (long)this);19return Devices[devnum]->Read(data,size);20}2122class device_CON : public DOS_Device {23public:24bool Read(unsigned char * data,unsigned short * size);25};2627bool device_CON::Read(unsigned char * data,unsigned short * size) {28printf("device_CON::Read (this = %ld) Sleep--> \n", (long)this);29EM_ASM({30Module.the_this = $0;31out('first this ' + Module.the_this);32}, this);33emscripten_sleep(1000);34EM_ASM({35out('second this ' + $0);36assert(Module.the_this === $0, 'this must be unchanged');37}, this);38printf("<--Sleep (this = %ld)\n", (long)this);39return true;40}4142int main(void) {43device_CON con;44Devices[0] = &con;45DOS_Device dev;46dev.Read(0,0);47return 0;48}49505152