Skip to content

Commit c804ce7

Browse files
authored
Simplify/shorten addReadyPromiseAssertions. NFC (#17346)
- Use a loop over EXPORTED_FUNCTIONS rather than repeating the same block over and over. - Use a single call to defineProperty - Use arrow functions
1 parent 6b434d8 commit c804ce7

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/parseTools.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,15 +1164,16 @@ function addReadyPromiseAssertions(promise) {
11641164
// Also warn on onRuntimeInitialized which might be a common pattern with
11651165
// older MODULARIZE-using codebases.
11661166
properties.push('onRuntimeInitialized');
1167-
return properties.map((property) => {
1168-
const warningEnding = `${property} on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js`;
1169-
return `
1170-
if (!Object.getOwnPropertyDescriptor(${promise}, '${property}')) {
1171-
Object.defineProperty(${promise}, '${property}', { configurable: true, get: function() { abort('You are getting ${warningEnding}') } });
1172-
Object.defineProperty(${promise}, '${property}', { configurable: true, set: function() { abort('You are setting ${warningEnding}') } });
1173-
}
1174-
`;
1175-
}).join('\n');
1167+
const warningEnding = ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js';
1168+
const res = JSON.stringify(properties);
1169+
return res + `.forEach((prop) => {
1170+
if (!Object.getOwnPropertyDescriptor(${promise}, prop)) {
1171+
Object.defineProperty(${promise}, prop, {
1172+
get: () => abort('You are getting ' + prop + '${warningEnding}'),
1173+
set: () => abort('You are setting ' + prop + '${warningEnding}'),
1174+
});
1175+
}
1176+
});`;
11761177
}
11771178

11781179
function makeMalloc(source, param) {

0 commit comments

Comments
 (0)