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.

add generator string tag

+11 -7
+9 -5
src/ant.c
··· 2322 2322 size_t anon_len; 2323 2323 }; 2324 2324 2325 + // TODO: migrate to Symbol.inspect 2325 2326 static const struct func_format formats[] = { 2326 - [0] = { "[Function: ", 11, "[Function (anonymous)]", 22 }, 2327 - [1] = { "[AsyncFunction: ", 16, "[AsyncFunction (anonymous)]", 27 }, 2327 + [0] = { "[Function: ", 11, "[Function (anonymous)]", 22 }, 2328 + [1] = { "[AsyncFunction: ", 16, "[AsyncFunction (anonymous)]", 27 }, 2329 + [2] = { "[GeneratorFunction: ", 20, "[GeneratorFunction (anonymous)]", 31 }, 2330 + [3] = { "[AsyncGeneratorFunction: ", 25, "[AsyncGeneratorFunction (anonymous)]", 36 }, 2328 2331 }; 2329 2332 2330 2333 // todo: make it work with bytecode NAME ··· 2336 2339 ant_value_t code_slot = get_slot(func_obj, SLOT_CODE); 2337 2340 ant_value_t builtin_slot = get_slot(func_obj, SLOT_BUILTIN); 2338 2341 ant_value_t async_slot = get_slot(func_obj, SLOT_ASYNC); 2342 + sv_closure_t *closure = js_func_closure(value); 2339 2343 2340 2344 bool is_async = (async_slot == js_true); 2341 2345 bool has_code = (vtype(code_slot) == T_NTARG); 2346 + bool is_generator = closure != NULL && closure->func != NULL && closure->func->is_generator; 2342 2347 2343 - const struct func_format *fmt = &formats[is_async]; 2348 + const struct func_format *fmt = &formats[(is_generator ? 2 : 0) | (is_async ? 1 : 0)]; 2344 2349 2345 2350 if (vtype(builtin_slot) == T_NUM) { 2346 2351 if (name && name_len > 0) { ··· 3053 3058 3054 3059 ant_value_t js_newobj(ant_t *js) { 3055 3060 ant_value_t obj = mkobj(js, 0); 3056 - ant_value_t proto = js->sym.object_proto; 3057 - if (vtype(proto) == T_OBJ) js_set_proto_init(obj, proto); 3061 + js_set_proto_init(obj, js->sym.object_proto); 3058 3062 return obj; 3059 3063 } 3060 3064
+2 -2
src/modules/generator.c
··· 44 44 ); 45 45 46 46 static ant_value_t generator_result(ant_t *js, bool done, ant_value_t value) { 47 - ant_value_t result = js_mkobj(js); 48 - js_set(js, result, "done", js_bool(done)); 47 + ant_value_t result = js_newobj(js); 49 48 js_set(js, result, "value", value); 49 + js_set(js, result, "done", js_bool(done)); 50 50 return result; 51 51 } 52 52