Skip to content

Commit a34d0bd

Browse files
authored
DOCS Update Module-Splitting code (#20118)
* DOCS Update Module-Splitting code A few fixes to the module splitting code example: 1. Using `buffer` yields an error saying it's been removed and to use `HEAP8.buffer` instead. 2. `nodeFS` is not defined unless we specifically `require` it.
1 parent 0a6f54b commit a34d0bd

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

site/source/docs/optimizing/Module-Splitting.rst

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,25 @@ included in the profile.
124124
Here’s the function to write the profile and our new main function::
125125

126126
EM_JS(void, write_profile, (), {
127-
var __write_profile = wasmExports['__write_profile'];
128-
if (__write_profile) {
127+
var __write_profile = wasmExports.__write_profile;
128+
if (!__write_profile) {
129+
return;
130+
}
129131

130-
// Get the size of the profile and allocate a buffer for it.
131-
var len = __write_profile(0, 0);
132-
var ptr = _malloc(len);
132+
// Get the size of the profile and allocate a buffer for it.
133+
var len = __write_profile(0, 0);
134+
var ptr = _malloc(len);
133135

134-
// Write the profile data to the buffer.
135-
__write_profile(ptr, len);
136+
// Write the profile data to the buffer.
137+
__write_profile(ptr, len);
136138

137-
// Write the profile file.
138-
var profile_data = new Uint8Array(buffer, ptr, len);
139-
nodeFS.writeFileSync('profile.data', profile_data);
139+
// Write the profile file.
140+
var profile_data = new Uint8Array(HEAP8.buffer, ptr, len);
141+
const fs = require("fs");
142+
fs.writeFileSync('profile.data', profile_data);
140143

141-
// Free the buffer.
142-
_free(ptr);
143-
}
144+
// Free the buffer.
145+
_free(ptr);
144146
});
145147

146148
int main() {

0 commit comments

Comments
 (0)