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.

fix accessor properties invoking getters during cjs namespace population

+69 -40
+30
include/internal.h
··· 249 249 size_t bytes; 250 250 } js_intern_stats_t; 251 251 252 + typedef struct { 253 + bool has_getter; 254 + bool has_setter; 255 + bool writable; 256 + bool enumerable; 257 + bool configurable; 258 + ant_value_t getter; 259 + ant_value_t setter; 260 + } prop_meta_t; 261 + 262 + typedef enum { 263 + PROP_META_STRING = 0, 264 + PROP_META_SYMBOL = 1, 265 + } prop_meta_key_t; 266 + 252 267 typedef ant_value_t 253 268 (*js_cfunc_fn_t)(ant_t *, ant_value_t *, int); 254 269 ··· 355 370 void js_module_eval_ctx_push(ant_t *js, ant_module_t *ctx); 356 371 void js_module_eval_ctx_pop(ant_t *js, ant_module_t *ctx); 357 372 373 + bool lookup_prop_meta( 374 + ant_t *js, ant_value_t cur_obj, 375 + prop_meta_key_t key_kind, 376 + const char *key, size_t klen, 377 + ant_offset_t sym_off, prop_meta_t *out 378 + ); 379 + 358 380 static inline ant_value_t js_module_eval_active_ns(ant_t *js) { 359 381 ant_module_t *ctx = js->module; 360 382 return ctx ? ctx->module_ns : js_mkundef(); ··· 400 422 401 423 static inline bool js_check_brand(ant_value_t obj, int brand) { 402 424 return js_brand_id(obj) == brand; 425 + } 426 + 427 + static inline bool lookup_symbol_prop_meta(ant_value_t cur_obj, ant_offset_t sym_off, prop_meta_t *out) { 428 + return lookup_prop_meta(NULL, cur_obj, PROP_META_SYMBOL, NULL, 0, sym_off, out); 429 + } 430 + 431 + static inline bool lookup_string_prop_meta(ant_t *js, ant_value_t cur_obj, const char *key, size_t klen, prop_meta_t *out) { 432 + return lookup_prop_meta(js, cur_obj, PROP_META_STRING, key, klen, 0, out); 403 433 } 404 434 405 435 static inline void js_set_module_default(ant_t *js, ant_value_t lib, ant_value_t ctor_fn, const char *name) {
+1 -27
src/ant.c
··· 214 214 if (pd->handlers) utarray_clear(pd->handlers); 215 215 } 216 216 217 - typedef struct { 218 - bool has_getter; 219 - bool has_setter; 220 - bool writable; 221 - bool enumerable; 222 - bool configurable; 223 - ant_value_t getter; 224 - ant_value_t setter; 225 - } prop_meta_t; 226 - 227 - static bool lookup_symbol_prop_meta(ant_value_t cur_obj, ant_offset_t sym_off, prop_meta_t *out); 228 - static bool lookup_string_prop_meta(ant_t *js, ant_value_t cur_obj, const char *key, size_t klen, prop_meta_t *out); 229 - 230 217 ant_value_t tov(double d) { 231 218 union { double d; ant_value_t v; } u = {d}; 232 219 if (__builtin_expect(isnan(d), 0)) ··· 3038 3025 return v; 3039 3026 } 3040 3027 3041 - typedef enum { 3042 - PROP_META_STRING = 0, 3043 - PROP_META_SYMBOL = 1, 3044 - } prop_meta_key_t; 3045 - 3046 3028 static inline void prop_meta_defaults(prop_meta_t *out) { 3047 3029 *out = (prop_meta_t){ 3048 3030 .has_getter = false, ··· 3075 3057 out->setter = desc->setter; 3076 3058 } 3077 3059 3078 - static bool lookup_prop_meta( 3060 + bool lookup_prop_meta( 3079 3061 ant_t *js, 3080 3062 ant_value_t cur_obj, 3081 3063 prop_meta_key_t key_kind, ··· 3132 3114 if (!desc) return false; 3133 3115 prop_meta_from_desc(out, desc); 3134 3116 return true; 3135 - } 3136 - 3137 - static inline bool lookup_symbol_prop_meta(ant_value_t cur_obj, ant_offset_t sym_off, prop_meta_t *out) { 3138 - return lookup_prop_meta(NULL, cur_obj, PROP_META_SYMBOL, NULL, 0, sym_off, out); 3139 - } 3140 - 3141 - static inline bool lookup_string_prop_meta(ant_t *js, ant_value_t cur_obj, const char *key, size_t klen, prop_meta_t *out) { 3142 - return lookup_prop_meta(js, cur_obj, PROP_META_STRING, key, klen, 0, out); 3143 3117 } 3144 3118 3145 3119 bool js_try_get_own_data_prop(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t *out) {
+38 -13
src/esm/commonjs.c
··· 6 6 #include "errors.h" 7 7 8 8 #include "silver/compiler.h" 9 - #include "silver/vm.h" 9 + #include "silver/engine.h" 10 10 11 11 #include <libgen.h> 12 12 #include <string.h> ··· 71 71 return resolved; 72 72 } 73 73 74 + static bool copy_own_prop( 75 + ant_t *js, ant_value_t dst, ant_value_t src, 76 + const char *key, size_t key_len, ant_value_t *err 77 + ) { 78 + ant_value_t value = js_mkundef(); 79 + 80 + if (js_try_get_own_data_prop(js, src, key, key_len, &value)) { 81 + ant_value_t res = setprop_cstr(js, dst, key, key_len, value); 82 + if (is_err(res)) { *err = res; return false; } 83 + return true; 84 + } 85 + 86 + prop_meta_t meta; 87 + if (lookup_string_prop_meta(js, src, key, key_len, &meta) && (meta.has_getter || meta.has_setter)) { 88 + ant_value_t ns = js_as_obj(dst); 89 + int flags = (meta.enumerable ? JS_DESC_E : 0) | (meta.configurable ? JS_DESC_C : 0); 90 + if (meta.has_getter) js_set_getter_desc(js, ns, key, key_len, meta.getter, flags); 91 + if (meta.has_setter) js_set_setter_desc(js, ns, key, key_len, meta.setter, flags); 92 + return true; 93 + } 94 + 95 + value = js_get(js, src, key); 96 + if (is_err(value)) { *err = value; return false; } 97 + if (vtype(value) == T_UNDEF) return true; 98 + 99 + ant_value_t res = setprop_cstr(js, dst, key, key_len, value); 100 + if (is_err(res)) { *err = res; return false; } 101 + 102 + return true; 103 + } 104 + 74 105 static ant_value_t esm_populate_cjs_namespace(ant_t *js, ant_value_t ns, ant_value_t exports_val) { 75 106 ant_value_t set_default = setprop_cstr(js, ns, "default", 7, exports_val); 76 107 if (is_err(set_default)) return set_default; ··· 83 114 size_t key_len = 0; 84 115 85 116 while (js_prop_iter_next(&iter, &key, &key_len, NULL)) { 86 - if (key_len == 7 && memcmp(key, "default", 7) == 0) continue; 87 - 88 - ant_value_t value = js_mkundef(); 89 - if (!js_try_get_own_data_prop(js, exports_val, key, key_len, &value)) { 90 - value = js_get(js, exports_val, key); 91 - if (is_err(value)) { js_prop_iter_end(&iter); return value; } 92 - if (vtype(value) == T_UNDEF) continue; 93 - } 94 - 95 - ant_value_t res = setprop_cstr(js, ns, key, key_len, value); 96 - if (is_err(res)) { js_prop_iter_end(&iter); return res; } 97 - } 117 + if (key_len == 7 && memcmp(key, "default", 7) == 0) continue; 118 + 119 + ant_value_t err = js_mkundef(); 120 + if (!copy_own_prop(js, ns, exports_val, key, key_len, &err)) { 121 + if (is_err(err)) { js_prop_iter_end(&iter); return err; } 122 + }} 98 123 99 124 js_prop_iter_end(&iter); 100 125 return js_mkundef();