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.

crypto alias + allocUnsafe

+46 -3
+3
include/modules/crypto.h
··· 1 1 #ifndef CRYPTO_H 2 2 #define CRYPTO_H 3 3 4 + #include "ant.h" 5 + 4 6 void init_crypto_module(); 7 + jsval_t crypto_library(struct js *js); 5 8 6 9 #endif
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.0.8.23') 77 + version_conf.set('ANT_VERSION', '0.0.8.24') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+1
src/main.c
··· 190 190 ant_register_library("ant:shell", shell_library); 191 191 ant_register_library("ant:path", path_library); 192 192 ant_register_library("ant:ffi", ffi_library); 193 + ant_register_library("node:crypto", crypto_library); 193 194 194 195 if (eval->count > 0) eval_code(js, eval, print); 195 196 else if (repl_mode) ant_repl_run(); else {
+21
src/modules/buffer.c
··· 626 626 ArrayBufferData *buffer = create_array_buffer_data(size); 627 627 if (!buffer) return js_mkerr(js, "Failed to allocate buffer"); 628 628 629 + memset(buffer->data, 0, size); 630 + 631 + jsval_t obj = create_typed_array(js, TYPED_ARRAY_UINT8, buffer, 0, size, "Buffer"); 632 + js_set(js, obj, "toString", js_mkfun(js_buffer_toString)); 633 + js_set(js, obj, "toBase64", js_mkfun(js_buffer_toBase64)); 634 + js_set(js, obj, "write", js_mkfun(js_buffer_write)); 635 + 636 + return obj; 637 + } 638 + 639 + // Buffer.allocUnsafe(size) 640 + static jsval_t js_buffer_allocUnsafe(struct js *js, jsval_t *args, int nargs) { 641 + if (nargs < 1) { 642 + return js_mkerr(js, "Buffer.allocUnsafe requires a size argument"); 643 + } 644 + 645 + size_t size = (size_t)js_getnum(args[0]); 646 + ArrayBufferData *buffer = create_array_buffer_data(size); 647 + if (!buffer) return js_mkerr(js, "Failed to allocate buffer"); 648 + 629 649 jsval_t obj = create_typed_array(js, TYPED_ARRAY_UINT8, buffer, 0, size, "Buffer"); 630 650 js_set(js, obj, "toString", js_mkfun(js_buffer_toString)); 631 651 js_set(js, obj, "toBase64", js_mkfun(js_buffer_toBase64)); ··· 794 814 jsval_t buffer_obj = js_mkobj(js); 795 815 js_set(js, buffer_obj, "from", js_mkfun(js_buffer_from)); 796 816 js_set(js, buffer_obj, "alloc", js_mkfun(js_buffer_alloc)); 817 + js_set(js, buffer_obj, "allocUnsafe", js_mkfun(js_buffer_allocUnsafe)); 797 818 js_set(js, buffer_obj, "@@toStringTag", js_mkstr(js, "Buffer", 6)); 798 819 js_set(js, glob, "Buffer", buffer_obj); 799 820 }
+20 -2
src/modules/crypto.c
··· 162 162 return args[0]; 163 163 } 164 164 165 - void init_crypto_module() { 166 - struct js *js = rt->js; 165 + static jsval_t create_crypto_obj(struct js *js) { 167 166 jsval_t crypto_obj = js_mkobj(js); 168 167 169 168 js_set(js, crypto_obj, "random", js_mkfun(js_crypto_random)); ··· 173 172 js_set(js, crypto_obj, "getRandomValues", js_mkfun(js_crypto_get_random_values)); 174 173 175 174 js_set(js, crypto_obj, "@@toStringTag", js_mkstr(js, "Crypto", 6)); 175 + return crypto_obj; 176 + } 177 + 178 + void init_crypto_module() { 179 + struct js *js = rt->js; 180 + jsval_t crypto_obj = create_crypto_obj(js); 176 181 js_set(js, js_glob(js), "crypto", crypto_obj); 177 182 } 183 + 184 + jsval_t crypto_library(struct js *js) { 185 + jsval_t lib = js_mkobj(js); 186 + jsval_t webcrypto = create_crypto_obj(js); 187 + 188 + js_set(js, lib, "webcrypto", webcrypto); 189 + js_set(js, lib, "randomBytes", js_mkfun(js_crypto_random_bytes)); 190 + js_set(js, lib, "randomUUID", js_mkfun(js_crypto_random_uuid)); 191 + js_set(js, lib, "getRandomValues", js_mkfun(js_crypto_get_random_values)); 192 + js_set(js, lib, "@@toStringTag", js_mkstr(js, "crypto", 6)); 193 + 194 + return lib; 195 + }