| 12 | EM_JS_DEPS(main, "$stringToUTF8OnStack"); |
| 13 | |
| 14 | void __attribute__((noinline)) InteropString(char *staticBuffer) { |
| 15 | char *string = (char*)EM_ASM_PTR({ |
| 16 | var str = "hello, this is a string! "; |
| 17 | #if ONE_BIG_STRING |
| 18 | // double it until it is bigger than the stack |
| 19 | for (var i = 0; i < 15; ++i) { |
| 20 | str = str + str; |
| 21 | } |
| 22 | stringToUTF8OnStack(str); |
| 23 | #else |
| 24 | // allocate as many times as we need to overflow |
| 25 | for (var i = 0; i < 1024 * 1024; i++) { |
| 26 | stringToUTF8OnStack(str); |
| 27 | } |
| 28 | abort("we should never get here!"); |
| 29 | #endif |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | int main() { |
| 34 | // Make C side consume a large portion of the stack, before bumping the rest with C++<->JS interop. |