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 native code function representation

+26 -10
+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.41') 99 + version_conf.set('ANT_VERSION', '0.3.2.42') 100 100 version_conf.set('ANT_GIT_HASH', git_hash) 101 101 version_conf.set('ANT_BUILD_DATE', build_date) 102 102
+24 -8
src/ant.c
··· 2104 2104 2105 2105 jsval_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); 2106 2106 if (vtype(builtin_slot) == T_NUM) { 2107 - return cpy(buf, len, "[Function (native)]", 19); 2107 + return cpy(buf, len, "[native code]", 13); 2108 2108 } 2109 2109 2110 2110 if (vtype(code_slot) != T_STR) { 2111 2111 jsval_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); 2112 - if (vtype(cfunc_slot) == T_CFUNC) return cpy(buf, len, "[Function (native)]", 19); 2112 + if (vtype(cfunc_slot) == T_CFUNC) return cpy(buf, len, "[native code]", 13); 2113 2113 if (name && name_len > 0) { 2114 2114 size_t n = cpy(buf, len, "[Function: ", 11); 2115 2115 n += cpy(buf + n, len - n, name, name_len); ··· 2409 2409 case T_BIGINT: return strbigint(js, value, buf, len); 2410 2410 case T_PROMISE: return strpromise(js, value, buf, len); 2411 2411 case T_FUNC: return strfunc(js, value, buf, len); 2412 - case T_CFUNC: return cpy(buf, len, "[Function (native)]", 19); 2413 - case T_FFI: return cpy(buf, len, "[Function (native)]", 19); 2412 + case T_CFUNC: return cpy(buf, len, "[native code]", 13); 2413 + case T_FFI: return cpy(buf, len, "[native code]", 13); 2414 2414 case T_PROP: return (size_t) snprintf(buf, len, "PROP@%lu", (unsigned long) vdata(value)); 2415 2415 default: return (size_t) snprintf(buf, len, "VTYPE%d", vtype(value)); 2416 2416 } ··· 11997 11997 return len; 11998 11998 } 11999 11999 12000 + static jsval_t builtin_function_toString(struct js *js, jsval_t *args, int nargs) { 12001 + (void) args; (void) nargs; 12002 + jsval_t func = js->this_val; 12003 + uint8_t t = vtype(func); 12004 + 12005 + if (t != T_FUNC && t != T_CFUNC) { 12006 + return js_mkerr_typed(js, JS_ERR_TYPE, "Function.prototype.toString requires that 'this' be a Function"); 12007 + } 12008 + if (t == T_CFUNC) return ANT_STRING("[native code]"); 12009 + 12010 + char buf[256]; 12011 + size_t len = strfunc(js, func, buf, sizeof(buf)); 12012 + return js_mkstr(js, buf, len); 12013 + } 12014 + 12000 12015 static jsval_t builtin_function_apply(struct js *js, jsval_t *args, int nargs) { 12001 12016 jsval_t func = js->this_val; 12002 12017 if (vtype(func) != T_FUNC && vtype(func) != T_CFUNC) { 12003 - return js_mkerr(js, "apply requires a function"); 12018 + return js_mkerr_typed(js, JS_ERR_TYPE, "Function.prototype.apply requires that 'this' be a Function"); 12004 12019 } 12005 12020 12006 12021 jsval_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); ··· 20610 20625 jsval_t function_proto_obj = js_mkobj(js); 20611 20626 set_proto(js, function_proto_obj, object_proto); 20612 20627 set_slot(js, function_proto_obj, SLOT_CFUNC, js_mkfun(builtin_function_empty)); 20613 - setprop(js, function_proto_obj, js_mkstr(js, "call", 4), js_mkfun(builtin_function_call)); 20614 - setprop(js, function_proto_obj, js_mkstr(js, "apply", 5), js_mkfun(builtin_function_apply)); 20615 - setprop(js, function_proto_obj, js_mkstr(js, "bind", 4), js_mkfun(builtin_function_bind)); 20628 + setprop(js, function_proto_obj, ANT_STRING("call"), js_mkfun(builtin_function_call)); 20629 + setprop(js, function_proto_obj, ANT_STRING("apply"), js_mkfun(builtin_function_apply)); 20630 + setprop(js, function_proto_obj, ANT_STRING("bind"), js_mkfun(builtin_function_bind)); 20631 + setprop(js, function_proto_obj, ANT_STRING("toString"), js_mkfun(builtin_function_toString)); 20616 20632 jsval_t function_proto = mkval(T_FUNC, vdata(function_proto_obj)); 20617 20633 20618 20634 jsval_t array_proto = js_mkobj(js);
+1 -1
src/modules/io.c
··· 117 117 continue; 118 118 } 119 119 120 - if (*p == '[' && strncmp(p, "[Function", 9) == 0) { 120 + if (*p == '[' && (strncmp(p, "[Function", 9) == 0 || strncmp(p, "[native code]", 13) == 0)) { 121 121 io_puts(JSON_FUNC, stream); 122 122 while (*p && *p != ']') io_putc(*p++, stream); 123 123 if (*p == ']') io_putc(*p, stream);