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 object prototype

+98 -99
+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.39') 99 + version_conf.set('ANT_VERSION', '0.3.2.41') 100 100 version_conf.set('ANT_GIT_HASH', git_hash) 101 101 version_conf.set('ANT_BUILD_DATE', build_date) 102 102
+97 -98
src/ant.c
··· 6297 6297 res = call_c(js, (jsval_t(*)(struct js *, jsval_t *, int)) vdata(cfunc_slot)); 6298 6298 js->current_func = saved_func; 6299 6299 } else { 6300 + jsval_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); 6301 + if (vtype(builtin_slot) == T_NUM && tod(builtin_slot) == BUILTIN_OBJECT) res = call_c(js, builtin_Object); else { 6300 6302 jsval_t code_val = get_slot(js, func_obj, SLOT_CODE); 6301 6303 if (vtype(code_val) != T_STR) return js_mkerr(js, "function has no code"); 6302 6304 jsval_t closure_scope = get_slot(js, func_obj, SLOT_SCOPE); ··· 6356 6358 } 6357 6359 } 6358 6360 6359 - jsval_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); 6360 - if (vtype(builtin_slot) == T_NUM && tod(builtin_slot) == BUILTIN_OBJECT) res = call_c(js, builtin_Object); else { 6361 - static char full_func_name[256]; 6362 - const char *func_name = NULL; 6363 - const char *this_name = NULL; 6361 + static char full_func_name[256]; 6362 + const char *func_name = NULL; 6363 + const char *this_name = NULL; 6364 + 6365 + if (vtype(nfe_name_val) == T_STR) { 6366 + jsoff_t name_len, name_offset = vstr(js, nfe_name_val, &name_len); 6367 + func_name = (const char *)&js->mem[name_offset]; 6368 + } 6369 + 6370 + if (vtype(target_this) != T_OBJ) goto skip_constructor_name; 6371 + 6372 + jsoff_t ctor_off = lkp_interned(js, target_this, INTERN_CONSTRUCTOR, 11); 6373 + if (ctor_off == 0) goto default_object_name; 6374 + 6375 + jsval_t ctor_val = resolveprop(js, mkval(T_PROP, ctor_off)); 6376 + if (vtype(ctor_val) != T_FUNC) goto default_object_name; 6377 + 6378 + jsval_t ctor_obj = mkval(T_OBJ, vdata(ctor_val)); 6379 + jsoff_t ctor_name_off = lkp(js, ctor_obj, "name", 4); 6380 + if (ctor_name_off == 0) goto default_object_name; 6381 + 6382 + jsval_t ctor_name_val = resolveprop(js, mkval(T_PROP, ctor_name_off)); 6383 + if (vtype(ctor_name_val) != T_STR) goto default_object_name; 6384 + 6385 + jsoff_t ctor_name_len, ctor_name_offset = vstr(js, ctor_name_val, &ctor_name_len); 6386 + this_name = (const char *)&js->mem[ctor_name_offset]; 6387 + if (this_name && strlen(this_name) > 0) goto skip_constructor_name; 6388 + 6389 + default_object_name: 6390 + this_name = "Object"; 6391 + 6392 + skip_constructor_name: 6393 + 6394 + const char *final_name; 6395 + if (this_name && func_name) { 6396 + snprintf(full_func_name, sizeof(full_func_name), "%s.%s", this_name, func_name); 6397 + final_name = full_func_name; 6398 + } else if (func_name) { 6399 + final_name = func_name; 6400 + } else if (this_name) { 6401 + snprintf(full_func_name, sizeof(full_func_name), "%s.<anonymous>", this_name); 6402 + final_name = full_func_name; 6403 + } else { 6404 + final_name = "<anonymous>"; 6405 + } 6406 + 6407 + push_call_frame( 6408 + js->filename, 6409 + final_name, 6410 + code, pos 6411 + ); 6412 + 6413 + jsval_t saved_func = js->current_func; 6414 + js->current_func = func; 6415 + js->nogc = (jsoff_t) (fnoff - sizeof(jsoff_t)); 6416 + 6417 + if (is_arrow || is_bound) { 6418 + pop_this(); 6419 + push_this(captured_this); 6420 + } 6421 + 6422 + jsval_t count_val = get_slot(js, func_obj, SLOT_FIELD_COUNT); 6423 + if (vtype(count_val) != T_NUM || vtype(target_this) != T_OBJ) goto skip_fields; 6424 + 6425 + int field_count = (int)tod(count_val); 6426 + jsval_t src_val = get_slot(js, func_obj, SLOT_SOURCE); 6427 + jsval_t fields_meta = get_slot(js, func_obj, SLOT_FIELDS); 6428 + if (vtype(src_val) == T_UNDEF || vtype(fields_meta) == T_UNDEF) goto skip_fields; 6429 + 6430 + jsoff_t src_len, src_ptr_off = vstr(js, src_val, &src_len); 6431 + const char *source = (const char *)(&js->mem[src_ptr_off]); 6432 + 6433 + jsoff_t meta_len, meta_ptr_off = vstr(js, fields_meta, &meta_len); 6434 + const jsoff_t *metadata = (const jsoff_t *)(&js->mem[meta_ptr_off]); 6435 + 6436 + for (int i = 0; i < field_count; i++) { 6437 + jsoff_t name_off = metadata[i * 4 + 0]; 6438 + jsoff_t name_len = metadata[i * 4 + 1]; 6439 + jsoff_t init_start = metadata[i * 4 + 2]; 6440 + jsoff_t init_end = metadata[i * 4 + 3]; 6364 6441 6365 - if (vtype(nfe_name_val) == T_STR) { 6366 - jsoff_t name_len, name_offset = vstr(js, nfe_name_val, &name_len); 6367 - func_name = (const char *)&js->mem[name_offset]; 6442 + jsval_t fname = js_mkstr(js, &source[name_off], name_len); 6443 + if (is_err(fname)) { 6444 + js->current_func = saved_func; 6445 + pop_call_frame(); 6446 + return fname; 6368 6447 } 6369 6448 6370 - if (vtype(target_this) != T_OBJ) goto skip_constructor_name; 6371 - 6372 - jsoff_t ctor_off = lkp_interned(js, target_this, INTERN_CONSTRUCTOR, 11); 6373 - if (ctor_off == 0) goto default_object_name; 6374 - 6375 - jsval_t ctor_val = resolveprop(js, mkval(T_PROP, ctor_off)); 6376 - if (vtype(ctor_val) != T_FUNC) goto default_object_name; 6377 - 6378 - jsval_t ctor_obj = mkval(T_OBJ, vdata(ctor_val)); 6379 - jsoff_t ctor_name_off = lkp(js, ctor_obj, "name", 4); 6380 - if (ctor_name_off == 0) goto default_object_name; 6381 - 6382 - jsval_t ctor_name_val = resolveprop(js, mkval(T_PROP, ctor_name_off)); 6383 - if (vtype(ctor_name_val) != T_STR) goto default_object_name; 6384 - 6385 - jsoff_t ctor_name_len, ctor_name_offset = vstr(js, ctor_name_val, &ctor_name_len); 6386 - this_name = (const char *)&js->mem[ctor_name_offset]; 6387 - if (this_name && strlen(this_name) > 0) goto skip_constructor_name; 6388 - 6389 - default_object_name: 6390 - this_name = "Object"; 6391 - 6392 - skip_constructor_name: 6393 - 6394 - const char *final_name; 6395 - if (this_name && func_name) { 6396 - snprintf(full_func_name, sizeof(full_func_name), "%s.%s", this_name, func_name); 6397 - final_name = full_func_name; 6398 - } else if (func_name) { 6399 - final_name = func_name; 6400 - } else if (this_name) { 6401 - snprintf(full_func_name, sizeof(full_func_name), "%s.<anonymous>", this_name); 6402 - final_name = full_func_name; 6403 - } else { 6404 - final_name = "<anonymous>"; 6449 + jsval_t field_val = js_mkundef(); 6450 + if (init_start > 0 && init_end > init_start) { 6451 + field_val = js_eval_str(js, &source[init_start], init_end - init_start); 6452 + field_val = resolveprop(js, field_val); 6405 6453 } 6406 6454 6407 - push_call_frame( 6408 - js->filename, 6409 - final_name, 6410 - code, pos 6411 - ); 6412 - 6413 - jsval_t saved_func = js->current_func; 6414 - js->current_func = func; 6415 - js->nogc = (jsoff_t) (fnoff - sizeof(jsoff_t)); 6416 - 6417 - if (is_arrow || is_bound) { 6418 - pop_this(); 6419 - push_this(captured_this); 6455 + jsval_t set_res = setprop(js, target_this, fname, field_val); 6456 + if (is_err(set_res)) { 6457 + js->current_func = saved_func; 6458 + pop_call_frame(); 6459 + return set_res; 6420 6460 } 6421 - 6422 - jsval_t count_val = get_slot(js, func_obj, SLOT_FIELD_COUNT); 6423 - if (vtype(count_val) != T_NUM || vtype(target_this) != T_OBJ) goto skip_fields; 6424 - 6425 - int field_count = (int)tod(count_val); 6426 - jsval_t src_val = get_slot(js, func_obj, SLOT_SOURCE); 6427 - jsval_t fields_meta = get_slot(js, func_obj, SLOT_FIELDS); 6428 - if (vtype(src_val) == T_UNDEF || vtype(fields_meta) == T_UNDEF) goto skip_fields; 6429 - 6430 - jsoff_t src_len, src_ptr_off = vstr(js, src_val, &src_len); 6431 - const char *source = (const char *)(&js->mem[src_ptr_off]); 6432 - 6433 - jsoff_t meta_len, meta_ptr_off = vstr(js, fields_meta, &meta_len); 6434 - const jsoff_t *metadata = (const jsoff_t *)(&js->mem[meta_ptr_off]); 6435 - 6436 - for (int i = 0; i < field_count; i++) { 6437 - jsoff_t name_off = metadata[i * 4 + 0]; 6438 - jsoff_t name_len = metadata[i * 4 + 1]; 6439 - jsoff_t init_start = metadata[i * 4 + 2]; 6440 - jsoff_t init_end = metadata[i * 4 + 3]; 6441 - 6442 - jsval_t fname = js_mkstr(js, &source[name_off], name_len); 6443 - if (is_err(fname)) { 6444 - js->current_func = saved_func; 6445 - pop_call_frame(); 6446 - return fname; 6447 - } 6448 - 6449 - jsval_t field_val = js_mkundef(); 6450 - if (init_start > 0 && init_end > init_start) { 6451 - field_val = js_eval_str(js, &source[init_start], init_end - init_start); 6452 - field_val = resolveprop(js, field_val); 6453 - } 6454 - 6455 - jsval_t set_res = setprop(js, target_this, fname, field_val); 6456 - if (is_err(set_res)) { 6457 - js->current_func = saved_func; 6458 - pop_call_frame(); 6459 - return set_res; 6460 - } 6461 - } 6461 + } 6462 6462 skip_fields: 6463 6463 if (is_async) { 6464 6464 res = start_async_in_coroutine(js, code_str, fnlen, closure_scope, bound_args, bound_argc); ··· 6467 6467 res = call_js_internal(js, code_str, fnlen, closure_scope, bound_args, bound_argc, func); 6468 6468 pop_call_frame(); 6469 6469 } 6470 - 6471 6470 js->current_func = saved_func; 6472 6471 } 6473 6472 }