Browse Source

Merge pull request #1653 from svaarala/longer-string-summaries

Make string summarization longer (32 -> 96) for error messages
pull/1657/head
Sami Vaarala 7 years ago
committed by GitHub
parent
commit
c36101f3c5
  1. 3
      RELEASES.rst
  2. 27
      src-input/duk_api_stack.c

3
RELEASES.rst

@ -2978,6 +2978,9 @@ Planned
(64 -> 128 bytes) and make it configurable via DUK_USE_FATAL_MAXLEN
(GH-1652)
* Make error message summary strings longer (32 -> 96 character) to better
capture error messages for e.g. uncaught errors (GH-1653)
* Fix incorrect handling of register bound unary operation target for
unary minus, unary plus, and bitwise NOT (GH-1623, GH-1624)

27
src-input/duk_api_stack.c

@ -6299,16 +6299,19 @@ DUK_INTERNAL void duk_push_string_funcptr(duk_hthread *thr, duk_uint8_t *ptr, du
* and is not intended to be fast (but small and safe).
*/
#define DUK__READABLE_STRING_MAXCHARS 32
/* String limits for summary strings. */
#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */
#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */
#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */
/* String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
*/
DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring *h_input) {
DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring *h_input, duk_small_uint_t maxchars) {
const duk_uint8_t *p, *p_start, *p_end;
duk_uint8_t buf[DUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_STRING_MAXCHARS +
duk_uint8_t buf[DUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS +
2 /*quotes*/ + 3 /*periods*/];
duk_uint8_t *q;
duk_ucodepoint_t cp;
@ -6316,6 +6319,7 @@ DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring
DUK_ASSERT_CTX_VALID(thr);
DUK_ASSERT(h_input != NULL);
DUK_ASSERT(maxchars <= DUK__READABLE_SUMMARY_MAXCHARS);
p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input);
p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
@ -6328,7 +6332,7 @@ DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring
if (p >= p_end) {
break;
}
if (nchars == DUK__READABLE_STRING_MAXCHARS) {
if (nchars == maxchars) {
*q++ = (duk_uint8_t) DUK_ASC_PERIOD;
*q++ = (duk_uint8_t) DUK_ASC_PERIOD;
*q++ = (duk_uint8_t) DUK_ASC_PERIOD;
@ -6373,12 +6377,12 @@ DUK_LOCAL const char *duk__push_string_tval_readable(duk_hthread *thr, duk_tval
duk_push_string(thr, "[Symbol ");
duk_push_string(thr, duk__get_symbol_type_string(h));
duk_push_string(thr, " ");
duk__push_hstring_readable_unicode(thr, h);
duk__push_hstring_readable_unicode(thr, h, DUK__READABLE_STRING_MAXCHARS);
duk_push_string(thr, "]");
duk_concat(thr, 5);
break;
}
duk__push_hstring_readable_unicode(thr, h);
duk__push_hstring_readable_unicode(thr, h, DUK__READABLE_STRING_MAXCHARS);
break;
}
case DUK_TAG_OBJECT: {
@ -6396,13 +6400,12 @@ DUK_LOCAL const char *duk__push_string_tval_readable(duk_hthread *thr, duk_tval
*/
duk_tval *tv_msg;
tv_msg = duk_hobject_find_existing_entry_tval_ptr(thr->heap, h, DUK_HTHREAD_STRING_MESSAGE(thr));
if (tv_msg) {
/* It's important this summarization is
* not error aware to avoid unlimited
* recursion when the .message property
* is e.g. another error.
if (tv_msg != NULL && DUK_TVAL_IS_STRING(tv_msg)) {
/* It's critical to avoid recursion so
* only summarize a string .message.
*/
return duk_push_string_tval_readable(thr, tv_msg);
duk__push_hstring_readable_unicode(thr, DUK_TVAL_GET_STRING(tv_msg), DUK__READABLE_ERRMSG_MAXCHARS);
break;
}
}
duk_push_class_string_tval(thr, tv);

Loading…
Cancel
Save