From e563243ff15321f7aeef941ccab66d54f9e42039 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 13 Dec 2016 13:40:41 +0200 Subject: [PATCH 1/2] Add internal duk_push_hstring_empty() helper --- src-input/duk_api_internal.h | 1 + src-input/duk_api_stack.c | 10 ++++++++-- src-input/duk_api_string.c | 2 +- src-input/duk_bi_array.c | 2 +- src-input/duk_bi_function.c | 2 +- src-input/duk_bi_json.c | 2 +- src-input/duk_bi_regexp.c | 4 ++-- src-input/duk_bi_string.c | 2 +- src-input/duk_debugger.c | 2 +- src-input/duk_js_var.c | 2 +- 10 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src-input/duk_api_internal.h b/src-input/duk_api_internal.h index 5ebe946a..5de79d48 100644 --- a/src-input/duk_api_internal.h +++ b/src-input/duk_api_internal.h @@ -151,6 +151,7 @@ DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_with_class(duk_context *ctx, DUK_INTERNAL_DECL void duk_push_hstring(duk_context *ctx, duk_hstring *h); DUK_INTERNAL_DECL void duk_push_hstring_stridx(duk_context *ctx, duk_small_uint_t stridx); +DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_context *ctx); DUK_INTERNAL_DECL void duk_push_hobject(duk_context *ctx, duk_hobject *h); DUK_INTERNAL_DECL void duk_push_hbuffer(duk_context *ctx, duk_hbuffer *h); #define duk_push_hthread(ctx,h) \ diff --git a/src-input/duk_api_stack.c b/src-input/duk_api_stack.c index 0d74ef57..24c9f191 100644 --- a/src-input/duk_api_stack.c +++ b/src-input/duk_api_stack.c @@ -3641,8 +3641,8 @@ DUK_EXTERNAL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va /* special handling of fmt==NULL */ if (!fmt) { duk_hstring *h_str; - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); - h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); /* rely on interning, must be this string */ + duk_push_hstring_empty(ctx); + h_str = duk_known_hstring(ctx, -1); return (const char *) DUK_HSTRING_GET_DATA(h_str); } @@ -4420,6 +4420,12 @@ DUK_INTERNAL void duk_push_hstring_stridx(duk_context *ctx, duk_small_uint_t str duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx)); } +DUK_INTERNAL void duk_push_hstring_empty(duk_context *ctx) { + duk_hthread *thr = (duk_hthread *) ctx; + DUK_UNREF(thr); + duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, DUK_STRIDX_EMPTY_STRING)); +} + DUK_INTERNAL void duk_push_hobject(duk_context *ctx, duk_hobject *h) { duk_tval tv; DUK_ASSERT_CTX_VALID(ctx); diff --git a/src-input/duk_api_string.c b/src-input/duk_api_string.c index f7e7183f..a0e898e1 100644 --- a/src-input/duk_api_string.c +++ b/src-input/duk_api_string.c @@ -21,7 +21,7 @@ DUK_LOCAL void duk__concat_and_join_helper(duk_context *ctx, duk_idx_t count_in, return; } DUK_ASSERT(count_in == 0); - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); return; } count = (duk_uint_t) count_in; diff --git a/src-input/duk_bi_array.c b/src-input/duk_bi_array.c index cf4c4877..f6e2a44d 100644 --- a/src-input/duk_bi_array.c +++ b/src-input/duk_bi_array.c @@ -379,7 +379,7 @@ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_join_shared(duk_context *ctx) { duk_get_prop_index(ctx, 1, (duk_uarridx_t) idx); if (duk_is_null_or_undefined(ctx, -1)) { duk_pop(ctx); - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); } else { if (to_locale_string) { duk_to_object(ctx, -1); diff --git a/src-input/duk_bi_function.c b/src-input/duk_bi_function.c index 292d5cf2..665fe61d 100644 --- a/src-input/duk_bi_function.c +++ b/src-input/duk_bi_function.c @@ -387,7 +387,7 @@ DUK_INTERNAL duk_ret_t duk_bi_function_prototype_bind(duk_context *ctx) { * empty string. ES6 19.2.3.2. */ duk_pop(ctx); - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); } duk_concat(ctx, 2); duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); diff --git a/src-input/duk_bi_json.c b/src-input/duk_bi_json.c index d42c7793..076e1e7d 100644 --- a/src-input/duk_bi_json.c +++ b/src-input/duk_bi_json.c @@ -3099,7 +3099,7 @@ void duk_bi_json_stringify_helper(duk_context *ctx, /* serialize the wrapper with empty string key */ - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); /* [ ... buf loop (proplist) (gap) holder "" ] */ diff --git a/src-input/duk_bi_regexp.c b/src-input/duk_bi_regexp.c index 6c19a843..62b9277a 100644 --- a/src-input/duk_bi_regexp.c +++ b/src-input/duk_bi_regexp.c @@ -56,12 +56,12 @@ DUK_INTERNAL duk_ret_t duk_bi_regexp_constructor(duk_context *ctx) { } } else { if (duk_is_undefined(ctx, 0)) { - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); } else { duk_dup_0(ctx); } if (duk_is_undefined(ctx, 1)) { - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); } else { duk_dup_1(ctx); } diff --git a/src-input/duk_bi_string.c b/src-input/duk_bi_string.c index efb6a0fd..2691742d 100644 --- a/src-input/duk_bi_string.c +++ b/src-input/duk_bi_string.c @@ -25,7 +25,7 @@ DUK_INTERNAL duk_ret_t duk_bi_string_constructor(duk_context *ctx) { */ if (duk_get_top(ctx) == 0) { - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); } else { duk_to_string(ctx, 0); } diff --git a/src-input/duk_debugger.c b/src-input/duk_debugger.c index ab11e36e..8a9eec0d 100644 --- a/src-input/duk_debugger.c +++ b/src-input/duk_debugger.c @@ -385,7 +385,7 @@ DUK_INTERNAL duk_hstring *duk_debug_read_hstring(duk_hthread *thr) { fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode int")); DUK__SET_CONN_BROKEN(thr, 1); - duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* always push some string */ + duk_push_hstring_empty(ctx); /* always push some string */ return duk_require_hstring(ctx, -1); } diff --git a/src-input/duk_js_var.c b/src-input/duk_js_var.c index 587ed542..ce0a44a9 100644 --- a/src-input/duk_js_var.c +++ b/src-input/duk_js_var.c @@ -441,7 +441,7 @@ void duk_js_push_closure(duk_hthread *thr, /* [ ... closure template undefined ] */ /* XXX: anonymous function name? empty string in e.g. V8 */ duk_pop(ctx); - duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); + duk_push_hstring_empty(ctx); } duk_xdef_prop_stridx_short(ctx, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> [ ... closure template ] */ #endif From 1331bdc78e8e16a881524ebab150da3f5b34a06c Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 13 Dec 2016 17:14:04 +0200 Subject: [PATCH 2/2] Releases: duk_push_hstring_empty() --- RELEASES.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASES.rst b/RELEASES.rst index 71961ffe..ef1e93c6 100644 --- a/RELEASES.rst +++ b/RELEASES.rst @@ -2252,7 +2252,8 @@ Planned bytecode allocation in Ecmascript compiler for low memory targets (GH-1146); packed arguments for some internal helper calls (GH-1158, GH-1172); misc internal helpers to reduce call site size (GH-1166, GH-1173); config options - for function .name and .fileName control (GH-1153) + for function .name and .fileName control (GH-1153); internal helper + duk_push_hstring_empty() (GH-1186) * Internal change: rework shared internal string handling so that shared strings are plain string constants used in macro values, rather than