Browse Source

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

pull/1/head
Sami Vaarala 11 years ago
parent
commit
fec3eea91b
  1. 12
      src/duk_api.c
  2. 4
      src/genstrings.py

12
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

4
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

Loading…
Cancel
Save