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.

clean up reflect, ffi, and internal_prop

+164 -124
-1
include/internal.h
··· 359 359 return meta && meta->fn == fn; 360 360 } 361 361 362 - bool is_internal_prop(const char *key, ant_offset_t klen); 363 362 size_t uint_to_str(char *buf, size_t bufsize, uint64_t val); 364 363 int extract_array_args(ant_t *js, ant_value_t arr, ant_value_t **out_args); 365 364
+3 -20
src/ant.c
··· 2293 2293 }; 2294 2294 } 2295 2295 2296 - bool is_internal_prop(const char *key, ant_offset_t klen) { 2297 - if (klen < 2) return false; 2298 - if (key[0] != '_' || key[1] != '_') return false; 2299 - if (klen == STR_PROTO_LEN && memcmp(key, STR_PROTO, STR_PROTO_LEN) == 0) return false; 2300 - return true; 2301 - } 2302 - 2303 2296 struct func_format { 2304 2297 const char *prefix; 2305 2298 size_t prefix_len; ··· 6031 6024 ant_object_t *ptr = js_obj_ptr(obj); 6032 6025 if (!ptr || !ptr->shape) return mkarr(js); 6033 6026 if (ptr->is_exotic && ptr->exotic_keys) { 6034 - if (mode == OBJ_ENUM_KEYS && (!ptr->exotic_ops || !ptr->exotic_ops->getter)) return ptr->exotic_keys(js, obj); 6027 + if (mode == OBJ_ENUM_KEYS) return ptr->exotic_keys(js, obj); 6035 6028 if (ptr->exotic_ops && ptr->exotic_ops->getter) { 6036 6029 dynamic_kv_mapper_fn mapper = (mode == OBJ_ENUM_ENTRIES) ? map_to_entry : NULL; 6037 6030 return iterate_dynamic_keys(js, obj, mapper); ··· 6069 6062 ant_offset_t klen = (ant_offset_t)strlen(key); 6070 6063 ant_value_t val = ant_object_prop_get_unchecked(ptr, i); 6071 6064 6072 - if (is_internal_prop(key, klen)) continue; 6073 6065 if (is_arr && is_array_index(key, klen)) { 6074 6066 ant_offset_t doff = get_dense_buf(obj); 6075 6067 if (doff) { ··· 6259 6251 ant_offset_t key_off = vstr(js, key, &key_len); 6260 6252 const char *key_ptr = (const char *)(uintptr_t)(key_off); 6261 6253 6262 - if (is_internal_prop(key_ptr, key_len)) goto done; 6263 6254 if (lkp(js, seen, key_ptr, key_len) != 0) goto done; 6264 6255 6265 6256 ant_value_t mark = setprop_cstr(js, seen, key_ptr, key_len, js_true); ··· 6352 6343 6353 6344 const char *kstr = prop->key.interned; 6354 6345 klen = (ant_offset_t)strlen(kstr); 6355 - if (is_internal_prop(kstr, klen)) continue; 6356 - 6357 6346 if (is_arr && is_array_index(kstr, klen)) { 6358 6347 doff = get_dense_buf(as_cur); 6359 6348 if (doff) { ··· 7245 7234 ant_value_t descriptor = js_mkundef(); 7246 7235 7247 7236 while (js_prop_iter_next(&iter, &key, &key_len, &descriptor)) { 7248 - if (is_internal_prop(key, key_len)) continue; 7249 7237 ant_value_t prop_key = js_mkstr(js, key, key_len); 7250 7238 ant_value_t define_args[3] = { obj, prop_key, descriptor }; 7251 7239 ant_value_t result = builtin_object_defineProperty(js, define_args, 3); ··· 7273 7261 return (ant_shape_get_attrs(source_ptr->shape, key->slot) & ANT_PROP_ATTR_ENUMERABLE) != 0; 7274 7262 } 7275 7263 7276 - if (!key->str || is_internal_prop(key->str, key->key_len)) return false; 7264 + if (!key->str) return false; 7277 7265 7278 7266 if (!source_ptr || source_ptr->is_exotic) { 7279 7267 descriptor_entry_t *desc = lookup_descriptor(js_as_obj(source), key->str, key->key_len); ··· 7348 7336 7349 7337 if (prop->type == ANT_SHAPE_KEY_STRING) { 7350 7338 const char *key = prop->key.interned; 7351 - size_t klen = strlen(key); 7352 - if (is_internal_prop(key, klen)) continue; 7353 7339 ant_shape_set_attrs_interned(ptr->shape, key, attrs); 7354 7340 } else ant_shape_set_attrs_symbol(ptr->shape, prop->key.sym_off, attrs); 7355 7341 } ··· 7395 7381 7396 7382 if (prop->type == ANT_SHAPE_KEY_STRING) { 7397 7383 const char *key = prop->key.interned; 7398 - size_t klen = strlen(key); 7399 - if (is_internal_prop(key, klen)) continue; 7400 7384 ant_shape_set_attrs_interned(ptr->shape, key, attrs); 7401 7385 } else { 7402 7386 ant_shape_set_attrs_symbol(ptr->shape, prop->key.sym_off, attrs); ··· 7708 7692 const char *key = prop->key.interned; 7709 7693 ant_offset_t klen = (ant_offset_t)strlen(key); 7710 7694 7711 - if (is_internal_prop(key, klen)) continue; 7712 7695 if (is_arr_obj && own_prop_names_is_dense_shadow(js, obj, key, klen)) continue; 7713 7696 arr_set(js, arr, idx++, js_mkstr(js, key, (size_t)klen)); 7714 7697 } ··· 14587 14570 } 14588 14571 14589 14572 ant_value_t js_cfunc_expose_named(ant_t *js, ant_value_t cfunc, const char *name, size_t name_len) { 14590 - if (vtype(cfunc) != T_CFUNC || !name || is_internal_prop(name, (ant_offset_t)name_len)) return cfunc; 14573 + if (vtype(cfunc) != T_CFUNC || !name) return cfunc; 14591 14574 14592 14575 const ant_cfunc_meta_t *base = js_as_cfunc_meta(cfunc); 14593 14576 if (!base) return cfunc;
+71 -76
src/modules/ffi.c
··· 16 16 #include <utarray.h> 17 17 #include <uthash.h> 18 18 19 + #include "ptr.h" 19 20 #include "errors.h" 20 21 #include "gc/modules.h" 21 22 #include "internal.h" ··· 66 67 UT_hash_handle hh; 67 68 } ffi_callback_t; 68 69 70 + enum { FFI_LIBRARY_NATIVE_TAG = 0x4646494Cu }; // FFIL 71 + 69 72 static ffi_lib_t *ffi_libraries = NULL; 70 73 static ffi_ptr_t *ffi_pointers = NULL; 71 74 static ffi_callback_t *ffi_callbacks = NULL; ··· 83 86 .dtor = NULL, 84 87 }; 85 88 86 - static ant_value_t ffi_dlopen(ant_t *js, ant_value_t *args, int nargs); 89 + static ffi_type *get_ffi_type(const char *type_str); 90 + static void *js_to_ffi_value(ant_t *js, ant_value_t val, ffi_type *type, void *buffer); 91 + 87 92 static ant_value_t ffi_define(ant_t *js, ant_value_t *args, int nargs); 88 93 static ant_value_t ffi_lib_call(ant_t *js, ant_value_t *args, int nargs); 89 - static ant_value_t ffi_call_function(ant_t *js, ffi_func_t *func, ant_value_t *args, int nargs); 90 - static ant_value_t ffi_alloc_memory(ant_t *js, ant_value_t *args, int nargs); 91 - static ant_value_t ffi_free_memory(ant_t *js, ant_value_t *args, int nargs); 92 - static ant_value_t ffi_read_memory(ant_t *js, ant_value_t *args, int nargs); 93 - static ant_value_t ffi_write_memory(ant_t *js, ant_value_t *args, int nargs); 94 - static ant_value_t ffi_get_pointer(ant_t *js, ant_value_t *args, int nargs); 95 - static ant_value_t ffi_create_callback(ant_t *js, ant_value_t *args, int nargs); 96 - static ant_value_t ffi_free_callback(ant_t *js, ant_value_t *args, int nargs); 97 - static ant_value_t ffi_read_ptr(ant_t *js, ant_value_t *args, int nargs); 98 - 99 - static ffi_type *get_ffi_type(const char *type_str); 100 - static void *js_to_ffi_value(ant_t *js, ant_value_t val, ffi_type *type, void *buffer); 101 94 static ant_value_t ffi_to_js_value(ant_t *js, void *val, ffi_type *type, const char *type_str); 102 - static void ffi_callback_handler(ffi_cif *cif, void *ret, void **args, void *user_data); 103 95 104 - ant_value_t ffi_library(ant_t *js) { 105 - ant_value_t ffi_obj = js_mkobj(js); 106 - 107 - js_set(js, ffi_obj, "dlopen", js_mkfun(ffi_dlopen)); 108 - js_set(js, ffi_obj, "alloc", js_mkfun(ffi_alloc_memory)); 109 - js_set(js, ffi_obj, "free", js_mkfun(ffi_free_memory)); 110 - js_set(js, ffi_obj, "read", js_mkfun(ffi_read_memory)); 111 - js_set(js, ffi_obj, "write", js_mkfun(ffi_write_memory)); 112 - js_set(js, ffi_obj, "pointer", js_mkfun(ffi_get_pointer)); 113 - js_set(js, ffi_obj, "callback", js_mkfun(ffi_create_callback)); 114 - js_set(js, ffi_obj, "freeCallback", js_mkfun(ffi_free_callback)); 115 - js_set(js, ffi_obj, "readPtr", js_mkfun(ffi_read_ptr)); 116 - 117 - const char *suffix; 118 - #ifdef __APPLE__ 119 - suffix = "dylib"; 120 - #elif defined(__linux__) 121 - suffix = "so"; 122 - #elif defined(_WIN32) 123 - suffix = "dll"; 124 - #else 125 - suffix = "so"; 126 - #endif 127 - js_set(js, ffi_obj, "suffix", js_mkstr(js, suffix, strlen(suffix))); 128 - 129 - ant_value_t ffi_types = js_mkobj(js); 130 - js_set(js, ffi_types, "void", js_mkstr(js, "void", 4)); 131 - js_set(js, ffi_types, "int8", js_mkstr(js, "int8", 4)); 132 - js_set(js, ffi_types, "int16", js_mkstr(js, "int16", 5)); 133 - js_set(js, ffi_types, "int", js_mkstr(js, "int", 3)); 134 - js_set(js, ffi_types, "int64", js_mkstr(js, "int64", 5)); 135 - js_set(js, ffi_types, "uint8", js_mkstr(js, "uint8", 5)); 136 - js_set(js, ffi_types, "uint16", js_mkstr(js, "uint16", 6)); 137 - js_set(js, ffi_types, "uint64", js_mkstr(js, "uint64", 6)); 138 - js_set(js, ffi_types, "float", js_mkstr(js, "float", 5)); 139 - js_set(js, ffi_types, "double", js_mkstr(js, "double", 6)); 140 - js_set(js, ffi_types, "pointer", js_mkstr(js, "pointer", 7)); 141 - js_set(js, ffi_types, "string", js_mkstr(js, "string", 6)); 142 - js_set(js, ffi_types, "spread", js_mkstr(js, "...", 3)); 143 - js_set(js, ffi_obj, "FFIType", ffi_types); 144 - js_set_sym(js, ffi_obj, get_toStringTag_sym(), js_mkstr(js, "FFI", 3)); 145 - 146 - return ffi_obj; 96 + static ffi_lib_t *ffi_get_library_this(ant_t *js, ant_value_t this_obj) { 97 + if (!is_object_type(this_obj) || !js_check_native_tag(this_obj, FFI_LIBRARY_NATIVE_TAG)) return NULL; 98 + return (ffi_lib_t *)js_get_native_ptr(this_obj); 147 99 } 148 100 149 101 static void ffi_init_array(void) { ··· 193 145 lib->handle = handle; 194 146 195 147 lib->js_obj = js_mkobj(js); 196 - js_set(js, lib->js_obj, "__lib_ptr", js_mknum((double)(uint64_t)lib)); 148 + js_set_native_ptr(lib->js_obj, lib); 149 + js_set_native_tag(lib->js_obj, FFI_LIBRARY_NATIVE_TAG); 150 + 197 151 js_set(js, lib->js_obj, "define", js_mkfun(ffi_define)); 198 152 js_set(js, lib->js_obj, "call", js_mkfun(ffi_lib_call)); 199 153 ··· 205 159 } 206 160 207 161 static ant_value_t ffi_define(ant_t *js, ant_value_t *args, int nargs) { 162 + ant_value_t this_obj; 163 + ffi_lib_t *lib; 164 + 208 165 if (nargs < 2 || vtype(args[0]) != T_STR) { 209 166 return js_mkerr(js, "define() requires function name string and signature"); 210 167 } 211 168 212 - ant_value_t this_obj = js_getthis(js); 213 - ant_value_t lib_ptr_val = js_get(js, this_obj, "__lib_ptr"); 214 - if (vtype(lib_ptr_val) != T_NUM) { 215 - return js_mkerr(js, "Invalid library object"); 216 - } 169 + this_obj = js_getthis(js); 170 + lib = ffi_get_library_this(js, this_obj); 171 + if (!lib) return js_mkerr(js, "Invalid library object"); 217 172 218 173 size_t func_name_len; 219 174 const char *func_name = js_getstr(js, args[0], &func_name_len); 220 175 221 176 ant_value_t sig = args[1]; 222 177 int sig_type = vtype(sig); 223 - if (sig_type == T_STR || sig_type == T_NUM || sig_type == T_NULL || 224 - sig_type == T_UNDEF) { 225 - return js_mkerr(js, 226 - "Signature must be an array [returnType, [argTypes...]] or " 227 - "an object {args: [...], returns: type}"); 228 - } 178 + 179 + if (sig_type == T_STR || sig_type == T_NUM || sig_type == T_NULL || sig_type == T_UNDEF) return js_mkerr(js, 180 + "Signature must be an array [returnType, [argTypes...]] or an object {args: [...], returns: type}" 181 + ); 229 182 230 183 const char *ret_type_str; 231 184 ant_value_t arg_types_arr; ··· 273 226 return js_mkerr(js, "Unknown return type: %s", ret_type_str); 274 227 } 275 228 276 - ffi_lib_t *lib = (ffi_lib_t *)(uint64_t)js_getnum(lib_ptr_val); 277 229 void *func_ptr = dlsym(lib->handle, func_name); 278 230 if (!func_ptr) { 279 231 return js_mkerr(js, "Function '%s' not found", func_name); ··· 353 305 354 306 static ant_value_t ffi_lib_call(ant_t *js, ant_value_t *args, int nargs) { 355 307 ant_value_t lib_obj = js_getthis(js); 356 - if (nargs < 1 || vtype(args[0]) != T_STR) 357 - return js_mkerr(js, "call() requires function name string"); 308 + 309 + if (!ffi_get_library_this(js, lib_obj)) return js_mkerr(js, "Invalid library object"); 310 + if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "call() requires function name string"); 358 311 359 312 size_t func_name_len; 360 313 const char *func_name = js_getstr(js, args[0], &func_name_len); 361 314 362 315 ant_value_t ffi_val = js_get(js, lib_obj, func_name); 363 316 int func_index = js_getffi(ffi_val); 364 - if (func_index < 0) { 365 - return js_mkerr(js, "Function '%s' not defined", func_name); 366 - } 317 + if (func_index < 0) return js_mkerr(js, "Function '%s' not defined", func_name); 367 318 368 319 return ffi_call_by_index(js, (unsigned int)func_index, args + 1, nargs - 1); 369 320 } ··· 994 945 return js_mkundef(); 995 946 } 996 947 948 + ant_value_t ffi_library(ant_t *js) { 949 + ant_value_t ffi_obj = js_mkobj(js); 950 + 951 + js_set(js, ffi_obj, "dlopen", js_mkfun(ffi_dlopen)); 952 + js_set(js, ffi_obj, "alloc", js_mkfun(ffi_alloc_memory)); 953 + js_set(js, ffi_obj, "free", js_mkfun(ffi_free_memory)); 954 + js_set(js, ffi_obj, "read", js_mkfun(ffi_read_memory)); 955 + js_set(js, ffi_obj, "write", js_mkfun(ffi_write_memory)); 956 + js_set(js, ffi_obj, "pointer", js_mkfun(ffi_get_pointer)); 957 + js_set(js, ffi_obj, "callback", js_mkfun(ffi_create_callback)); 958 + js_set(js, ffi_obj, "freeCallback", js_mkfun(ffi_free_callback)); 959 + js_set(js, ffi_obj, "readPtr", js_mkfun(ffi_read_ptr)); 960 + 961 + const char *suffix; 962 + #ifdef __APPLE__ 963 + suffix = "dylib"; 964 + #elif defined(__linux__) 965 + suffix = "so"; 966 + #elif defined(_WIN32) 967 + suffix = "dll"; 968 + #else 969 + suffix = "so"; 970 + #endif 971 + js_set(js, ffi_obj, "suffix", js_mkstr(js, suffix, strlen(suffix))); 972 + 973 + ant_value_t ffi_types = js_mkobj(js); 974 + js_set(js, ffi_types, "void", js_mkstr(js, "void", 4)); 975 + js_set(js, ffi_types, "int8", js_mkstr(js, "int8", 4)); 976 + js_set(js, ffi_types, "int16", js_mkstr(js, "int16", 5)); 977 + js_set(js, ffi_types, "int", js_mkstr(js, "int", 3)); 978 + js_set(js, ffi_types, "int64", js_mkstr(js, "int64", 5)); 979 + js_set(js, ffi_types, "uint8", js_mkstr(js, "uint8", 5)); 980 + js_set(js, ffi_types, "uint16", js_mkstr(js, "uint16", 6)); 981 + js_set(js, ffi_types, "uint64", js_mkstr(js, "uint64", 6)); 982 + js_set(js, ffi_types, "float", js_mkstr(js, "float", 5)); 983 + js_set(js, ffi_types, "double", js_mkstr(js, "double", 6)); 984 + js_set(js, ffi_types, "pointer", js_mkstr(js, "pointer", 7)); 985 + js_set(js, ffi_types, "string", js_mkstr(js, "string", 6)); 986 + js_set(js, ffi_types, "spread", js_mkstr(js, "...", 3)); 987 + js_set(js, ffi_obj, "FFIType", ffi_types); 988 + js_set_sym(js, ffi_obj, get_toStringTag_sym(), js_mkstr(js, "FFI", 3)); 989 + 990 + return ffi_obj; 991 + } 992 + 997 993 void gc_mark_ffi(ant_t *js, gc_mark_fn mark) { 998 994 pthread_mutex_lock(&ffi_callbacks_mutex); 999 995 ffi_callback_t *cb, *tmp; ··· 1002 998 } 1003 999 pthread_mutex_unlock(&ffi_callbacks_mutex); 1004 1000 } 1005 -
-1
src/modules/process.c
··· 1446 1446 const char *key; size_t key_len; ant_value_t value; 1447 1447 1448 1448 while (js_prop_iter_next(&iter, &key, &key_len, &value)) { 1449 - if (key_len >= 2 && key[0] == '_' && key[1] == '_') continue; 1450 1449 if (vtype(value) != T_STR) continue; 1451 1450 1452 1451 CSTR_BUF(buf, 256);
-2
src/modules/reflect.c
··· 110 110 const char *key; size_t key_len; ant_value_t value; 111 111 112 112 while (js_prop_iter_next(&iter, &key, &key_len, &value)) { 113 - if (key_len >= 9 && memcmp(key, STR_PROTO, STR_PROTO_LEN) == 0) continue; 114 - if (key_len >= 2 && key[0] == '_' && key[1] == '_') continue; 115 113 js_arr_push(js, keys_arr, js_mkstr(js, key, key_len)); 116 114 } 117 115
+52
tests/test_double_underscore_enumeration.mjs
··· 1 + function assert(condition, message) { 2 + if (!condition) throw new Error(message); 3 + } 4 + 5 + const plain = { __x: 1, visible: 2 }; 6 + assert( 7 + JSON.stringify(Object.keys(plain)) === JSON.stringify(['__x', 'visible']), 8 + 'Object.keys() should retain double-underscore own properties' 9 + ); 10 + assert( 11 + JSON.stringify(Object.entries(plain)) === JSON.stringify([['__x', 1], ['visible', 2]]), 12 + 'Object.entries() should retain double-underscore own properties' 13 + ); 14 + assert( 15 + JSON.stringify(Reflect.ownKeys(plain)) === JSON.stringify(['__x', 'visible']), 16 + 'Reflect.ownKeys() should retain double-underscore own properties' 17 + ); 18 + 19 + const forInKeys = []; 20 + for (const key in plain) forInKeys.push(key); 21 + assert( 22 + JSON.stringify(forInKeys) === JSON.stringify(['__x', 'visible']), 23 + 'for...in should retain double-underscore own properties' 24 + ); 25 + 26 + const ctorBytes = new Uint8Array([ 27 + 0, 97, 115, 109, 1, 0, 0, 0, 28 + 1, 5, 1, 96, 0, 1, 127, 29 + 3, 2, 1, 0, 30 + 7, 21, 1, 17, 95, 95, 119, 97, 115, 109, 95, 99, 97, 108, 108, 95, 99, 116, 111, 114, 115, 0, 0, 31 + 10, 6, 1, 4, 0, 65, 1, 11, 32 + ]); 33 + 34 + const module = new WebAssembly.Module(ctorBytes); 35 + const instance = new WebAssembly.Instance(module); 36 + assert( 37 + typeof instance.exports.__wasm_call_ctors === 'function', 38 + 'wasm export named __wasm_call_ctors should be callable' 39 + ); 40 + assert( 41 + JSON.stringify(Object.keys(instance.exports)) === JSON.stringify(['__wasm_call_ctors']), 42 + 'Object.keys(instance.exports) should retain __wasm_call_ctors' 43 + ); 44 + 45 + const copiedExports = Object.fromEntries(Object.entries(instance.exports)); 46 + assert( 47 + typeof copiedExports.__wasm_call_ctors === 'function', 48 + 'Object.entries(instance.exports) should preserve __wasm_call_ctors for Asyncify-style wrappers' 49 + ); 50 + assert(copiedExports.__wasm_call_ctors() === 1, 'copied wasm export should still execute'); 51 + 52 + console.log('double-underscore-enumeration:ok');
+17 -24
tests/test_primitive_wrappers.js
··· 5 5 6 6 function test(name, condition) { 7 7 if (condition) { 8 - console.log("โœ“", name); 8 + console.log('โœ“', name); 9 9 passed++; 10 10 } else { 11 - console.log("โœ—", name); 11 + console.log('โœ—', name); 12 12 failed++; 13 13 } 14 14 } 15 15 16 16 // String wrapper 17 - let s = new String("hello"); 18 - test("String wrapper typeof", typeof s === "object"); 19 - test("String wrapper + concat", s + " world" === "hello world"); 20 - test("String wrapper length", s.length === 5); 21 - test("String wrapper valueOf", s.valueOf() === "hello"); 17 + let s = new String('hello'); 18 + test('String wrapper typeof', typeof s === 'object'); 19 + test('String wrapper + concat', s + ' world' === 'hello world'); 20 + test('String wrapper length', s.length === 5); 21 + test('String wrapper valueOf', s.valueOf() === 'hello'); 22 22 23 23 // Number wrapper 24 24 let n = new Number(42); 25 - test("Number wrapper typeof", typeof n === "object"); 26 - test("Number wrapper + arithmetic", n + 8 === 50); 27 - test("Number wrapper valueOf", n.valueOf() === 42); 25 + test('Number wrapper typeof', typeof n === 'object'); 26 + test('Number wrapper + arithmetic', n + 8 === 50); 27 + test('Number wrapper valueOf', n.valueOf() === 42); 28 28 29 29 // Boolean wrapper 30 30 let b = new Boolean(true); 31 - test("Boolean wrapper typeof", typeof b === "object"); 32 - test("Boolean wrapper is truthy", !!b === true); 33 - test("Boolean wrapper valueOf", b.valueOf() === true); 34 - 35 - // Slot should be hidden from enumeration 36 - let sKeys = Object.keys(s); 37 - test("String keys excludes internal slot", !sKeys.includes("__primitive_value__")); 38 - 39 - let nKeys = Object.keys(n); 40 - test("Number keys excludes internal slot", !nKeys.includes("__primitive_value__")); 31 + test('Boolean wrapper typeof', typeof b === 'object'); 32 + test('Boolean wrapper is truthy', !!b === true); 33 + test('Boolean wrapper valueOf', b.valueOf() === true); 41 34 42 35 // Object() wrapping primitives 43 - let wrapped = Object("test"); 44 - test("Object(string) is object", typeof wrapped === "object"); 45 - test("Object(string) valueOf", wrapped.valueOf() === "test"); 36 + let wrapped = Object('test'); 37 + test('Object(string) is object', typeof wrapped === 'object'); 38 + test('Object(string) valueOf', wrapped.valueOf() === 'test'); 46 39 47 - console.log("\nResults:", passed, "passed,", failed, "failed"); 40 + console.log('\nResults:', passed, 'passed,', failed, 'failed');
+21
tests/test_process_env_double_underscore.cjs
··· 1 + function assert(condition, message) { 2 + if (!condition) throw new Error(message); 3 + } 4 + 5 + process.env.__ANT_ENV_DOUBLE = 'from-js'; 6 + 7 + assert(process.env.__ANT_ENV_DOUBLE === 'from-js', 'process.env getter should read __* assignments'); 8 + 9 + const keys = Object.keys(process.env); 10 + assert(keys.includes('__ANT_ENV_DOUBLE'), 'Object.keys(process.env) should include __* assignments'); 11 + 12 + const obj = process.env.toObject(); 13 + assert(obj.__ANT_ENV_DOUBLE === 'from-js', 'process.env.toObject() should include __* assignments'); 14 + 15 + const envString = process.env.toString(); 16 + assert( 17 + envString.split('\n').includes('__ANT_ENV_DOUBLE=from-js'), 18 + 'process.env.toString() should include __* assignments' 19 + ); 20 + 21 + console.log('process-env-double-underscore:ok');