MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / force_memory_growth

Function force_memory_growth

test/embind/embind_test.cpp:225–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225void force_memory_growth() {
226 std::size_t old_size = emscripten_get_heap_size();
227 EM_ASM({"globalThis.oldheap = HEAP8;"});
228 assert(val::global("oldheap")["byteLength"].as<size_t>() == old_size);
229 emscripten_resize_heap(old_size + EMSCRIPTEN_PAGE_SIZE);
230 assert(emscripten_get_heap_size() > old_size);
231 // HEAP8 on the module should always be correct after the resize.
232 // Our oldheap reference may be detached, depending on whether the
233 // buffer is resizable.
234 assert(val::module_property("HEAP8")["byteLength"].as<size_t>() > old_size);
235
236 val oldheap = val::global("oldheap");
237 val buffer = oldheap["buffer"];
238 bool growable = false;
239 if (!buffer.isUndefined()) {
240 if (!buffer["resizable"].isUndefined()) {
241 growable = buffer["resizable"].as<bool>();
242 } else if (!buffer["growable"].isUndefined()) {
243 growable = buffer["growable"].as<bool>();
244 }
245 }
246
247 if (growable) {
248 assert(oldheap["byteLength"].as<size_t>() == emscripten_get_heap_size());
249 } else {
250 assert(oldheap["byteLength"].as<size_t>() == 0);
251 }
252}
253
254std::string emval_test_take_and_return_const_char_star(const char* str) {
255 return str;

Calls 6

emscripten_get_heap_sizeFunction · 0.85
globalFunction · 0.85
emscripten_resize_heapFunction · 0.85
module_propertyFunction · 0.85
EM_ASMFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected