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 util.deprecate

+32
+32
src/modules/util.c
··· 378 378 return promise; 379 379 } 380 380 381 + static ant_value_t util_deprecated_call(ant_t *js, ant_value_t *args, int nargs) { 382 + ant_value_t fn = js_getcurrentfunc(js); 383 + ant_value_t ctx = js_get_slot(fn, SLOT_DATA); 384 + if (!is_object_type(ctx)) return js_mkundef(); 385 + 386 + ant_value_t warned = js_get_slot(ctx, SLOT_SETTLED); 387 + if (!(vtype(warned) == T_BOOL && warned == js_true)) { 388 + js_set_slot(ctx, SLOT_SETTLED, js_true); 389 + ant_value_t msg_val = js_get(js, ctx, "msg"); 390 + const char *msg = js_getstr(js, msg_val, NULL); 391 + if (msg) fprintf(stderr, "DeprecationWarning: %s\n", msg); 392 + } 393 + 394 + ant_value_t original = js_get_slot(ctx, SLOT_DATA); 395 + ant_value_t this_arg = js_getthis(js); 396 + return sv_vm_call(js->vm, js, original, this_arg, args, nargs, NULL, false); 397 + } 398 + 399 + static ant_value_t util_deprecate(ant_t *js, ant_value_t *args, int nargs) { 400 + if (nargs < 1 || !is_callable(args[0])) { 401 + return js_mkerr(js, "deprecate(fn, msg) requires a function"); 402 + } 403 + 404 + ant_value_t ctx = js_mkobj(js); 405 + js_set_slot(ctx, SLOT_DATA, args[0]); 406 + js_set_slot(ctx, SLOT_SETTLED, js_false); 407 + if (nargs >= 2) js_set(js, ctx, "msg", args[1]); 408 + 409 + return js_heavy_mkfun(js, util_deprecated_call, ctx); 410 + } 411 + 381 412 static ant_value_t util_promisify(ant_t *js, ant_value_t *args, int nargs) { 382 413 if (nargs < 1 || !is_callable(args[0])) { 383 414 return js_mkerr(js, "promisify(fn) requires a function"); ··· 391 422 js_set(js, lib, "format", js_mkfun(util_format)); 392 423 js_set(js, lib, "formatWithOptions", js_mkfun(util_format_with_options)); 393 424 js_set(js, lib, "inspect", js_mkfun(util_inspect)); 425 + js_set(js, lib, "deprecate", js_mkfun(util_deprecate)); 394 426 js_set(js, lib, "promisify", js_mkfun(util_promisify)); 395 427 js_set(js, lib, "stripVTControlCharacters", js_mkfun(util_strip_vt_control_characters)); 396 428 js_set(js, lib, "styleText", js_mkfun(util_style_text));