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.

use ASan to catch memory leaks

+26 -33
+1
.gitignore
··· 7 7 *.dll 8 8 9 9 /build 10 + /traces 10 11 /javascript-zoo 11 12 12 13 /subprojects/*/
+6
maidfile.toml
··· 24 24 meson setup build --wipe' 25 25 '''] 26 26 27 + [tasks.asan] 28 + script = ['meson subprojects download', ''' 29 + bash -c 'CC="ccache $(which clang)" \ 30 + meson setup build --wipe -Db_sanitize=address -Doptimization=0 -Db_lto=false -Dstrip=false' 31 + '''] 32 + 27 33 [tasks.install] 28 34 script = ''' 29 35 bash -c 'which ant && cp ./build/ant "$(which ant)" ||
+1 -1
meson.build
··· 79 79 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 80 80 81 81 version_conf = configuration_data() 82 - version_conf.set('ANT_VERSION', '0.2.2.15') 82 + version_conf.set('ANT_VERSION', '0.2.2.16') 83 83 version_conf.set('ANT_GIT_HASH', git_hash) 84 84 version_conf.set('ANT_BUILD_DATE', build_date) 85 85
+8 -5
src/ant.c
··· 2315 2315 jsoff_t ofs = js_alloc(js, len + sizeof(b)); 2316 2316 if (ofs == (jsoff_t) ~0) return js_mkerr(js, "oom"); 2317 2317 memcpy(&js->mem[ofs], &b, sizeof(b)); 2318 - if (buf != NULL) memmove(&js->mem[ofs + sizeof(b)], buf, len); 2318 + if (buf != NULL) { 2319 + size_t copy_len = ((b & 3) == T_STR && len > 0) ? len - 1 : len; 2320 + memmove(&js->mem[ofs + sizeof(b)], buf, copy_len); 2321 + } 2319 2322 if ((b & 3) == T_STR) js->mem[ofs + sizeof(b) + len - 1] = 0; 2320 2323 return mkval(b & 3, ofs); 2321 2324 } ··· 17001 17004 if (idx >= str_len) return js_mkstr(js, "", 0); 17002 17005 17003 17006 jsoff_t str_off = (jsoff_t) vdata(str) + sizeof(jsoff_t); 17004 - char ch = js->mem[str_off + idx]; 17007 + char ch[2] = { js->mem[str_off + idx], '\0' }; 17005 17008 17006 - return js_mkstr(js, &ch, 1); 17009 + return js_mkstr(js, ch, 1); 17007 17010 } 17008 17011 17009 17012 static jsval_t builtin_string_at(struct js *js, jsval_t *args, int nargs) { ··· 17019 17022 if (idx < 0 || idx >= (long) str_len) return js_mkundef(); 17020 17023 17021 17024 jsoff_t str_off = (jsoff_t) vdata(str) + sizeof(jsoff_t); 17022 - char ch = js->mem[str_off + idx]; 17023 - return js_mkstr(js, &ch, 1); 17025 + char ch[2] = { js->mem[str_off + idx], '\0' }; 17026 + return js_mkstr(js, ch, 1); 17024 17027 } 17025 17028 17026 17029 static jsval_t builtin_string_localeCompare(struct js *js, jsval_t *args, int nargs) {
+3 -5
src/main.c
··· 106 106 buffer[len] = '\0'; 107 107 108 108 char abs_path[4096]; 109 - char *use_path = NULL; 109 + const char *use_path = NULL; 110 110 if (realpath(filename, abs_path) != NULL) { 111 - use_path = strdup(abs_path); 112 - } else use_path = strdup(filename); 111 + use_path = abs_path; 112 + } else use_path = filename; 113 113 114 114 js_set_filename(js, use_path); 115 115 js_setup_import_meta(js, use_path); ··· 122 122 123 123 if (js_type(result) == JS_ERR) { 124 124 fprintf(stderr, "%s\n", js_str(js, result)); 125 - free(use_path); 126 125 return EXIT_FAILURE; 127 126 } 128 127 129 - free(use_path); 130 128 return EXIT_SUCCESS; 131 129 } 132 130
+7 -22
src/modules/server.c
··· 31 31 for (size_t i = 0; i < len; i++) { 32 32 if (str[i] == '\033' && i + 1 < len && str[i + 1] == '[') { 33 33 i += 2; 34 - while (i < len && !((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z'))) { 35 - i++; 36 - } 34 + while (i < len && !((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z'))) i++; 37 35 continue; 38 36 } 39 37 result[j++] = str[i]; ··· 315 313 memcpy(req->body, body_start, req->body_len); 316 314 req->body[req->body_len] = '\0'; 317 315 } 318 - } else { 319 - req->body = NULL; 320 - } 316 + } else req->body = NULL; 321 317 } else { 322 318 req->body = NULL; 323 319 req->body_len = 0; ··· 745 741 746 742 jsval_t args[1] = {ctx}; 747 743 result = js_call(server->js, server->handler, args, 1); 748 - if (js_type(result) == JS_PROMISE) { 749 - return; 750 - } 744 + if (js_type(result) == JS_PROMISE) return; 751 745 752 746 if (js_type(result) == JS_ERR) { 753 747 const char *error_msg = js_str(server->js, result); ··· 806 800 uv_close((uv_handle_t *)ctx->client_handle, on_close); 807 801 } 808 802 809 - if (ctx->custom_headers) { 810 - utarray_free(ctx->custom_headers); 811 - } 812 - 813 - if (ctx->should_free_body && ctx->body) { 814 - free(ctx->body); 815 - } 803 + if (ctx->custom_headers) utarray_free(ctx->custom_headers); 804 + if (ctx->should_free_body && ctx->body) free(ctx->body); 816 805 817 806 free(ctx); 818 - } else { 819 - current = &ctx->next; 820 - } 807 + } else { current = &ctx->next; } 821 808 } 822 809 } 823 810 ··· 919 906 920 907 if (uv_accept(server, (uv_stream_t *)&client->handle) == 0) { 921 908 uv_read_start((uv_stream_t *)&client->handle, alloc_buffer, on_read); 922 - } else { 923 - uv_close((uv_handle_t *)&client->handle, on_close); 924 - } 909 + } else uv_close((uv_handle_t *)&client->handle, on_close); 925 910 } 926 911 927 912 // Ant.serve(port, handler)