From fec3eea91bfe091a730fe9d82be26d3044f7e10b Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Thu, 24 Oct 2013 22:23:14 +0300 Subject: [PATCH] set error 'message' to a numeric code if a string code not given; useful for minimized builds and good default for C code in general --- src/duk_api.c | 12 ++++++++++-- src/genstrings.py | 4 +--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/duk_api.c b/src/duk_api.c index 4fb4752f..adf8c8bb 100644 --- a/src/duk_api.c +++ b/src/duk_api.c @@ -2835,11 +2835,19 @@ static int duk_push_error_object_vsprintf(duk_context *ctx, int err_code, const if (fmt) { duk_push_vsprintf(ctx, fmt, ap); duk_def_prop_stridx(ctx, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC); + } else { + /* If no explicit message given, put error code into message field + * (as a number). This is not fully in keeping with the Ecmascript + * error model because messages are supposed to be strings (Error + * constructors use ToString() on their argument). However, it's + * probably more useful than having a separate 'code' property. + */ + duk_push_int(ctx, err_code); + duk_def_prop_stridx(ctx, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC); } #if 0 - /* FIXME: disabled for now, not sure this is a useful property */ - /* 'code' property is custom */ + /* Disabled for now, not sure this is a useful property */ duk_push_int(ctx, err_code); duk_def_prop_stridx(ctx, -2, DUK_STRIDX_CODE, DUK_PROPDESC_FLAGS_WC); #endif diff --git a/src/genstrings.py b/src/genstrings.py index 5d90a5b5..7da9b59c 100644 --- a/src/genstrings.py +++ b/src/genstrings.py @@ -478,9 +478,7 @@ duk_string_list = [ mkstr("pc", custom=True), mkstr("fileName", custom=True), mkstr("lineNumber", custom=True), - mkstr("isNative", custom=True), - mkstr("code", custom=True), - mkstr("cause", custom=True), + #mkstr("code", custom=True), mkstr("tracedata", custom=True), # non-standard function instance properties