MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove promise from shell command execution

+34 -23
+17
examples/demo/uptime.js
··· 1 + #!/usr/bin/env ant 2 + 3 + import { $ } from 'ant:shell'; 4 + import { uptime as osUptime, loadavg } from 'ant:os'; 5 + 6 + const uptime = osUptime(); 7 + const users = $`who | wc -l`.text().trim(); 8 + 9 + const days = Math.floor(uptime / 86400); 10 + const hours = Math.floor((uptime % 86400) / 3600); 11 + const minutes = String(Math.floor((uptime % 3600) / 60)).padStart(2, '0'); 12 + 13 + const load = loadavg() 14 + .map(n => n.toFixed(2)) 15 + .join(' '); 16 + 17 + console.log(`up ${days} days, ${hours}:${minutes}, ${users} user${users == 1 ? '' : 's'}, load averages: ${load}`);
+1 -2
examples/spec/run.js
··· 29 29 const name = path.basename(file, '.js'); 30 30 31 31 try { 32 - const result = await $`./build/ant ${filePath}`; 33 - const output = result.text(); 32 + const output = $`./build/ant ${filePath}`.text(); 34 33 console.log(output); 35 34 36 35 const passedMatch = output.match(/Passed:\s*(\d+)/);
+1 -1
meson.build
··· 96 96 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 97 97 98 98 version_conf = configuration_data() 99 - version_conf.set('ANT_VERSION', '0.3.2.36') 99 + version_conf.set('ANT_VERSION', '0.3.2.37') 100 100 version_conf.set('ANT_GIT_HASH', git_hash) 101 101 version_conf.set('ANT_BUILD_DATE', build_date) 102 102
+6 -3
src/ant.c
··· 8155 8155 js->consumed = 1; 8156 8156 next(js); 8157 8157 js->consumed = 1; 8158 - jsval_t result = js_tagged_template(js, tag_func); 8159 - return result; 8158 + res = js_tagged_template(js, tag_func); 8159 + if (is_err(res)) return res; 8160 + goto js_call_dot_loop; 8160 8161 } 8161 8162 if ((js->flags & F_STRICT) && is_eval_or_arguments(js, coderefoff(res), codereflen(res))) { 8162 8163 uint8_t la = lookahead(js); ··· 8190 8191 if (is_err(res)) return res; 8191 8192 } 8192 8193 } 8194 + js_call_dot_loop: 8193 8195 while (next(js) == TOK_LPAREN || next(js) == TOK_DOT || next(js) == TOK_OPTIONAL_CHAIN || next(js) == TOK_LBRACKET || next(js) == TOK_TEMPLATE) { 8194 8196 if (js->tok == TOK_TEMPLATE) { 8195 8197 if (vtype(res) == T_PROP) res = resolveprop(js, res); 8196 8198 if (is_err(res)) return res; 8197 8199 js->consumed = 1; 8198 - return js_tagged_template(js, res); 8200 + res = js_tagged_template(js, res); 8201 + if (is_err(res)) return res; 8199 8202 } else if (js->tok == TOK_DOT || js->tok == TOK_OPTIONAL_CHAIN) { 8200 8203 uint8_t op = js->tok; 8201 8204 js->consumed = 1;
+2 -10
src/modules/shell.c
··· 129 129 size_t cmd_len; 130 130 char *cmd = js_getstr(js, args[0], &cmd_len); 131 131 if (!cmd) return js_mkerr(js, "Failed to get command string"); 132 - 133 - jsval_t result = shell_exec(js, cmd, cmd_len); 134 - jsval_t promise = js_mkpromise(js); 135 - js_resolve_promise(js, promise, result); 136 - 137 - return promise; 132 + return shell_exec(js, cmd, cmd_len); 138 133 } 139 134 140 135 return js_mkerr(js, "$() requires a template string"); ··· 208 203 jsval_t result = shell_exec(js, command, cmd_pos); 209 204 free(command); 210 205 211 - jsval_t promise = js_mkpromise(js); 212 - js_resolve_promise(js, promise, result); 213 - 214 - return promise; 206 + return result; 215 207 } 216 208 217 209 jsval_t shell_library(struct js *js) {
+7 -7
tests/test_shell.js
··· 3 3 console.log('Testing $ shell command execution...'); 4 4 5 5 console.log('\n=== Test 1: Simple echo ==='); 6 - const result1 = await $`echo "Hello, world!"`; 6 + const result1 = $`echo "Hello, world!"`; 7 7 const text1 = result1.text(); 8 8 console.log('Output:', text1); 9 9 if (text1 !== 'Hello, world!') { ··· 14 14 } 15 15 16 16 console.log('\n=== Test 2: Multi-line output ==='); 17 - const result2 = await $`echo "line1\nline2\nline3"`; 17 + const result2 = $`echo "line1\nline2\nline3"`; 18 18 const lines2 = result2.lines(); 19 19 console.log('Line count:', lines2.length); 20 20 console.log('Line 0:', lines2[0]); ··· 35 35 } 36 36 37 37 console.log('\n=== Test 3: ls command ==='); 38 - const result3 = await $`ls tests/test_shell.js`; 38 + const result3 = $`ls tests/test_shell.js`; 39 39 const text3 = result3.text(); 40 40 console.log('Output:', text3); 41 41 if (!text3.includes('test_shell.js')) { ··· 43 43 } 44 44 45 45 console.log('\n=== Test 4: pwd command ==='); 46 - const result4 = await $`pwd`; 46 + const result4 = $`pwd`; 47 47 const text4 = result4.text(); 48 48 console.log('Current directory:', text4); 49 49 if (text4.length === 0) { ··· 51 51 } 52 52 53 53 console.log('\n=== Test 5: .text() method ==='); 54 - const result5 = await $`echo "test text method"`; 54 + const result5 = $`echo "test text method"`; 55 55 const text5 = result5.text(); 56 56 console.log('Text:', text5); 57 57 if (text5 !== 'test text method') { ··· 59 59 } 60 60 61 61 console.log('\n=== Test 6: Listing files with .lines() ==='); 62 - const result6 = await $`ls tests/*.cjs | head -5`; 62 + const result6 = $`ls tests/*.cjs | head -5`; 63 63 const lines6 = result6.lines(); 64 64 console.log('Found', lines6.length, 'files'); 65 65 for (let i = 0; i < lines6.length && i < 3; i++) { ··· 67 67 } 68 68 69 69 console.log('\n=== Test 7: date command ==='); 70 - const result7 = await $`date +%Y`; 70 + const result7 = $`date +%Y`; 71 71 const year = result7.text(); 72 72 console.log('Current year:', year); 73 73 if (year.length !== 4) {