Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
34 lines (22 loc) · 1.09 KB

File metadata and controls

34 lines (22 loc) · 1.09 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2013 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
var Module = require("./test.js");
console.log("\nTesting main.js");
var length = 20;
var ptr = Module._malloc(length); // Get buffer from emscripten.
var buffer= new Uint8Array(Module.HEAPU8.buffer, ptr, length); // Get a bytes view on the newly allocated buffer.
// Populate the buffer in JavaScript land.
console.log("buffer length = " + length + "\n");
for (var i = 0; i < length; i++) {
buffer[i] = i + 20; // Add 20 just for a bit of interest.
console.log("setting buffer[" + i + "] = " + buffer[i]);
}
// Export bufferTest function.
var bufferTest = Module.cwrap('bufferTest', 'number', ['number', 'number']);
console.log("\ncalling bufferTest\n");
bufferTest(ptr, length); // Call our exported C function to prove the buffer was passed correctly.
console.log("\nbufferTest finished\n");
// free the heap buffer
Module._free(ptr);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.