Browse Source

default logger name only if argument is not given at all, distinguish from 'undefined' given as argument

pull/2/head
Sami Vaarala 11 years ago
parent
commit
fd50c7f52a
  1. 6
      src/duk_bi_logger.c
  2. 1
      src/genbuiltins.py

6
src/duk_bi_logger.c

@ -17,17 +17,21 @@ static const duk_uint8_t duk__log_level_strings[] = {
/* Constructor */
duk_ret_t duk_bi_logger_constructor(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_int_t nargs; /* FIXME: type */
/* Calling as a non-constructor is not meaningful. */
if (!duk_is_constructor_call(ctx)) {
return DUK_RET_TYPE_ERROR;
}
nargs = duk_get_top(ctx);
duk_set_top(ctx, 1);
duk_push_this(ctx);
/* [ name this ] */
if (duk_is_undefined(ctx, 0)) {
if (nargs == 0) {
/* Automatic defaulting of logger name from caller. */
if (thr->callstack_top >= 2) {
duk_activation *act_caller = thr->callstack + thr->callstack_top - 2;

1
src/genbuiltins.py

@ -1213,6 +1213,7 @@ bi_logger_constructor = {
'name': 'Logger',
'length': 1,
'varargs': True,
'native': 'duk_bi_logger_constructor',
'callable': True,
'constructable': True,

Loading…
Cancel
Save