Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_api_stack.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Macros

#define DUK__CHECK_SPACE()
 
#define DUK__PACK_ARGS(classnum, protobidx, elemtype, elemshift, isview)    (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (isview))
 
#define DUK__READABLE_STRING_MAXCHARS   32
 

Typedefs

typedef duk_double_t(* duk__toint_coercer) (duk_hthread *thr, duk_tval *tv)
 

Functions

DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw (duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_uint_t flags)
 
DUK_LOCAL_DECL duk_heaphdrduk__get_tagged_heaphdr_raw (duk_context *ctx, duk_idx_t index, duk_uint_t tag)
 
DUK_LOCAL duk_int_t duk__api_coerce_d2i (duk_context *ctx, duk_idx_t index, duk_bool_t require)
 
DUK_LOCAL duk_uint_t duk__api_coerce_d2ui (duk_context *ctx, duk_idx_t index, duk_bool_t require)
 
DUK_EXTERNAL duk_idx_t duk_normalize_index (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_idx_t duk_require_normalize_index (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_tvalduk_get_tval (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_tvalduk_require_tval (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_valid_index (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_require_valid_index (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_idx_t duk_get_top (duk_context *ctx)
 
DUK_EXTERNAL void duk_set_top (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_idx_t duk_get_top_index (duk_context *ctx)
 
DUK_EXTERNAL duk_idx_t duk_require_top_index (duk_context *ctx)
 
DUK_LOCAL duk_bool_t duk__resize_valstack (duk_context *ctx, duk_size_t new_size)
 
DUK_INTERNAL duk_bool_t duk_valstack_resize_raw (duk_context *ctx, duk_size_t min_new_size, duk_small_uint_t flags)
 
DUK_EXTERNAL duk_bool_t duk_check_stack (duk_context *ctx, duk_idx_t extra)
 
DUK_EXTERNAL void duk_require_stack (duk_context *ctx, duk_idx_t extra)
 
DUK_EXTERNAL duk_bool_t duk_check_stack_top (duk_context *ctx, duk_idx_t top)
 
DUK_EXTERNAL void duk_require_stack_top (duk_context *ctx, duk_idx_t top)
 
DUK_EXTERNAL void duk_swap (duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
 
DUK_EXTERNAL void duk_swap_top (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_dup (duk_context *ctx, duk_idx_t from_index)
 
DUK_EXTERNAL void duk_dup_top (duk_context *ctx)
 
DUK_EXTERNAL void duk_insert (duk_context *ctx, duk_idx_t to_index)
 
DUK_EXTERNAL void duk_replace (duk_context *ctx, duk_idx_t to_index)
 
DUK_EXTERNAL void duk_copy (duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index)
 
DUK_EXTERNAL void duk_remove (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_xcopymove_raw (duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy)
 
DUK_EXTERNAL void duk_require_undefined (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_require_null (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_get_boolean (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_require_boolean (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_double_t duk_get_number (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_double_t duk_require_number (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_int_t duk_get_int (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_uint_t duk_get_uint (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_int_t duk_require_int (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_uint_t duk_require_uint (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL const char * duk_get_lstring (duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
 
DUK_EXTERNAL const char * duk_require_lstring (duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
 
DUK_EXTERNAL const char * duk_get_string (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL const char * duk_require_string (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void * duk_get_pointer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void * duk_require_pointer (duk_context *ctx, duk_idx_t index)
 
DUK_LOCAL void * duk__get_buffer_helper (duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_bool_t throw_flag)
 
DUK_EXTERNAL void * duk_get_buffer (duk_context *ctx, duk_idx_t index, duk_size_t *out_size)
 
DUK_EXTERNAL void * duk_require_buffer (duk_context *ctx, duk_idx_t index, duk_size_t *out_size)
 
DUK_LOCAL void * duk__get_buffer_data_helper (duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_bool_t throw_flag)
 
DUK_EXTERNAL void * duk_get_buffer_data (duk_context *ctx, duk_idx_t index, duk_size_t *out_size)
 
DUK_EXTERNAL void * duk_require_buffer_data (duk_context *ctx, duk_idx_t index, duk_size_t *out_size)
 
DUK_INTERNAL duk_hstringduk_get_hstring (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hstringduk_require_hstring (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hobjectduk_get_hobject (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hobjectduk_require_hobject (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hbufferduk_get_hbuffer (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hbufferduk_require_hbuffer (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hthreadduk_get_hthread (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hthreadduk_require_hthread (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hcompiledfunctionduk_get_hcompiledfunction (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hcompiledfunctionduk_require_hcompiledfunction (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hnativefunctionduk_get_hnativefunction (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hnativefunctionduk_require_hnativefunction (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_c_function duk_get_c_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_c_function duk_require_c_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_require_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_contextduk_get_context (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_contextduk_require_context (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void * duk_get_heapptr (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void * duk_require_heapptr (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hobjectduk_get_hobject_or_lfunc_coerce (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hobjectduk_require_hobject_or_lfunc (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hobjectduk_require_hobject_or_lfunc_coerce (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hobjectduk_get_hobject_with_class (duk_context *ctx, duk_idx_t index, duk_small_uint_t classnum)
 
DUK_INTERNAL duk_hobjectduk_require_hobject_with_class (duk_context *ctx, duk_idx_t index, duk_small_uint_t classnum)
 
DUK_EXTERNAL duk_size_t duk_get_length (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL void duk_set_length (duk_context *ctx, duk_idx_t index, duk_size_t length)
 
DUK_LOCAL duk_bool_t duk__defaultvalue_coerce_attempt (duk_context *ctx, duk_idx_t index, duk_small_int_t func_stridx)
 
DUK_EXTERNAL void duk_to_defaultvalue (duk_context *ctx, duk_idx_t index, duk_int_t hint)
 
DUK_EXTERNAL void duk_to_undefined (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_to_null (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_to_primitive (duk_context *ctx, duk_idx_t index, duk_int_t hint)
 
DUK_EXTERNAL duk_bool_t duk_to_boolean (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_double_t duk_to_number (duk_context *ctx, duk_idx_t index)
 
DUK_LOCAL duk_double_t duk__to_int_uint_helper (duk_context *ctx, duk_idx_t index, duk__toint_coercer coerce_func)
 
DUK_EXTERNAL duk_int_t duk_to_int (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_uint_t duk_to_uint (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_int32_t duk_to_int32 (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_uint32_t duk_to_uint32 (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_uint16_t duk_to_uint16 (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_uint8_t duk_to_uint8clamped (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL const char * duk_to_lstring (duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
 
DUK_LOCAL duk_ret_t duk__safe_to_string_raw (duk_context *ctx)
 
DUK_EXTERNAL const char * duk_safe_to_lstring (duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
 
DUK_INTERNAL void duk_to_object_class_string_top (duk_context *ctx)
 
DUK_INTERNAL void duk_push_hobject_class_string (duk_context *ctx, duk_hobject *h)
 
DUK_INTERNAL duk_int_t duk_to_int_clamped_raw (duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped)
 
DUK_INTERNAL duk_int_t duk_to_int_clamped (duk_context *ctx, duk_idx_t index, duk_idx_t minval, duk_idx_t maxval)
 
DUK_INTERNAL duk_int_t duk_to_int_check_range (duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval)
 
DUK_EXTERNAL const char * duk_to_string (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL duk_hstringduk_to_hstring (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void * duk_to_buffer_raw (duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t mode)
 
DUK_EXTERNAL void * duk_to_pointer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_to_object (duk_context *ctx, duk_idx_t index)
 
DUK_LOCAL duk_bool_t duk__tag_check (duk_context *ctx, duk_idx_t index, duk_small_uint_t tag)
 
DUK_LOCAL duk_bool_t duk__obj_flag_any_default_false (duk_context *ctx, duk_idx_t index, duk_uint_t flag_mask)
 
DUK_EXTERNAL duk_int_t duk_get_type (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_check_type (duk_context *ctx, duk_idx_t index, duk_int_t type)
 
DUK_EXTERNAL duk_uint_t duk_get_type_mask (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_check_type_mask (duk_context *ctx, duk_idx_t index, duk_uint_t mask)
 
DUK_EXTERNAL duk_bool_t duk_is_undefined (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_null (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_null_or_undefined (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_boolean (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_number (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_nan (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_string (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_object (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_buffer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_pointer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_lightfunc (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_array (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_c_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_bound_function (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_thread (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_fixed_buffer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_dynamic_buffer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_bool_t duk_is_external_buffer (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL duk_errcode_t duk_get_error_code (duk_context *ctx, duk_idx_t index)
 
DUK_INTERNAL void duk_push_tval (duk_context *ctx, duk_tval *tv)
 
DUK_EXTERNAL void duk_push_undefined (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_null (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_boolean (duk_context *ctx, duk_bool_t val)
 
DUK_EXTERNAL void duk_push_true (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_false (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_number (duk_context *ctx, duk_double_t val)
 
DUK_EXTERNAL void duk_push_int (duk_context *ctx, duk_int_t val)
 
DUK_EXTERNAL void duk_push_uint (duk_context *ctx, duk_uint_t val)
 
DUK_EXTERNAL void duk_push_nan (duk_context *ctx)
 
DUK_EXTERNAL const char * duk_push_lstring (duk_context *ctx, const char *str, duk_size_t len)
 
DUK_EXTERNAL const char * duk_push_string (duk_context *ctx, const char *str)
 
DUK_EXTERNAL const char * duk_push_string_file_raw (duk_context *ctx, const char *path, duk_uint_t flags)
 
DUK_EXTERNAL void duk_push_pointer (duk_context *ctx, void *val)
 
DUK_LOCAL void duk__push_this_helper (duk_context *ctx, duk_small_uint_t check_object_coercible)
 
DUK_EXTERNAL void duk_push_this (duk_context *ctx)
 
DUK_INTERNAL void duk_push_this_check_object_coercible (duk_context *ctx)
 
DUK_INTERNAL duk_hobjectduk_push_this_coercible_to_object (duk_context *ctx)
 
DUK_INTERNAL duk_hstringduk_push_this_coercible_to_string (duk_context *ctx)
 
DUK_INTERNAL duk_tvalduk_get_borrowed_this_tval (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_current_function (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_current_thread (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_global_object (duk_context *ctx)
 
DUK_LOCAL void duk__push_stash (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_heap_stash (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_global_stash (duk_context *ctx)
 
DUK_EXTERNAL void duk_push_thread_stash (duk_context *ctx, duk_context *target_ctx)
 
DUK_LOCAL duk_int_t duk__try_push_vsprintf (duk_context *ctx, void *buf, duk_size_t sz, const char *fmt, va_list ap)
 
DUK_EXTERNAL const char * duk_push_vsprintf (duk_context *ctx, const char *fmt, va_list ap)
 
DUK_EXTERNAL const char * duk_push_sprintf (duk_context *ctx, const char *fmt,...)
 
DUK_INTERNAL duk_idx_t duk_push_object_helper (duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx)
 
DUK_INTERNAL duk_idx_t duk_push_object_helper_proto (duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_hobject *proto)
 
DUK_EXTERNAL duk_idx_t duk_push_object (duk_context *ctx)
 
DUK_EXTERNAL duk_idx_t duk_push_array (duk_context *ctx)
 
DUK_EXTERNAL duk_idx_t duk_push_thread_raw (duk_context *ctx, duk_uint_t flags)
 
DUK_INTERNAL duk_idx_t duk_push_compiledfunction (duk_context *ctx)
 
DUK_EXTERNAL duk_idx_t duk_push_c_function (duk_context *ctx, duk_c_function func, duk_int_t nargs)
 
DUK_INTERNAL void duk_push_c_function_noexotic (duk_context *ctx, duk_c_function func, duk_int_t nargs)
 
DUK_INTERNAL void duk_push_c_function_noconstruct_noexotic (duk_context *ctx, duk_c_function func, duk_int_t nargs)
 
DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc (duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic)
 
DUK_INTERNAL duk_hbufferobjectduk_push_bufferobject_raw (duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx)
 
DUK_EXTERNAL void duk_push_buffer_object (duk_context *ctx, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags)
 
DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw (duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap)
 
DUK_EXTERNAL duk_idx_t duk_push_error_object_raw (duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt,...)
 
DUK_EXTERNAL duk_idx_t duk_push_error_object_stash (duk_context *ctx, duk_errcode_t err_code, const char *fmt,...)
 
DUK_EXTERNAL void * duk_push_buffer_raw (duk_context *ctx, duk_size_t size, duk_small_uint_t flags)
 
DUK_EXTERNAL duk_idx_t duk_push_heapptr (duk_context *ctx, void *ptr)
 
DUK_INTERNAL duk_idx_t duk_push_object_internal (duk_context *ctx)
 
DUK_INTERNAL void duk_push_hstring (duk_context *ctx, duk_hstring *h)
 
DUK_INTERNAL void duk_push_hstring_stridx (duk_context *ctx, duk_small_int_t stridx)
 
DUK_INTERNAL void duk_push_hobject (duk_context *ctx, duk_hobject *h)
 
DUK_INTERNAL void duk_push_hbuffer (duk_context *ctx, duk_hbuffer *h)
 
DUK_INTERNAL void duk_push_hobject_bidx (duk_context *ctx, duk_small_int_t builtin_idx)
 
DUK_EXTERNAL void duk_pop_n (duk_context *ctx, duk_idx_t count)
 
DUK_EXTERNAL void duk_pop (duk_context *ctx)
 
DUK_EXTERNAL void duk_pop_2 (duk_context *ctx)
 
DUK_EXTERNAL void duk_pop_3 (duk_context *ctx)
 
DUK_EXTERNAL void duk_throw (duk_context *ctx)
 
DUK_EXTERNAL void duk_fatal (duk_context *ctx, duk_errcode_t err_code, const char *err_msg)
 
DUK_EXTERNAL void duk_error_va_raw (duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap)
 
DUK_EXTERNAL void duk_error_raw (duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt,...)
 
DUK_EXTERNAL void duk_error_stash (duk_context *ctx, duk_errcode_t err_code, const char *fmt,...)
 
DUK_EXTERNAL duk_bool_t duk_equals (duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
 
DUK_EXTERNAL duk_bool_t duk_strict_equals (duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
 
DUK_EXTERNAL duk_bool_t duk_instanceof (duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
 
DUK_INTERNAL void duk_push_lightfunc_name (duk_context *ctx, duk_tval *tv)
 
DUK_INTERNAL void duk_push_lightfunc_tostring (duk_context *ctx, duk_tval *tv)
 
DUK_INTERNAL void duk_push_string_funcptr (duk_context *ctx, duk_uint8_t *ptr, duk_size_t sz)
 
DUK_LOCAL void duk__push_hstring_readable_unicode (duk_context *ctx, duk_hstring *h_input)
 
DUK_INTERNAL const char * duk_push_string_tval_readable (duk_context *ctx, duk_tval *tv)
 
DUK_INTERNAL const char * duk_push_string_readable (duk_context *ctx, duk_idx_t index)
 

Variables

DUK_EXTERNAL const char * duk_api_global_filename = NULL
 
DUK_EXTERNAL duk_int_t duk_api_global_line = 0
 
static const duk_uint32_t duk__bufobj_flags_lookup []
 

Macro Definition Documentation

◆ DUK__CHECK_SPACE

#define DUK__CHECK_SPACE ( )
Value:
do { \
if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \
DUK_ERROR_API(thr, DUK_STR_PUSH_BEYOND_ALLOC_STACK); \
} \
} while (0)
#define DUK_STR_PUSH_BEYOND_ALLOC_STACK

Definition at line 41 of file duktape-1.5.2/src-separate/duk_api_stack.c.

41#define DUK__CHECK_SPACE() do { \
42 if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \
43 DUK_ERROR_API(thr, DUK_STR_PUSH_BEYOND_ALLOC_STACK); \
44 } \
45 } while (0)

Referenced by duk__push_this_helper(), duk_dup(), duk_dup_top(), duk_push_boolean(), duk_push_false(), duk_push_int(), duk_push_nan(), duk_push_null(), duk_push_number(), duk_push_pointer(), duk_push_true(), duk_push_tval(), duk_push_uint(), and duk_push_undefined().

◆ DUK__PACK_ARGS

#define DUK__PACK_ARGS ( classnum,
protobidx,
elemtype,
elemshift,
isview )    (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (isview))

Definition at line 3894 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3894#define DUK__PACK_ARGS(classnum,protobidx,elemtype,elemshift,isview) \
3895 (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (isview))

◆ DUK__READABLE_STRING_MAXCHARS

#define DUK__READABLE_STRING_MAXCHARS   32

Typedef Documentation

◆ duk__toint_coercer

typedef duk_double_t(* duk__toint_coercer) (duk_hthread *thr, duk_tval *tv)

Definition at line 1915 of file duktape-1.5.2/src-separate/duk_api_stack.c.

Function Documentation

◆ duk__api_coerce_d2i()

DUK_LOCAL duk_int_t duk__api_coerce_d2i ( duk_context * ctx,
duk_idx_t index,
duk_bool_t require )

Definition at line 50 of file duktape-1.5.2/src-separate/duk_api_stack.c.

50 {
51 duk_hthread *thr;
52 duk_tval *tv;
55
56 thr = (duk_hthread *) ctx;
57
58 tv = duk_get_tval(ctx, index);
59 if (tv == NULL) {
60 goto error_notnumber;
61 }
62
63 /*
64 * Special cases like NaN and +/- Infinity are handled explicitly
65 * because a plain C coercion from double to int handles these cases
66 * in undesirable ways. For instance, NaN may coerce to INT_MIN
67 * (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
68 *
69 * This double-to-int coercion differs from ToInteger() because it
70 * has a finite range (ToInteger() allows e.g. +/- Infinity). It
71 * also differs from ToInt32() because the INT_MIN/INT_MAX clamping
72 * depends on the size of the int type on the platform. In particular,
73 * on platforms with a 64-bit int type, the full range is allowed.
74 */
75
76#if defined(DUK_USE_FASTINT)
77 if (DUK_TVAL_IS_FASTINT(tv)) {
78 duk_int64_t t = DUK_TVAL_GET_FASTINT(tv);
79#if (DUK_INT_MAX <= 0x7fffffffL)
80 /* Clamping only necessary for 32-bit ints. */
81 if (t < DUK_INT_MIN) {
82 t = DUK_INT_MIN;
83 } else if (t > DUK_INT_MAX) {
84 t = DUK_INT_MAX;
85 }
86#endif
87 return (duk_int_t) t;
88 }
89#endif
90
91 if (DUK_TVAL_IS_NUMBER(tv)) {
92 d = DUK_TVAL_GET_NUMBER(tv);
94 if (c == DUK_FP_NAN) {
95 return 0;
96 } else if (d < (duk_double_t) DUK_INT_MIN) {
97 /* covers -Infinity */
98 return DUK_INT_MIN;
99 } else if (d > (duk_double_t) DUK_INT_MAX) {
100 /* covers +Infinity */
101 return DUK_INT_MAX;
102 } else {
103 /* coerce towards zero */
104 return (duk_int_t) d;
105 }
106 }
107
108 error_notnumber:
109
110 if (require) {
112 /* not reachable */
113 }
114 return 0;
115}
guint index
duk_int_fast32_t duk_int_t
#define DUK_TVAL_IS_NUMBER(tv)
#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, expectname, lowmemstr)
#define DUK_TVAL_GET_NUMBER(tv)
DUK_INTERNAL duk_tval * duk_get_tval(duk_context *ctx, duk_idx_t index)
#define NULL
Definition gmacros.h:924

References DUK_ERROR_REQUIRE_TYPE_INDEX, DUK_FP_NAN, DUK_FPCLASSIFY, duk_get_tval(), DUK_INT_MAX, DUK_INT_MIN, DUK_STR_NOT_NUMBER, DUK_TVAL_GET_NUMBER, DUK_TVAL_IS_NUMBER, index, and NULL.

Referenced by duk_get_int(), duk_require_int(), and duk_to_int().

◆ duk__api_coerce_d2ui()

DUK_LOCAL duk_uint_t duk__api_coerce_d2ui ( duk_context * ctx,
duk_idx_t index,
duk_bool_t require )

Definition at line 117 of file duktape-1.5.2/src-separate/duk_api_stack.c.

117 {
118 duk_hthread *thr;
119 duk_tval *tv;
121 duk_double_t d;
122
123 /* Same as above but for unsigned int range. */
124
125 thr = (duk_hthread *) ctx;
126
127 tv = duk_get_tval(ctx, index);
128 if (tv == NULL) {
129 goto error_notnumber;
130 }
131
132#if defined(DUK_USE_FASTINT)
133 if (DUK_TVAL_IS_FASTINT(tv)) {
134 duk_int64_t t = DUK_TVAL_GET_FASTINT(tv);
135 if (t < 0) {
136 t = 0;
137 }
138#if (DUK_UINT_MAX <= 0xffffffffUL)
139 /* Clamping only necessary for 32-bit ints. */
140 else if (t > DUK_UINT_MAX) {
141 t = DUK_UINT_MAX;
142 }
143#endif
144 return (duk_uint_t) t;
145 }
146#endif
147
148 if (DUK_TVAL_IS_NUMBER(tv)) {
149 d = DUK_TVAL_GET_NUMBER(tv);
151 if (c == DUK_FP_NAN) {
152 return 0;
153 } else if (d < 0.0) {
154 /* covers -Infinity */
155 return (duk_uint_t) 0;
156 } else if (d > (duk_double_t) DUK_UINT_MAX) {
157 /* covers +Infinity */
158 return (duk_uint_t) DUK_UINT_MAX;
159 } else {
160 /* coerce towards zero */
161 return (duk_uint_t) d;
162 }
163 }
164
165 error_notnumber:
166
167 if (require) {
169 /* not reachable */
170 }
171 return 0;
172}
duk_uint_fast32_t duk_uint_t

References DUK_ERROR_REQUIRE_TYPE_INDEX, DUK_FP_NAN, DUK_FPCLASSIFY, duk_get_tval(), DUK_STR_NOT_NUMBER, DUK_TVAL_GET_NUMBER, DUK_TVAL_IS_NUMBER, DUK_UINT_MAX, index, and NULL.

Referenced by duk_get_uint(), duk_require_uint(), and duk_to_uint().

◆ duk__defaultvalue_coerce_attempt()

DUK_LOCAL duk_bool_t duk__defaultvalue_coerce_attempt ( duk_context * ctx,
duk_idx_t index,
duk_small_int_t func_stridx )

Definition at line 1775 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1775 {
1776 if (duk_get_prop_stridx(ctx, index, func_stridx)) {
1777 /* [ ... func ] */
1778 if (duk_is_callable(ctx, -1)) {
1779 duk_dup(ctx, index); /* -> [ ... func this ] */
1780 duk_call_method(ctx, 0); /* -> [ ... retval ] */
1781 if (duk_is_primitive(ctx, -1)) {
1782 duk_replace(ctx, index);
1783 return 1;
1784 }
1785 /* [ ... retval ]; popped below */
1786 }
1787 }
1788 duk_pop(ctx); /* [ ... func/retval ] -> [ ... ] */
1789 return 0;
1790}
DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx)
DUK_EXTERNAL void duk_call_method(duk_context *ctx, duk_idx_t nargs)
#define duk_is_primitive(ctx, index)
#define duk_is_callable(ctx, index)
DUK_EXTERNAL void duk_replace(duk_context *ctx, duk_idx_t to_index)
DUK_EXTERNAL void duk_dup(duk_context *ctx, duk_idx_t from_index)
DUK_EXTERNAL void duk_pop(duk_context *ctx)

References duk_call_method(), duk_dup(), duk_get_prop_stridx(), duk_is_callable, duk_is_primitive, duk_pop(), duk_replace(), and index.

Referenced by duk_to_defaultvalue().

◆ duk__get_buffer_data_helper()

DUK_LOCAL void * duk__get_buffer_data_helper ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size,
duk_bool_t throw_flag )

Definition at line 1332 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1332 {
1333 duk_hthread *thr = (duk_hthread *) ctx;
1334 duk_tval *tv;
1335
1337 DUK_UNREF(thr);
1338
1339 if (out_size != NULL) {
1340 *out_size = 0;
1341 }
1342
1343 tv = duk_get_tval(ctx, index);
1344 if (tv == NULL) {
1345 goto fail;
1346 }
1347
1348 if (DUK_TVAL_IS_BUFFER(tv)) {
1350 DUK_ASSERT(h != NULL);
1351 if (out_size) {
1352 *out_size = DUK_HBUFFER_GET_SIZE(h);
1353 }
1354 return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */
1355 } else if (DUK_TVAL_IS_OBJECT(tv)) {
1357 DUK_ASSERT(h != NULL);
1359 /* XXX: this is probably a useful shared helper: for a
1360 * duk_hbufferobject, get a validated buffer pointer/length.
1361 */
1362 duk_hbufferobject *h_bufobj = (duk_hbufferobject *) h;
1364
1365 if (h_bufobj->buf != NULL &&
1367 duk_uint8_t *p;
1368
1369 p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf);
1370 if (out_size != NULL) {
1371 *out_size = (duk_size_t) h_bufobj->length;
1372 }
1373 return (void *) (p + h_bufobj->offset);
1374 }
1375 /* if slice not fully valid, treat as error */
1376 }
1377 }
1378
1379 fail:
1380 if (throw_flag) {
1382 }
1383 return NULL;
1384}
#define DUK_ASSERT_CTX_VALID(ctx)
#define DUK_TVAL_GET_OBJECT(tv)
#define DUK_TVAL_IS_BUFFER(tv)
#define DUK_TVAL_IS_OBJECT(tv)
#define DUK_TVAL_GET_BUFFER(tv)
#define DUK_HBUFFEROBJECT_VALID_SLICE(h)
#define DUK_ASSERT_HBUFFEROBJECT_VALID(h)
#define DUK_HOBJECT_IS_BUFFEROBJECT(h)
#define DUK_HBUFFER_GET_DATA_PTR(heap, x)
#define DUK_HBUFFER_GET_SIZE(x)

References duk_hbufferobject::buf, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_HBUFFEROBJECT_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_HBUFFER_GET_DATA_PTR, DUK_HBUFFER_GET_SIZE, DUK_HBUFFEROBJECT_VALID_SLICE, DUK_HOBJECT_IS_BUFFEROBJECT, DUK_STR_NOT_BUFFER, DUK_TVAL_GET_BUFFER, DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_BUFFER, DUK_TVAL_IS_OBJECT, DUK_UNREF, duk_hthread::heap, index, duk_hbufferobject::length, NULL, and duk_hbufferobject::offset.

Referenced by duk_get_buffer_data(), and duk_require_buffer_data().

◆ duk__get_buffer_helper()

DUK_LOCAL void * duk__get_buffer_helper ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size,
duk_bool_t throw_flag )

Definition at line 1297 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1297 {
1298 duk_hthread *thr = (duk_hthread *) ctx;
1299 duk_tval *tv;
1300
1302 DUK_UNREF(thr);
1303
1304 if (out_size != NULL) {
1305 *out_size = 0;
1306 }
1307
1308 tv = duk_get_tval(ctx, index);
1309 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
1311 DUK_ASSERT(h != NULL);
1312 if (out_size) {
1313 *out_size = DUK_HBUFFER_GET_SIZE(h);
1314 }
1315 return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */
1316 }
1317
1318 if (throw_flag) {
1320 }
1321 return NULL;
1322}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_HBUFFER_GET_DATA_PTR, DUK_HBUFFER_GET_SIZE, DUK_STR_NOT_BUFFER, DUK_TVAL_GET_BUFFER, DUK_TVAL_IS_BUFFER, DUK_UNREF, duk_hthread::heap, index, and NULL.

Referenced by duk_get_buffer(), and duk_require_buffer().

◆ duk__get_tagged_heaphdr_raw()

◆ duk__obj_flag_any_default_false()

DUK_LOCAL duk_bool_t duk__obj_flag_any_default_false ( duk_context * ctx,
duk_idx_t index,
duk_uint_t flag_mask )

Definition at line 2593 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2593 {
2594 duk_hobject *obj;
2595
2597
2598 obj = duk_get_hobject(ctx, index);
2599 if (obj) {
2600 return (DUK_HEAPHDR_CHECK_FLAG_BITS((duk_heaphdr *) obj, flag_mask) ? 1 : 0);
2601 }
2602 return 0;
2603}
#define DUK_HEAPHDR_CHECK_FLAG_BITS(h, bits)
DUK_INTERNAL duk_hobject * duk_get_hobject(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, duk_get_hobject(), DUK_HEAPHDR_CHECK_FLAG_BITS, and index.

Referenced by duk_is_bound_function(), duk_is_c_function(), duk_is_ecmascript_function(), duk_is_function(), and duk_is_thread().

◆ duk__push_c_function_raw()

DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw ( duk_context * ctx,
duk_c_function func,
duk_idx_t nargs,
duk_uint_t flags )

Definition at line 3726 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3726 {
3727 duk_hthread *thr = (duk_hthread *) ctx;
3729 duk_idx_t ret;
3730 duk_tval *tv_slot;
3731 duk_int16_t func_nargs;
3732
3734
3735 /* check stack first */
3736 if (thr->valstack_top >= thr->valstack_end) {
3738 }
3739 if (func == NULL) {
3740 goto api_error;
3741 }
3742 if (nargs >= 0 && nargs < DUK_HNATIVEFUNCTION_NARGS_MAX) {
3743 func_nargs = (duk_int16_t) nargs;
3744 } else if (nargs == DUK_VARARGS) {
3746 } else {
3747 goto api_error;
3748 }
3749
3750 obj = duk_hnativefunction_alloc(thr->heap, flags);
3751 if (!obj) {
3753 }
3754
3755 obj->func = func;
3756 obj->nargs = func_nargs;
3757
3758 DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08lx, nargs=%ld",
3759 (unsigned long) obj->obj.hdr.h_flags, (long) obj->nargs));
3760
3761 tv_slot = thr->valstack_top;
3762 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3763 DUK_HOBJECT_INCREF(thr, obj);
3764 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3765 thr->valstack_top++;
3766
3767 /* default prototype (Note: 'obj' must be reachable) */
3769
3770 return ret;
3771
3772 api_error:
3774 return 0; /* not reached */
3775}
#define DUK_TVAL_SET_OBJECT(tv, hptr)
DUK_INTERNAL_DECL duk_hnativefunction * duk_hnativefunction_alloc(duk_heap *heap, duk_uint_t hobject_flags)
#define DUK_STR_INVALID_CALL_ARGS
#define DUK_BIDX_FUNCTION_PROTOTYPE
#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p)
#define DUK_ERROR_API(thr, msg)
#define DUK_ERROR_ALLOC_DEFMSG(thr)
#define DUK_HNATIVEFUNCTION_NARGS_VARARGS
#define DUK_HOBJECT_INCREF(thr, h)
#define DUK_HNATIVEFUNCTION_NARGS_MAX
duk_hobject * builtins[DUK_NUM_BUILTINS]

References duk_hthread::builtins, DUK_ASSERT_CTX_VALID, DUK_BIDX_FUNCTION_PROTOTYPE, DUK_DDD, DUK_DDDPRINT, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_API, duk_hnativefunction_alloc(), DUK_HNATIVEFUNCTION_NARGS_MAX, DUK_HNATIVEFUNCTION_NARGS_VARARGS, DUK_HOBJECT_INCREF, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, DUK_STR_INVALID_CALL_ARGS, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_SET_OBJECT, DUK_VARARGS, duk_hnativefunction::func, duk_heaphdr::h_flags, duk_hobject::hdr, duk_hthread::heap, duk_hnativefunction::nargs, NULL, duk_hnativefunction::obj, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

Referenced by duk_push_c_function(), duk_push_c_function_noconstruct_noexotic(), duk_push_c_function_noexotic(), and duk_to_object().

◆ duk__push_hstring_readable_unicode()

DUK_LOCAL void duk__push_hstring_readable_unicode ( duk_context * ctx,
duk_hstring * h_input )

Definition at line 4551 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4551 {
4552 duk_hthread *thr;
4553 const duk_uint8_t *p, *p_start, *p_end;
4555 2 /*quotes*/ + 3 /*periods*/];
4556 duk_uint8_t *q;
4558 duk_small_uint_t nchars;
4559
4561 DUK_ASSERT(h_input != NULL);
4562 thr = (duk_hthread *) ctx;
4563
4564 p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input);
4565 p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
4566 p = p_start;
4567 q = buf;
4568
4569 nchars = 0;
4570 *q++ = (duk_uint8_t) DUK_ASC_SINGLEQUOTE;
4571 for (;;) {
4572 if (p >= p_end) {
4573 break;
4574 }
4575 if (nchars == DUK__READABLE_STRING_MAXCHARS) {
4576 *q++ = (duk_uint8_t) DUK_ASC_PERIOD;
4577 *q++ = (duk_uint8_t) DUK_ASC_PERIOD;
4578 *q++ = (duk_uint8_t) DUK_ASC_PERIOD;
4579 break;
4580 }
4581 if (duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) {
4582 if (cp < 0x20 || cp == 0x7f || cp == DUK_ASC_SINGLEQUOTE || cp == DUK_ASC_BACKSLASH) {
4583 DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */
4584 DUK_ASSERT((cp >> 4) <= 0x0f);
4585 *q++ = (duk_uint8_t) DUK_ASC_BACKSLASH;
4586 *q++ = (duk_uint8_t) DUK_ASC_LC_X;
4587 *q++ = (duk_uint8_t) duk_lc_digits[cp >> 4];
4588 *q++ = (duk_uint8_t) duk_lc_digits[cp & 0x0f];
4589 } else {
4590 q += duk_unicode_encode_xutf8(cp, q);
4591 }
4592 } else {
4593 p++; /* advance manually */
4594 *q++ = (duk_uint8_t) DUK_ASC_QUESTION;
4595 }
4596 nchars++;
4597 }
4598 *q++ = (duk_uint8_t) DUK_ASC_SINGLEQUOTE;
4599
4600 duk_push_lstring(ctx, (const char *) buf, (duk_size_t) (q - buf));
4601}
unsigned int duk_small_uint_t
#define DUK_HSTRING_GET_DATA(x)
DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_xutf8(duk_ucodepoint_t cp, duk_uint8_t *out)
DUK_INTERNAL const duk_uint8_t duk_lc_digits[36]
#define DUK_HSTRING_GET_BYTELEN(x)
#define DUK_UNICODE_MAX_XUTF8_LENGTH
DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp)
DUK_EXTERNAL const char * duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len)

References DUK__READABLE_STRING_MAXCHARS, DUK_ASC_BACKSLASH, DUK_ASC_LC_X, DUK_ASC_PERIOD, DUK_ASC_QUESTION, DUK_ASC_SINGLEQUOTE, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_HSTRING_GET_BYTELEN, DUK_HSTRING_GET_DATA, duk_lc_digits, duk_push_lstring(), duk_unicode_decode_xutf8(), duk_unicode_encode_xutf8(), DUK_UNICODE_MAX_XUTF8_LENGTH, and NULL.

Referenced by duk_push_string_tval_readable().

◆ duk__push_stash()

DUK_LOCAL void duk__push_stash ( duk_context * ctx)

Definition at line 3384 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3384 {
3387 DUK_DDD(DUK_DDDPRINT("creating heap/global/thread stash on first use"));
3388 duk_pop(ctx);
3390 duk_dup_top(ctx);
3391 duk_xdef_prop_stridx(ctx, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* [ ... parent stash stash ] -> [ ... parent stash ] */
3392 }
3393 duk_remove(ctx, -2);
3394}
DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_uint_t desc_flags)
DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL void duk_dup_top(duk_context *ctx)
DUK_INTERNAL duk_idx_t duk_push_object_internal(duk_context *ctx)

References DUK_ASSERT_CTX_VALID, DUK_DDD, DUK_DDDPRINT, duk_dup_top(), duk_get_prop_stridx(), duk_pop(), DUK_PROPDESC_FLAGS_C, duk_push_object_internal(), duk_remove(), DUK_STRIDX_INT_VALUE, and duk_xdef_prop_stridx().

Referenced by duk_push_global_stash(), duk_push_heap_stash(), and duk_push_thread_stash().

◆ duk__push_this_helper()

DUK_LOCAL void duk__push_this_helper ( duk_context * ctx,
duk_small_uint_t check_object_coercible )

Definition at line 3259 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3259 {
3260 duk_hthread *thr;
3261 duk_tval *tv_slot;
3262
3264 DUK_ASSERT_DISABLE(thr->callstack_top >= 0); /* avoid warning (unsigned) */
3265 thr = (duk_hthread *) ctx;
3268
3269 DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */
3270 tv_slot = thr->valstack_top++;
3271
3272 if (DUK_UNLIKELY(thr->callstack_top == 0)) {
3273 if (check_object_coercible) {
3274 goto type_error;
3275 }
3276 /* 'undefined' already on stack top */
3277 } else {
3278 duk_tval *tv;
3279
3280 /* 'this' binding is just before current activation's bottom */
3281 DUK_ASSERT(thr->valstack_bottom > thr->valstack);
3282 tv = thr->valstack_bottom - 1;
3283 if (check_object_coercible &&
3285 /* XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv) */
3286 goto type_error;
3287 }
3288
3289 DUK_TVAL_SET_TVAL(tv_slot, tv);
3290 DUK_TVAL_INCREF(thr, tv);
3291 }
3292 return;
3293
3294 type_error:
3296}
#define DUK_TVAL_SET_TVAL(v, x)
#define DUK_ERROR_TYPE(thr, msg)
#define DUK_TVAL_IS_NULL(tv)
#define DUK_TVAL_IS_UNDEFINED(tv)
#define DUK_TVAL_INCREF(thr, tv)
#define DUK_STR_NOT_OBJECT_COERCIBLE
#define DUK_ASSERT_DISABLE(x)

References duk_hthread::callstack_size, duk_hthread::callstack_top, DUK__CHECK_SPACE, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_ERROR_TYPE, DUK_STR_NOT_OBJECT_COERCIBLE, DUK_TVAL_INCREF, DUK_TVAL_IS_NULL, DUK_TVAL_IS_UNDEFINED, DUK_TVAL_SET_TVAL, DUK_UNLIKELY, duk_hthread::valstack, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk_push_this(), duk_push_this_check_object_coercible(), duk_push_this_coercible_to_object(), and duk_push_this_coercible_to_string().

◆ duk__resize_valstack()

DUK_LOCAL duk_bool_t duk__resize_valstack ( duk_context * ctx,
duk_size_t new_size )

Definition at line 487 of file duktape-1.5.2/src-separate/duk_api_stack.c.

487 {
488 duk_hthread *thr = (duk_hthread *) ctx;
489 duk_ptrdiff_t old_bottom_offset;
490 duk_ptrdiff_t old_top_offset;
491 duk_ptrdiff_t old_end_offset_post;
492#ifdef DUK_USE_DEBUG
493 duk_ptrdiff_t old_end_offset_pre;
494 duk_tval *old_valstack_pre;
495 duk_tval *old_valstack_post;
496#endif
497 duk_tval *new_valstack;
498 duk_size_t new_alloc_size;
499 duk_tval *p;
500
502 DUK_ASSERT(thr != NULL);
503 DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
506 DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */
507 DUK_ASSERT(new_size <= thr->valstack_max); /* valstack limit caller has check, prevents wrapping */
508 DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */
509
510 /* get pointer offsets for tweaking below */
511 old_bottom_offset = (((duk_uint8_t *) thr->valstack_bottom) - ((duk_uint8_t *) thr->valstack));
512 old_top_offset = (((duk_uint8_t *) thr->valstack_top) - ((duk_uint8_t *) thr->valstack));
513#ifdef DUK_USE_DEBUG
514 old_end_offset_pre = (((duk_uint8_t *) thr->valstack_end) - ((duk_uint8_t *) thr->valstack)); /* not very useful, used for debugging */
515 old_valstack_pre = thr->valstack;
516#endif
517
518 /* Allocate a new valstack.
519 *
520 * Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
521 * invalidate the original thr->valstack base pointer inside the realloc
522 * process. See doc/memory-management.rst.
523 */
524
525 new_alloc_size = sizeof(duk_tval) * new_size;
526 new_valstack = (duk_tval *) DUK_REALLOC_INDIRECT(thr->heap, duk_hthread_get_valstack_ptr, (void *) thr, new_alloc_size);
527 if (!new_valstack) {
528 /* Because new_size != 0, if condition doesn't need to be
529 * (new_valstack != NULL || new_size == 0).
530 */
531 DUK_ASSERT(new_size != 0);
532 DUK_D(DUK_DPRINT("failed to resize valstack to %lu entries (%lu bytes)",
533 (unsigned long) new_size, (unsigned long) new_alloc_size));
534 return 0;
535 }
536
537 /* Note: the realloc may have triggered a mark-and-sweep which may
538 * have resized our valstack internally. However, the mark-and-sweep
539 * MUST NOT leave the stack bottom/top in a different state. Particular
540 * assumptions and facts:
541 *
542 * - The thr->valstack pointer may be different after realloc,
543 * and the offset between thr->valstack_end <-> thr->valstack
544 * may have changed.
545 * - The offset between thr->valstack_bottom <-> thr->valstack
546 * and thr->valstack_top <-> thr->valstack MUST NOT have changed,
547 * because mark-and-sweep must adhere to a strict stack policy.
548 * In other words, logical bottom and top MUST NOT have changed.
549 * - All values above the top are unreachable but are initialized
550 * to UNDEFINED, up to the post-realloc valstack_end.
551 * - 'old_end_offset' must be computed after realloc to be correct.
552 */
553
554 DUK_ASSERT((((duk_uint8_t *) thr->valstack_bottom) - ((duk_uint8_t *) thr->valstack)) == old_bottom_offset);
555 DUK_ASSERT((((duk_uint8_t *) thr->valstack_top) - ((duk_uint8_t *) thr->valstack)) == old_top_offset);
556
557 /* success, fixup pointers */
558 old_end_offset_post = (((duk_uint8_t *) thr->valstack_end) - ((duk_uint8_t *) thr->valstack)); /* must be computed after realloc */
559#ifdef DUK_USE_DEBUG
560 old_valstack_post = thr->valstack;
561#endif
562 thr->valstack = new_valstack;
563 thr->valstack_end = new_valstack + new_size;
564#if !defined(DUK_USE_PREFER_SIZE)
565 thr->valstack_size = new_size;
566#endif
567 thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + old_bottom_offset);
568 thr->valstack_top = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + old_top_offset);
569
570 DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
573
574 /* useful for debugging */
575#ifdef DUK_USE_DEBUG
576 if (old_end_offset_pre != old_end_offset_post) {
577 DUK_D(DUK_DPRINT("valstack was resized during valstack_resize(), probably by mark-and-sweep; "
578 "end offset changed: %lu -> %lu",
579 (unsigned long) old_end_offset_pre,
580 (unsigned long) old_end_offset_post));
581 }
582 if (old_valstack_pre != old_valstack_post) {
583 DUK_D(DUK_DPRINT("valstack pointer changed during valstack_resize(), probably by mark-and-sweep: %p -> %p",
584 (void *) old_valstack_pre,
585 (void *) old_valstack_post));
586 }
587#endif
588
589 DUK_DD(DUK_DDPRINT("resized valstack to %lu elements (%lu bytes), bottom=%ld, top=%ld, "
590 "new pointers: start=%p end=%p bottom=%p top=%p",
591 (unsigned long) new_size, (unsigned long) new_alloc_size,
592 (long) (thr->valstack_bottom - thr->valstack),
593 (long) (thr->valstack_top - thr->valstack),
594 (void *) thr->valstack, (void *) thr->valstack_end,
595 (void *) thr->valstack_bottom, (void *) thr->valstack_top));
596
597 /* Init newly allocated slots (only). */
598 p = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + old_end_offset_post);
599 while (p < thr->valstack_end) {
600 /* Never executed if new size is smaller. */
602 p++;
603 }
604
605 /* Assert for value stack initialization policy. */
606#if defined(DUK_USE_ASSERTIONS)
607 p = thr->valstack_top;
608 while (p < thr->valstack_end) {
610 p++;
611 }
612#endif
613
614 return 1;
615}
#define DUK_REALLOC_INDIRECT(heap, cb, ud, newsize)
struct duk_tval_struct duk_tval
DUK_INTERNAL_DECL void * duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud)
#define DUK_TVAL_SET_UNDEFINED(tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_D, DUK_DD, DUK_DDPRINT, DUK_DPRINT, duk_hthread_get_valstack_ptr(), DUK_REALLOC_INDIRECT, DUK_SIZE_MAX, DUK_TVAL_IS_UNDEFINED, DUK_TVAL_SET_UNDEFINED, duk_hthread::heap, NULL, duk_hthread::valstack, duk_hthread::valstack_bottom, duk_hthread::valstack_end, duk_hthread::valstack_size, and duk_hthread::valstack_top.

Referenced by duk_valstack_resize_raw().

◆ duk__safe_to_string_raw()

DUK_LOCAL duk_ret_t duk__safe_to_string_raw ( duk_context * ctx)

Definition at line 2049 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2049 {
2051
2052 duk_to_string(ctx, -1);
2053 return 1;
2054}
DUK_EXTERNAL const char * duk_to_string(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, and duk_to_string().

Referenced by duk_safe_to_lstring().

◆ duk__tag_check()

DUK_LOCAL duk_bool_t duk__tag_check ( duk_context * ctx,
duk_idx_t index,
duk_small_uint_t tag )

Definition at line 2583 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2583 {
2584 duk_tval *tv;
2585
2586 tv = duk_get_tval(ctx, index);
2587 if (!tv) {
2588 return 0;
2589 }
2590 return (DUK_TVAL_GET_TAG(tv) == tag);
2591}

References duk_get_tval(), DUK_TVAL_GET_TAG, and index.

Referenced by duk_is_boolean(), duk_is_buffer(), duk_is_lightfunc(), duk_is_null(), duk_is_object(), duk_is_pointer(), duk_is_string(), and duk_is_undefined().

◆ duk__to_int_uint_helper()

DUK_LOCAL duk_double_t duk__to_int_uint_helper ( duk_context * ctx,
duk_idx_t index,
duk__toint_coercer coerce_func )

Definition at line 1917 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1917 {
1918 duk_hthread *thr = (duk_hthread *) ctx;
1919 duk_tval *tv;
1920 duk_double_t d;
1921
1923
1924 tv = duk_require_tval(ctx, index);
1925 DUK_ASSERT(tv != NULL);
1926 d = coerce_func(thr, tv);
1927
1928 /* XXX: fastint? */
1929
1930 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
1931 tv = duk_require_tval(ctx, index);
1932 DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */
1933 return d;
1934}
#define DUK_TVAL_SET_NUMBER_UPDREF
DUK_INTERNAL duk_tval * duk_require_tval(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_SET_NUMBER_UPDREF, index, and NULL.

Referenced by duk_to_int(), and duk_to_uint().

◆ duk__try_push_vsprintf()

DUK_LOCAL duk_int_t duk__try_push_vsprintf ( duk_context * ctx,
void * buf,
duk_size_t sz,
const char * fmt,
va_list ap )

Definition at line 3424 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3424 {
3425 duk_int_t len;
3426
3428 DUK_UNREF(ctx);
3429
3430 /* NUL terminator handling doesn't matter here */
3431 len = DUK_VSNPRINTF((char *) buf, sz, fmt, ap);
3432 if (len < (duk_int_t) sz) {
3433 /* Return value of 'sz' or more indicates output was (potentially)
3434 * truncated.
3435 */
3436 return (duk_int_t) len;
3437 }
3438 return -1;
3439}

References DUK_ASSERT_CTX_VALID, DUK_UNREF, and DUK_VSNPRINTF.

Referenced by duk_push_vsprintf().

◆ duk_check_stack()

DUK_EXTERNAL duk_bool_t duk_check_stack ( duk_context * ctx,
duk_idx_t extra )

Definition at line 717 of file duktape-1.5.2/src-separate/duk_api_stack.c.

717 {
718 duk_hthread *thr = (duk_hthread *) ctx;
719 duk_size_t min_new_size;
720
722 DUK_ASSERT(thr != NULL);
723
724 if (DUK_UNLIKELY(extra < 0)) {
725 /* Clamping to zero makes the API more robust to calling code
726 * calculation errors.
727 */
728 extra = 0;
729 }
730
731 min_new_size = (thr->valstack_top - thr->valstack) + extra + DUK_VALSTACK_INTERNAL_EXTRA;
732 return duk_valstack_resize_raw(ctx,
733 min_new_size, /* min_new_size */
734 0 /* no shrink */ | /* flags */
735 0 /* no compact */ |
736 0 /* no throw */);
737}
#define DUK_VALSTACK_INTERNAL_EXTRA
DUK_INTERNAL duk_bool_t duk_valstack_resize_raw(duk_context *ctx, duk_size_t min_new_size, duk_small_uint_t flags)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_UNLIKELY, DUK_VALSTACK_INTERNAL_EXTRA, duk_valstack_resize_raw(), NULL, duk_hthread::valstack, and duk_hthread::valstack_top.

◆ duk_check_stack_top()

DUK_EXTERNAL duk_bool_t duk_check_stack_top ( duk_context * ctx,
duk_idx_t top )

Definition at line 761 of file duktape-1.5.2/src-separate/duk_api_stack.c.

761 {
762 duk_size_t min_new_size;
763
765
766 if (DUK_UNLIKELY(top < 0)) {
767 /* Clamping to zero makes the API more robust to calling code
768 * calculation errors.
769 */
770 top = 0;
771 }
772
773 min_new_size = top + DUK_VALSTACK_INTERNAL_EXTRA;
774 return duk_valstack_resize_raw(ctx,
775 min_new_size, /* min_new_size */
776 0 /* no shrink */ | /* flags */
777 0 /* no compact */ |
778 0 /* no throw */);
779}

References DUK_ASSERT_CTX_VALID, DUK_UNLIKELY, DUK_VALSTACK_INTERNAL_EXTRA, and duk_valstack_resize_raw().

◆ duk_check_type()

DUK_EXTERNAL duk_bool_t duk_check_type ( duk_context * ctx,
duk_idx_t index,
duk_int_t type )

Definition at line 2668 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2668 {
2670
2671 return (duk_get_type(ctx, index) == type) ? 1 : 0;
2672}
DUK_EXTERNAL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, duk_get_type(), and index.

◆ duk_check_type_mask()

DUK_EXTERNAL duk_bool_t duk_check_type_mask ( duk_context * ctx,
duk_idx_t index,
duk_uint_t mask )

Definition at line 2712 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2712 {
2713 duk_hthread *thr = (duk_hthread *) ctx;
2714
2716
2717 if (duk_get_type_mask(ctx, index) & mask) {
2718 return 1;
2719 }
2720 if (mask & DUK_TYPE_MASK_THROW) {
2723 }
2724 return 0;
2725}
#define DUK_STR_UNEXPECTED_TYPE
#define DUK_TYPE_MASK_THROW
DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index)
#define mask(n)

References DUK_ASSERT_CTX_VALID, DUK_ERROR_TYPE, duk_get_type_mask(), DUK_STR_UNEXPECTED_TYPE, DUK_TYPE_MASK_THROW, DUK_UNREACHABLE, index, and mask.

Referenced by duk_to_primitive().

◆ duk_copy()

DUK_EXTERNAL void duk_copy ( duk_context * ctx,
duk_idx_t from_index,
duk_idx_t to_index )

Definition at line 930 of file duktape-1.5.2/src-separate/duk_api_stack.c.

930 {
931 duk_hthread *thr = (duk_hthread *) ctx;
932 duk_tval *tv1;
933 duk_tval *tv2;
934
936 DUK_UNREF(thr); /* w/o refcounting */
937
938 tv1 = duk_require_tval(ctx, from_index);
939 DUK_ASSERT(tv1 != NULL);
940 tv2 = duk_require_tval(ctx, to_index);
941 DUK_ASSERT(tv2 != NULL);
942
943 /* For tv1 == tv2, this is a no-op (no explicit check needed). */
944 DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */
945}
#define DUK_TVAL_SET_TVAL_UPDREF

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_SET_TVAL_UPDREF, DUK_UNREF, and NULL.

◆ duk_dup()

DUK_EXTERNAL void duk_dup ( duk_context * ctx,
duk_idx_t from_index )

Definition at line 829 of file duktape-1.5.2/src-separate/duk_api_stack.c.

829 {
830 duk_hthread *thr;
831 duk_tval *tv_from;
832 duk_tval *tv_to;
833
835 thr = (duk_hthread *) ctx;
837
838 tv_from = duk_require_tval(ctx, from_index);
839 tv_to = thr->valstack_top++;
840 DUK_ASSERT(tv_from != NULL);
841 DUK_ASSERT(tv_to != NULL);
842 DUK_TVAL_SET_TVAL(tv_to, tv_from);
843 DUK_TVAL_INCREF(thr, tv_to); /* no side effects */
844}

References DUK__CHECK_SPACE, DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_INCREF, DUK_TVAL_SET_TVAL, NULL, and duk_hthread::valstack_top.

Referenced by duk__defaultvalue_coerce_attempt(), duk_safe_to_lstring(), and duk_to_object().

◆ duk_dup_top()

DUK_EXTERNAL void duk_dup_top ( duk_context * ctx)

Definition at line 846 of file duktape-1.5.2/src-separate/duk_api_stack.c.

846 {
847 duk_hthread *thr;
848 duk_tval *tv_from;
849 duk_tval *tv_to;
850
852 thr = (duk_hthread *) ctx;
854
855 if (thr->valstack_top - thr->valstack_bottom <= 0) {
856 DUK_ERROR_API_INDEX(thr, -1);
857 return; /* unreachable */
858 }
859 tv_from = thr->valstack_top - 1;
860 tv_to = thr->valstack_top++;
861 DUK_ASSERT(tv_from != NULL);
862 DUK_ASSERT(tv_to != NULL);
863 DUK_TVAL_SET_TVAL(tv_to, tv_from);
864 DUK_TVAL_INCREF(thr, tv_to); /* no side effects */
865}
#define DUK_ERROR_API_INDEX(thr, index)

References DUK__CHECK_SPACE, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API_INDEX, DUK_TVAL_INCREF, DUK_TVAL_SET_TVAL, NULL, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk__push_stash().

◆ duk_equals()

DUK_EXTERNAL duk_bool_t duk_equals ( duk_context * ctx,
duk_idx_t index1,
duk_idx_t index2 )

Definition at line 4409 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4409 {
4410 duk_hthread *thr = (duk_hthread *) ctx;
4411 duk_tval *tv1, *tv2;
4412
4414
4415 tv1 = duk_get_tval(ctx, index1);
4416 tv2 = duk_get_tval(ctx, index2);
4417 if ((tv1 == NULL) || (tv2 == NULL)) {
4418 return 0;
4419 }
4420
4421 /* Coercion may be needed, the helper handles that by pushing the
4422 * tagged values to the stack.
4423 */
4424 return duk_js_equals(thr, tv1, tv2);
4425}
#define duk_js_equals(thr, tv_x, tv_y)

References DUK_ASSERT_CTX_VALID, duk_get_tval(), duk_js_equals, and NULL.

◆ duk_error_raw()

DUK_EXTERNAL void duk_error_raw ( duk_context * ctx,
duk_errcode_t err_code,
const char * filename,
duk_int_t line,
const char * fmt,
... )

Definition at line 4374 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4374 {
4375 va_list ap;
4376
4378
4379 va_start(ap, fmt);
4380 duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4381 va_end(ap);
4382 duk_throw(ctx);
4383}
DUK_EXTERNAL void duk_throw(duk_context *ctx)
DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap)

References DUK_ASSERT_CTX_VALID, duk_push_error_object_va_raw(), and duk_throw().

◆ duk_error_stash()

DUK_EXTERNAL void duk_error_stash ( duk_context * ctx,
duk_errcode_t err_code,
const char * fmt,
... )

Definition at line 4386 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4386 {
4387 const char *filename;
4388 duk_int_t line;
4389 va_list ap;
4390
4392
4393 filename = duk_api_global_filename;
4394 line = duk_api_global_line;
4397
4398 va_start(ap, fmt);
4399 duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4400 va_end(ap);
4401 duk_throw(ctx);
4402}
DUK_EXTERNAL duk_int_t duk_api_global_line
DUK_EXTERNAL const char * duk_api_global_filename

References duk_api_global_filename, duk_api_global_line, DUK_ASSERT_CTX_VALID, duk_push_error_object_va_raw(), duk_throw(), and NULL.

◆ duk_error_va_raw()

DUK_EXTERNAL void duk_error_va_raw ( duk_context * ctx,
duk_errcode_t err_code,
const char * filename,
duk_int_t line,
const char * fmt,
va_list ap )

Definition at line 4367 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4367 {
4369
4370 duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4371 duk_throw(ctx);
4372}

References DUK_ASSERT_CTX_VALID, duk_push_error_object_va_raw(), and duk_throw().

◆ duk_fatal()

DUK_EXTERNAL void duk_fatal ( duk_context * ctx,
duk_errcode_t err_code,
const char * err_msg )

Definition at line 4347 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4347 {
4348 duk_hthread *thr = (duk_hthread *) ctx;
4349
4351 DUK_ASSERT(thr != NULL);
4352 DUK_ASSERT(thr->heap != NULL);
4353 DUK_ASSERT(thr->heap->fatal_func != NULL);
4354
4355 DUK_D(DUK_DPRINT("fatal error occurred, code %ld, message %s",
4356 (long) err_code, (const char *) err_msg));
4357
4358 /* fatal_func should be noreturn, but noreturn declarations on function
4359 * pointers has a very spotty support apparently so it's not currently
4360 * done.
4361 */
4362 thr->heap->fatal_func(ctx, err_code, err_msg);
4363
4364 DUK_PANIC(DUK_ERR_API_ERROR, "fatal handler returned");
4365}
#define DUK_PANIC(code, msg)
duk_fatal_function fatal_func

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_D, DUK_DPRINT, DUK_ERR_API_ERROR, DUK_PANIC, duk_heap::fatal_func, duk_hthread::heap, and NULL.

◆ duk_get_boolean()

DUK_EXTERNAL duk_bool_t duk_get_boolean ( duk_context * ctx,
duk_idx_t index )

Definition at line 1092 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1092 {
1093 duk_bool_t ret = 0; /* default: false */
1094 duk_tval *tv;
1095
1097
1098 tv = duk_get_tval(ctx, index);
1099 if (tv && DUK_TVAL_IS_BOOLEAN(tv)) {
1100 ret = DUK_TVAL_GET_BOOLEAN(tv);
1101 }
1102
1103 DUK_ASSERT(ret == 0 || ret == 1);
1104 return ret;
1105}
duk_small_int_t duk_bool_t
#define DUK_TVAL_GET_BOOLEAN(tv)
#define DUK_TVAL_IS_BOOLEAN(tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TVAL_GET_BOOLEAN, DUK_TVAL_IS_BOOLEAN, and index.

◆ duk_get_borrowed_this_tval()

DUK_INTERNAL duk_tval * duk_get_borrowed_this_tval ( duk_context * ctx)

Definition at line 3334 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3334 {
3335 duk_hthread *thr;
3336
3337 DUK_ASSERT(ctx != NULL);
3338 thr = (duk_hthread *) ctx;
3339
3340 DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */
3341 DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */
3342 DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */
3343
3344 return thr->valstack_bottom - 1;
3345}

References duk_hthread::callstack_top, DUK_ASSERT, NULL, duk_hthread::valstack, and duk_hthread::valstack_bottom.

◆ duk_get_buffer()

DUK_EXTERNAL void * duk_get_buffer ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size )

Definition at line 1324 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1324 {
1325 return duk__get_buffer_helper(ctx, index, out_size, 0 /*throw_flag*/);
1326}
DUK_LOCAL void * duk__get_buffer_helper(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_bool_t throw_flag)

References duk__get_buffer_helper(), and index.

◆ duk_get_buffer_data()

DUK_EXTERNAL void * duk_get_buffer_data ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size )

Definition at line 1386 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1386 {
1387 return duk__get_buffer_data_helper(ctx, index, out_size, 0 /*throw_flag*/);
1388}
DUK_LOCAL void * duk__get_buffer_data_helper(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_bool_t throw_flag)

References duk__get_buffer_data_helper(), and index.

◆ duk_get_c_function()

DUK_EXTERNAL duk_c_function duk_get_c_function ( duk_context * ctx,
duk_idx_t index )

Definition at line 1505 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1505 {
1506 duk_tval *tv;
1507 duk_hobject *h;
1509
1511
1512 tv = duk_get_tval(ctx, index);
1513 if (!tv) {
1514 return NULL;
1515 }
1516 if (!DUK_TVAL_IS_OBJECT(tv)) {
1517 return NULL;
1518 }
1519 h = DUK_TVAL_GET_OBJECT(tv);
1520 DUK_ASSERT(h != NULL);
1521
1523 return NULL;
1524 }
1526 f = (duk_hnativefunction *) h;
1527
1528 return f->func;
1529}
#define DUK_HOBJECT_IS_NATIVEFUNCTION(h)
#define DUK_HOBJECT_HAS_NATIVEFUNCTION(h)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HOBJECT_HAS_NATIVEFUNCTION, DUK_HOBJECT_IS_NATIVEFUNCTION, DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_OBJECT, duk_hnativefunction::func, index, and NULL.

Referenced by duk_require_c_function().

◆ duk_get_context()

DUK_EXTERNAL duk_context * duk_get_context ( duk_context * ctx,
duk_idx_t index )

Definition at line 1550 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1550 {
1552
1553 return (duk_context *) duk_get_hthread(ctx, index);
1554}
DUK_INTERNAL duk_hthread * duk_get_hthread(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, duk_get_hthread(), and index.

◆ duk_get_error_code()

DUK_EXTERNAL duk_errcode_t duk_get_error_code ( duk_context * ctx,
duk_idx_t index )

Definition at line 2916 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2916 {
2917 duk_hthread *thr = (duk_hthread *) ctx;
2918 duk_hobject *h;
2919 duk_uint_t sanity;
2920
2922
2923 h = duk_get_hobject(ctx, index);
2924
2926 do {
2927 if (!h) {
2928 return DUK_ERR_NONE;
2929 }
2930 if (h == thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE]) {
2931 return DUK_ERR_EVAL_ERROR;
2932 }
2934 return DUK_ERR_RANGE_ERROR;
2935 }
2938 }
2940 return DUK_ERR_SYNTAX_ERROR;
2941 }
2942 if (h == thr->builtins[DUK_BIDX_TYPE_ERROR_PROTOTYPE]) {
2943 return DUK_ERR_TYPE_ERROR;
2944 }
2945 if (h == thr->builtins[DUK_BIDX_URI_ERROR_PROTOTYPE]) {
2946 return DUK_ERR_URI_ERROR;
2947 }
2948 if (h == thr->builtins[DUK_BIDX_ERROR_PROTOTYPE]) {
2949 return DUK_ERR_ERROR;
2950 }
2951
2952 h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
2953 } while (--sanity > 0);
2954
2955 return DUK_ERR_NONE;
2956}
#define DUK_HOBJECT_GET_PROTOTYPE(heap, h)
#define DUK_BIDX_EVAL_ERROR_PROTOTYPE
#define DUK_BIDX_TYPE_ERROR_PROTOTYPE
#define DUK_BIDX_ERROR_PROTOTYPE
#define DUK_BIDX_REFERENCE_ERROR_PROTOTYPE
#define DUK_BIDX_URI_ERROR_PROTOTYPE
#define DUK_BIDX_SYNTAX_ERROR_PROTOTYPE
#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY
#define DUK_BIDX_RANGE_ERROR_PROTOTYPE
#define DUK_ERR_SYNTAX_ERROR
#define DUK_ERR_RANGE_ERROR
#define DUK_ERR_REFERENCE_ERROR

References duk_hthread::builtins, DUK_ASSERT_CTX_VALID, DUK_BIDX_ERROR_PROTOTYPE, DUK_BIDX_EVAL_ERROR_PROTOTYPE, DUK_BIDX_RANGE_ERROR_PROTOTYPE, DUK_BIDX_REFERENCE_ERROR_PROTOTYPE, DUK_BIDX_SYNTAX_ERROR_PROTOTYPE, DUK_BIDX_TYPE_ERROR_PROTOTYPE, DUK_BIDX_URI_ERROR_PROTOTYPE, DUK_ERR_ERROR, DUK_ERR_EVAL_ERROR, DUK_ERR_NONE, DUK_ERR_RANGE_ERROR, DUK_ERR_REFERENCE_ERROR, DUK_ERR_SYNTAX_ERROR, DUK_ERR_TYPE_ERROR, DUK_ERR_URI_ERROR, duk_get_hobject(), DUK_HOBJECT_GET_PROTOTYPE, DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY, duk_hthread::heap, and index.

◆ duk_get_hbuffer()

DUK_INTERNAL duk_hbuffer * duk_get_hbuffer ( duk_context * ctx,
duk_idx_t index )

Definition at line 1441 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1441 {
1443}
DUK_LOCAL_DECL duk_heaphdr * duk__get_tagged_heaphdr_raw(duk_context *ctx, duk_idx_t index, duk_uint_t tag)

References duk__get_tagged_heaphdr_raw(), DUK_TAG_BUFFER, and index.

Referenced by duk_to_buffer_raw().

◆ duk_get_hcompiledfunction()

◆ duk_get_heapptr()

DUK_EXTERNAL void * duk_get_heapptr ( duk_context * ctx,
duk_idx_t index )

Definition at line 1562 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1562 {
1563 duk_tval *tv;
1564 void *ret;
1565
1567
1568 tv = duk_get_tval(ctx, index);
1569 if (tv && DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
1570 ret = (void *) DUK_TVAL_GET_HEAPHDR(tv);
1571 DUK_ASSERT(ret != NULL);
1572 return ret;
1573 }
1574
1575 return (void *) NULL;
1576}
#define DUK_TVAL_IS_HEAP_ALLOCATED(tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TVAL_GET_HEAPHDR, DUK_TVAL_IS_HEAP_ALLOCATED, index, and NULL.

◆ duk_get_hnativefunction()

DUK_INTERNAL duk_hnativefunction * duk_get_hnativefunction ( duk_context * ctx,
duk_idx_t index )

◆ duk_get_hobject()

◆ duk_get_hobject_or_lfunc_coerce()

DUK_INTERNAL duk_hobject * duk_get_hobject_or_lfunc_coerce ( duk_context * ctx,
duk_idx_t index )

Definition at line 1610 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1610 {
1611 duk_tval *tv;
1612
1614
1615 tv = duk_require_tval(ctx, index);
1616 DUK_ASSERT(tv != NULL);
1617 if (DUK_TVAL_IS_OBJECT(tv)) {
1618 return DUK_TVAL_GET_OBJECT(tv);
1619 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
1620 duk_to_object(ctx, index);
1621 return duk_require_hobject(ctx, index);
1622 }
1623
1624 return NULL;
1625}
#define DUK_TVAL_IS_LIGHTFUNC(tv)
DUK_INTERNAL duk_hobject * duk_require_hobject(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL void duk_to_object(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_hobject(), duk_require_tval(), duk_to_object(), DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_LIGHTFUNC, DUK_TVAL_IS_OBJECT, index, and NULL.

◆ duk_get_hobject_with_class()

DUK_INTERNAL duk_hobject * duk_get_hobject_with_class ( duk_context * ctx,
duk_idx_t index,
duk_small_uint_t classnum )

Definition at line 1668 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1668 {
1669 duk_hobject *h;
1670
1672 DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */
1673 DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX);
1674
1676 if (h != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h) != classnum) {
1677 h = NULL;
1678 }
1679 return h;
1680}
#define DUK_HOBJECT_CLASS_MAX
#define DUK_HOBJECT_GET_CLASS_NUMBER(h)

References duk__get_tagged_heaphdr_raw(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_HOBJECT_CLASS_MAX, DUK_HOBJECT_GET_CLASS_NUMBER, DUK_TAG_OBJECT, index, and NULL.

◆ duk_get_hstring()

◆ duk_get_hthread()

DUK_INTERNAL duk_hthread * duk_get_hthread ( duk_context * ctx,
duk_idx_t index )

Definition at line 1454 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1454 {
1456 if (h != NULL && !DUK_HOBJECT_IS_THREAD(h)) {
1457 h = NULL;
1458 }
1459 return (duk_hthread *) h;
1460}
#define DUK_HOBJECT_IS_THREAD(h)

References duk__get_tagged_heaphdr_raw(), DUK_HOBJECT_IS_THREAD, DUK_TAG_OBJECT, index, and NULL.

Referenced by duk_get_context().

◆ duk_get_int()

DUK_EXTERNAL duk_int_t duk_get_int ( duk_context * ctx,
duk_idx_t index )

Definition at line 1167 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1167 {
1168 /* Custom coercion for API */
1170 return (duk_int_t) duk__api_coerce_d2i(ctx, index, 0 /*require*/);
1171}
DUK_LOCAL duk_int_t duk__api_coerce_d2i(duk_context *ctx, duk_idx_t index, duk_bool_t require)

References duk__api_coerce_d2i(), DUK_ASSERT_CTX_VALID, and index.

◆ duk_get_length()

DUK_EXTERNAL duk_size_t duk_get_length ( duk_context * ctx,
duk_idx_t index )

Definition at line 1702 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1702 {
1703 duk_tval *tv;
1704
1706
1707 tv = duk_get_tval(ctx, index);
1708 if (!tv) {
1709 return 0;
1710 }
1711
1712 switch (DUK_TVAL_GET_TAG(tv)) {
1713 case DUK_TAG_UNDEFINED:
1714 case DUK_TAG_NULL:
1715 case DUK_TAG_BOOLEAN:
1716 case DUK_TAG_POINTER:
1717 return 0;
1718 case DUK_TAG_STRING: {
1720 DUK_ASSERT(h != NULL);
1722 }
1723 case DUK_TAG_OBJECT: {
1725 DUK_ASSERT(h != NULL);
1726 return (duk_size_t) duk_hobject_get_length((duk_hthread *) ctx, h);
1727 }
1728 case DUK_TAG_BUFFER: {
1730 DUK_ASSERT(h != NULL);
1731 return (duk_size_t) DUK_HBUFFER_GET_SIZE(h);
1732 }
1733 case DUK_TAG_LIGHTFUNC: {
1734 duk_small_uint_t lf_flags;
1735 lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
1736 return (duk_size_t) DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
1737 }
1738#if defined(DUK_USE_FASTINT)
1739 case DUK_TAG_FASTINT:
1740#endif
1741 default:
1742 /* number */
1745 return 0;
1746 }
1747
1749}
#define DUK_HSTRING_GET_CHARLEN(x)
#define DUK_TVAL_IS_UNUSED(tv)
#define DUK_TVAL_GET_STRING(tv)
DUK_INTERNAL_DECL duk_uint32_t duk_hobject_get_length(duk_hthread *thr, duk_hobject *obj)
#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags)
#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HBUFFER_GET_SIZE, duk_hobject_get_length(), DUK_HSTRING_GET_CHARLEN, DUK_LFUNC_FLAGS_GET_LENGTH, DUK_TAG_BOOLEAN, DUK_TAG_BUFFER, DUK_TAG_LIGHTFUNC, DUK_TAG_NULL, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, DUK_TAG_UNDEFINED, DUK_TVAL_GET_BUFFER, DUK_TVAL_GET_LIGHTFUNC_FLAGS, DUK_TVAL_GET_OBJECT, DUK_TVAL_GET_STRING, DUK_TVAL_GET_TAG, DUK_TVAL_IS_NUMBER, DUK_TVAL_IS_UNUSED, DUK_UNREACHABLE, index, and NULL.

◆ duk_get_lstring()

DUK_EXTERNAL const char * duk_get_lstring ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_len )

Definition at line 1191 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1191 {
1192 const char *ret;
1193 duk_tval *tv;
1194
1196
1197 /* default: NULL, length 0 */
1198 ret = NULL;
1199 if (out_len) {
1200 *out_len = 0;
1201 }
1202
1203 tv = duk_get_tval(ctx, index);
1204 if (tv && DUK_TVAL_IS_STRING(tv)) {
1205 /* Here we rely on duk_hstring instances always being zero
1206 * terminated even if the actual string is not.
1207 */
1209 DUK_ASSERT(h != NULL);
1210 ret = (const char *) DUK_HSTRING_GET_DATA(h);
1211 if (out_len) {
1212 *out_len = DUK_HSTRING_GET_BYTELEN(h);
1213 }
1214 }
1215
1216 return ret;
1217}
#define DUK_TVAL_IS_STRING(tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HSTRING_GET_BYTELEN, DUK_HSTRING_GET_DATA, DUK_TVAL_GET_STRING, DUK_TVAL_IS_STRING, index, and NULL.

Referenced by duk_get_string(), duk_require_lstring(), and duk_safe_to_lstring().

◆ duk_get_number()

DUK_EXTERNAL duk_double_t duk_get_number ( duk_context * ctx,
duk_idx_t index )

Definition at line 1123 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1123 {
1124 duk_double_union ret;
1125 duk_tval *tv;
1126
1128
1129 ret.d = DUK_DOUBLE_NAN; /* default: NaN */
1130 tv = duk_get_tval(ctx, index);
1131 if (tv && DUK_TVAL_IS_NUMBER(tv)) {
1132 ret.d = DUK_TVAL_GET_NUMBER(tv);
1133 }
1134
1135 /*
1136 * Number should already be in NaN-normalized form, but let's
1137 * normalize anyway.
1138 */
1139
1141 return ret.d;
1142}
#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u)

References duk_double_union::d, DUK_ASSERT_CTX_VALID, DUK_DBLUNION_NORMALIZE_NAN_CHECK, DUK_DOUBLE_NAN, duk_get_tval(), DUK_TVAL_GET_NUMBER, DUK_TVAL_IS_NUMBER, and index.

◆ duk_get_pointer()

DUK_EXTERNAL void * duk_get_pointer ( duk_context * ctx,
duk_idx_t index )

Definition at line 1248 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1248 {
1249 duk_tval *tv;
1250
1252
1253 tv = duk_get_tval(ctx, index);
1254 if (tv && DUK_TVAL_IS_POINTER(tv)) {
1255 void *p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */
1256 return (void *) p;
1257 }
1258
1259 return NULL;
1260}
#define DUK_TVAL_IS_POINTER(tv)
#define DUK_TVAL_GET_POINTER(tv)

References DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TVAL_GET_POINTER, DUK_TVAL_IS_POINTER, index, and NULL.

◆ duk_get_string()

DUK_EXTERNAL const char * duk_get_string ( duk_context * ctx,
duk_idx_t index )

Definition at line 1236 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1236 {
1238
1239 return duk_get_lstring(ctx, index, NULL);
1240}
DUK_EXTERNAL const char * duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)

References DUK_ASSERT_CTX_VALID, duk_get_lstring(), index, and NULL.

Referenced by duk_safe_to_lstring().

◆ duk_get_top()

DUK_EXTERNAL duk_idx_t duk_get_top ( duk_context * ctx)

Definition at line 331 of file duktape-1.5.2/src-separate/duk_api_stack.c.

331 {
332 duk_hthread *thr = (duk_hthread *) ctx;
333
335
336 return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
337}

References DUK_ASSERT_CTX_VALID, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

◆ duk_get_top_index()

DUK_EXTERNAL duk_idx_t duk_get_top_index ( duk_context * ctx)

Definition at line 434 of file duktape-1.5.2/src-separate/duk_api_stack.c.

434 {
435 duk_hthread *thr = (duk_hthread *) ctx;
436 duk_idx_t ret;
437
439
440 ret = ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
441 if (DUK_UNLIKELY(ret < 0)) {
442 /* Return invalid index; if caller uses this without checking
443 * in another API call, the index won't map to a valid stack
444 * entry.
445 */
446 return DUK_INVALID_INDEX;
447 }
448 return ret;
449}

References DUK_ASSERT_CTX_VALID, DUK_INVALID_INDEX, DUK_UNLIKELY, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

◆ duk_get_tval()

DUK_INTERNAL duk_tval * duk_get_tval ( duk_context * ctx,
duk_idx_t index )

Definition at line 248 of file duktape-1.5.2/src-separate/duk_api_stack.c.

248 {
249 duk_hthread *thr = (duk_hthread *) ctx;
250 duk_uidx_t vs_size;
251 duk_uidx_t uindex;
252
255
257 vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
258 DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */
259
260 if (index < 0) {
261 uindex = vs_size + (duk_uidx_t) index;
262 } else {
264 uindex = (duk_uidx_t) index;
265 }
266
267 /* DUK_INVALID_INDEX won't be accepted as a valid index. */
268 DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
269
270 if (DUK_LIKELY(uindex < vs_size)) {
271 return thr->valstack_bottom + uindex;
272 }
273 return NULL;
274}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_INVALID_INDEX, DUK_LIKELY, index, NULL, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk__api_coerce_d2i(), duk__api_coerce_d2ui(), duk__get_buffer_data_helper(), duk__get_buffer_helper(), duk__get_tagged_heaphdr_raw(), duk__tag_check(), duk_equals(), duk_get_boolean(), duk_get_c_function(), duk_get_heapptr(), duk_get_length(), duk_get_lstring(), duk_get_number(), duk_get_pointer(), duk_get_type(), duk_get_type_mask(), duk_is_dynamic_buffer(), duk_is_external_buffer(), duk_is_fixed_buffer(), duk_is_function(), duk_is_nan(), duk_is_null_or_undefined(), duk_is_number(), duk_push_string_readable(), duk_require_boolean(), duk_require_null(), duk_require_number(), duk_require_pointer(), duk_require_undefined(), duk_strict_equals(), duk_throw(), and duk_to_int_clamped_raw().

◆ duk_get_type()

DUK_EXTERNAL duk_int_t duk_get_type ( duk_context * ctx,
duk_idx_t index )

Definition at line 2605 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2605 {
2606 duk_tval *tv;
2607
2609
2610 tv = duk_get_tval(ctx, index);
2611 if (!tv) {
2612 return DUK_TYPE_NONE;
2613 }
2614 switch (DUK_TVAL_GET_TAG(tv)) {
2615 case DUK_TAG_UNDEFINED:
2616 return DUK_TYPE_UNDEFINED;
2617 case DUK_TAG_NULL:
2618 return DUK_TYPE_NULL;
2619 case DUK_TAG_BOOLEAN:
2620 return DUK_TYPE_BOOLEAN;
2621 case DUK_TAG_STRING:
2622 return DUK_TYPE_STRING;
2623 case DUK_TAG_OBJECT:
2624 return DUK_TYPE_OBJECT;
2625 case DUK_TAG_BUFFER:
2626 return DUK_TYPE_BUFFER;
2627 case DUK_TAG_POINTER:
2628 return DUK_TYPE_POINTER;
2629 case DUK_TAG_LIGHTFUNC:
2630 return DUK_TYPE_LIGHTFUNC;
2631#if defined(DUK_USE_FASTINT)
2632 case DUK_TAG_FASTINT:
2633#endif
2634 default:
2635 /* Note: number has no explicit tag (in 8-byte representation) */
2638 return DUK_TYPE_NUMBER;
2639 }
2641}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TAG_BOOLEAN, DUK_TAG_BUFFER, DUK_TAG_LIGHTFUNC, DUK_TAG_NULL, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, DUK_TAG_UNDEFINED, DUK_TVAL_GET_TAG, DUK_TVAL_IS_NUMBER, DUK_TVAL_IS_UNUSED, DUK_TYPE_BOOLEAN, DUK_TYPE_BUFFER, DUK_TYPE_LIGHTFUNC, DUK_TYPE_NONE, DUK_TYPE_NULL, DUK_TYPE_NUMBER, DUK_TYPE_OBJECT, DUK_TYPE_POINTER, DUK_TYPE_STRING, DUK_TYPE_UNDEFINED, DUK_UNREACHABLE, and index.

Referenced by duk_check_type().

◆ duk_get_type_mask()

DUK_EXTERNAL duk_uint_t duk_get_type_mask ( duk_context * ctx,
duk_idx_t index )

Definition at line 2674 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2674 {
2675 duk_tval *tv;
2676
2678
2679 tv = duk_get_tval(ctx, index);
2680 if (!tv) {
2681 return DUK_TYPE_MASK_NONE;
2682 }
2683 switch (DUK_TVAL_GET_TAG(tv)) {
2684 case DUK_TAG_UNDEFINED:
2686 case DUK_TAG_NULL:
2687 return DUK_TYPE_MASK_NULL;
2688 case DUK_TAG_BOOLEAN:
2689 return DUK_TYPE_MASK_BOOLEAN;
2690 case DUK_TAG_STRING:
2691 return DUK_TYPE_MASK_STRING;
2692 case DUK_TAG_OBJECT:
2693 return DUK_TYPE_MASK_OBJECT;
2694 case DUK_TAG_BUFFER:
2695 return DUK_TYPE_MASK_BUFFER;
2696 case DUK_TAG_POINTER:
2697 return DUK_TYPE_MASK_POINTER;
2698 case DUK_TAG_LIGHTFUNC:
2700#if defined(DUK_USE_FASTINT)
2701 case DUK_TAG_FASTINT:
2702#endif
2703 default:
2704 /* Note: number has no explicit tag (in 8-byte representation) */
2707 return DUK_TYPE_MASK_NUMBER;
2708 }
2710}
#define DUK_TYPE_MASK_STRING
#define DUK_TYPE_MASK_OBJECT
#define DUK_TYPE_MASK_BUFFER
#define DUK_TYPE_MASK_LIGHTFUNC
#define DUK_TYPE_MASK_NUMBER
#define DUK_TYPE_MASK_BOOLEAN
#define DUK_TYPE_MASK_POINTER
#define DUK_TYPE_MASK_UNDEFINED

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TAG_BOOLEAN, DUK_TAG_BUFFER, DUK_TAG_LIGHTFUNC, DUK_TAG_NULL, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, DUK_TAG_UNDEFINED, DUK_TVAL_GET_TAG, DUK_TVAL_IS_NUMBER, DUK_TVAL_IS_UNUSED, DUK_TYPE_MASK_BOOLEAN, DUK_TYPE_MASK_BUFFER, DUK_TYPE_MASK_LIGHTFUNC, DUK_TYPE_MASK_NONE, DUK_TYPE_MASK_NULL, DUK_TYPE_MASK_NUMBER, DUK_TYPE_MASK_OBJECT, DUK_TYPE_MASK_POINTER, DUK_TYPE_MASK_STRING, DUK_TYPE_MASK_UNDEFINED, DUK_UNREACHABLE, and index.

Referenced by duk_check_type_mask(), and duk_to_object_class_string_top().

◆ duk_get_uint()

DUK_EXTERNAL duk_uint_t duk_get_uint ( duk_context * ctx,
duk_idx_t index )

Definition at line 1173 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1173 {
1174 /* Custom coercion for API */
1176 return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 0 /*require*/);
1177}
DUK_LOCAL duk_uint_t duk__api_coerce_d2ui(duk_context *ctx, duk_idx_t index, duk_bool_t require)

References duk__api_coerce_d2ui(), DUK_ASSERT_CTX_VALID, and index.

◆ duk_insert()

DUK_EXTERNAL void duk_insert ( duk_context * ctx,
duk_idx_t to_index )

Definition at line 867 of file duktape-1.5.2/src-separate/duk_api_stack.c.

867 {
868 duk_tval *p;
869 duk_tval *q;
870 duk_tval tv_tmp;
871 duk_size_t nbytes;
872
874
875 p = duk_require_tval(ctx, to_index);
876 DUK_ASSERT(p != NULL);
877 q = duk_require_tval(ctx, -1);
878 DUK_ASSERT(q != NULL);
879
880 DUK_ASSERT(q >= p);
881
882 /* nbytes
883 * <--------->
884 * [ ... | p | x | x | q ]
885 * => [ ... | q | p | x | x ]
886 */
887
888 nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */
889
890 DUK_DDD(DUK_DDDPRINT("duk_insert: to_index=%ld, p=%p, q=%p, nbytes=%lu",
891 (long) to_index, (void *) p, (void *) q, (unsigned long) nbytes));
892
893 /* No net refcount changes. */
894
895 if (nbytes > 0) {
896 DUK_TVAL_SET_TVAL(&tv_tmp, q);
897 DUK_ASSERT(nbytes > 0);
898 DUK_MEMMOVE((void *) (p + 1), (const void *) p, (size_t) nbytes);
899 DUK_TVAL_SET_TVAL(p, &tv_tmp);
900 } else {
901 /* nop: insert top to top */
902 DUK_ASSERT(nbytes == 0);
903 DUK_ASSERT(p == q);
904 }
905}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_DDD, DUK_DDDPRINT, DUK_MEMMOVE, duk_require_tval(), DUK_TVAL_SET_TVAL, and NULL.

◆ duk_instanceof()

DUK_EXTERNAL duk_bool_t duk_instanceof ( duk_context * ctx,
duk_idx_t index1,
duk_idx_t index2 )

Definition at line 4446 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4446 {
4447 duk_tval *tv1, *tv2;
4448
4450
4451 /* Index validation is strict, which differs from duk_equals().
4452 * The strict behavior mimics how instanceof itself works, e.g.
4453 * it is a TypeError if rval is not a -callable- object. It would
4454 * be somewhat inconsistent if rval would be allowed to be
4455 * non-existent without a TypeError.
4456 */
4457 tv1 = duk_require_tval(ctx, index1);
4458 DUK_ASSERT(tv1 != NULL);
4459 tv2 = duk_require_tval(ctx, index2);
4460 DUK_ASSERT(tv2 != NULL);
4461
4462 return duk_js_instanceof((duk_hthread *) ctx, tv1, tv2);
4463}
DUK_INTERNAL_DECL duk_bool_t duk_js_instanceof(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_js_instanceof(), duk_require_tval(), and NULL.

◆ duk_is_array()

DUK_EXTERNAL duk_bool_t duk_is_array ( duk_context * ctx,
duk_idx_t index )

Definition at line 2818 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2818 {
2819 duk_hobject *obj;
2820
2822
2823 obj = duk_get_hobject(ctx, index);
2824 if (obj) {
2826 }
2827 return 0;
2828}
#define DUK_HOBJECT_CLASS_ARRAY

References DUK_ASSERT_CTX_VALID, duk_get_hobject(), DUK_HOBJECT_CLASS_ARRAY, DUK_HOBJECT_GET_CLASS_NUMBER, and index.

◆ duk_is_boolean()

DUK_EXTERNAL duk_bool_t duk_is_boolean ( duk_context * ctx,
duk_idx_t index )

Definition at line 2751 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2751 {
2753 return duk__tag_check(ctx, index, DUK_TAG_BOOLEAN);
2754}
DUK_LOCAL duk_bool_t duk__tag_check(duk_context *ctx, duk_idx_t index, duk_small_uint_t tag)

References duk__tag_check(), DUK_ASSERT_CTX_VALID, DUK_TAG_BOOLEAN, and index.

◆ duk_is_bound_function()

DUK_EXTERNAL duk_bool_t duk_is_bound_function ( duk_context * ctx,
duk_idx_t index )

Definition at line 2860 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2860 {
2863 index,
2865}
#define DUK_HOBJECT_FLAG_BOUND
DUK_LOCAL duk_bool_t duk__obj_flag_any_default_false(duk_context *ctx, duk_idx_t index, duk_uint_t flag_mask)

References duk__obj_flag_any_default_false(), DUK_ASSERT_CTX_VALID, DUK_HOBJECT_FLAG_BOUND, and index.

◆ duk_is_buffer()

DUK_EXTERNAL duk_bool_t duk_is_buffer ( duk_context * ctx,
duk_idx_t index )

◆ duk_is_c_function()

◆ duk_is_dynamic_buffer()

DUK_EXTERNAL duk_bool_t duk_is_dynamic_buffer ( duk_context * ctx,
duk_idx_t index )

Definition at line 2888 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2888 {
2889 duk_tval *tv;
2890
2892
2893 tv = duk_get_tval(ctx, index);
2894 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
2896 DUK_ASSERT(h != NULL);
2897 return (DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h) ? 1 : 0);
2898 }
2899 return 0;
2900}
#define DUK_HBUFFER_HAS_EXTERNAL(x)
#define DUK_HBUFFER_HAS_DYNAMIC(x)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HBUFFER_HAS_DYNAMIC, DUK_HBUFFER_HAS_EXTERNAL, DUK_TVAL_GET_BUFFER, DUK_TVAL_IS_BUFFER, index, and NULL.

◆ duk_is_ecmascript_function()

◆ duk_is_external_buffer()

DUK_EXTERNAL duk_bool_t duk_is_external_buffer ( duk_context * ctx,
duk_idx_t index )

Definition at line 2902 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2902 {
2903 duk_tval *tv;
2904
2906
2907 tv = duk_get_tval(ctx, index);
2908 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
2910 DUK_ASSERT(h != NULL);
2911 return (DUK_HBUFFER_HAS_DYNAMIC(h) && DUK_HBUFFER_HAS_EXTERNAL(h) ? 1 : 0);
2912 }
2913 return 0;
2914}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HBUFFER_HAS_DYNAMIC, DUK_HBUFFER_HAS_EXTERNAL, DUK_TVAL_GET_BUFFER, DUK_TVAL_IS_BUFFER, index, and NULL.

◆ duk_is_fixed_buffer()

DUK_EXTERNAL duk_bool_t duk_is_fixed_buffer ( duk_context * ctx,
duk_idx_t index )

Definition at line 2874 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2874 {
2875 duk_tval *tv;
2876
2878
2879 tv = duk_get_tval(ctx, index);
2880 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
2882 DUK_ASSERT(h != NULL);
2883 return (DUK_HBUFFER_HAS_DYNAMIC(h) ? 0 : 1);
2884 }
2885 return 0;
2886}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HBUFFER_HAS_DYNAMIC, DUK_TVAL_GET_BUFFER, DUK_TVAL_IS_BUFFER, index, and NULL.

◆ duk_is_function()

◆ duk_is_lightfunc()

DUK_EXTERNAL duk_bool_t duk_is_lightfunc ( duk_context * ctx,
duk_idx_t index )

◆ duk_is_nan()

DUK_EXTERNAL duk_bool_t duk_is_nan ( duk_context * ctx,
duk_idx_t index )

Definition at line 2775 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2775 {
2776 /* XXX: This will now return false for non-numbers, even though they would
2777 * coerce to NaN (as a general rule). In particular, duk_get_number()
2778 * returns a NaN for non-numbers, so should this function also return
2779 * true for non-numbers?
2780 */
2781
2782 duk_tval *tv;
2783
2785
2786 tv = duk_get_tval(ctx, index);
2787 if (!tv || !DUK_TVAL_IS_NUMBER(tv)) {
2788 return 0;
2789 }
2790 return DUK_ISNAN(DUK_TVAL_GET_NUMBER(tv));
2791}

References DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_ISNAN, DUK_TVAL_GET_NUMBER, DUK_TVAL_IS_NUMBER, and index.

◆ duk_is_null()

DUK_EXTERNAL duk_bool_t duk_is_null ( duk_context * ctx,
duk_idx_t index )

Definition at line 2732 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2732 {
2734 return duk__tag_check(ctx, index, DUK_TAG_NULL);
2735}

References duk__tag_check(), DUK_ASSERT_CTX_VALID, DUK_TAG_NULL, and index.

◆ duk_is_null_or_undefined()

DUK_EXTERNAL duk_bool_t duk_is_null_or_undefined ( duk_context * ctx,
duk_idx_t index )

Definition at line 2737 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2737 {
2738 duk_tval *tv;
2739 duk_small_uint_t tag;
2740
2742
2743 tv = duk_get_tval(ctx, index);
2744 if (!tv) {
2745 return 0;
2746 }
2747 tag = DUK_TVAL_GET_TAG(tv);
2748 return (tag == DUK_TAG_UNDEFINED) || (tag == DUK_TAG_NULL);
2749}

References DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TAG_NULL, DUK_TAG_UNDEFINED, DUK_TVAL_GET_TAG, and index.

◆ duk_is_number()

DUK_EXTERNAL duk_bool_t duk_is_number ( duk_context * ctx,
duk_idx_t index )

Definition at line 2756 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2756 {
2757 duk_tval *tv;
2758
2760
2761 /*
2762 * Number is special because it doesn't have a specific
2763 * tag in the 8-byte representation.
2764 */
2765
2766 /* XXX: shorter version for 12-byte representation? */
2767
2768 tv = duk_get_tval(ctx, index);
2769 if (!tv) {
2770 return 0;
2771 }
2772 return DUK_TVAL_IS_NUMBER(tv);
2773}

References DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_TVAL_IS_NUMBER, and index.

◆ duk_is_object()

DUK_EXTERNAL duk_bool_t duk_is_object ( duk_context * ctx,
duk_idx_t index )

◆ duk_is_pointer()

DUK_EXTERNAL duk_bool_t duk_is_pointer ( duk_context * ctx,
duk_idx_t index )

◆ duk_is_string()

DUK_EXTERNAL duk_bool_t duk_is_string ( duk_context * ctx,
duk_idx_t index )

Definition at line 2793 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2793 {
2795 return duk__tag_check(ctx, index, DUK_TAG_STRING);
2796}

References duk__tag_check(), DUK_ASSERT_CTX_VALID, DUK_TAG_STRING, and index.

Referenced by duk_safe_to_lstring().

◆ duk_is_thread()

◆ duk_is_undefined()

DUK_EXTERNAL duk_bool_t duk_is_undefined ( duk_context * ctx,
duk_idx_t index )

◆ duk_is_valid_index()

DUK_EXTERNAL duk_bool_t duk_is_valid_index ( duk_context * ctx,
duk_idx_t index )

Definition at line 307 of file duktape-1.5.2/src-separate/duk_api_stack.c.

307 {
310
311 return (duk_normalize_index(ctx, index) >= 0);
312}
DUK_EXTERNAL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_INVALID_INDEX, duk_normalize_index(), and index.

◆ duk_normalize_index()

DUK_EXTERNAL duk_idx_t duk_normalize_index ( duk_context * ctx,
duk_idx_t index )

Definition at line 183 of file duktape-1.5.2/src-separate/duk_api_stack.c.

183 {
184 duk_hthread *thr = (duk_hthread *) ctx;
185 duk_uidx_t vs_size;
186 duk_uidx_t uindex;
187
190
191 /* Care must be taken to avoid pointer wrapping in the index
192 * validation. For instance, on a 32-bit platform with 8-byte
193 * duk_tval the index 0x20000000UL would wrap the memory space
194 * once.
195 */
196
197 /* Assume value stack sizes (in elements) fits into duk_idx_t. */
199 vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
200 DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */
201
202 if (index < 0) {
203 uindex = vs_size + (duk_uidx_t) index;
204 } else {
205 /* since index non-negative */
207 uindex = (duk_uidx_t) index;
208 }
209
210 /* DUK_INVALID_INDEX won't be accepted as a valid index. */
211 DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
212
213 if (DUK_LIKELY(uindex < vs_size)) {
214 return (duk_idx_t) uindex;
215 }
216 return DUK_INVALID_INDEX;
217}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_INVALID_INDEX, DUK_LIKELY, index, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk_is_valid_index(), and duk_require_valid_index().

◆ duk_pop()

DUK_EXTERNAL void duk_pop ( duk_context * ctx)

Definition at line 4273 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4273 {
4274 duk_hthread *thr = (duk_hthread *) ctx;
4275 duk_tval *tv;
4277
4279 if (DUK_UNLIKELY(thr->valstack_top == thr->valstack_bottom)) {
4281 }
4282
4283 tv = --thr->valstack_top; /* tv points to element just below prev top */
4284 DUK_ASSERT(tv >= thr->valstack_bottom);
4285#ifdef DUK_USE_REFERENCE_COUNTING
4286 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
4287#else
4289#endif
4291}
#define DUK_TVAL_SET_UNDEFINED_UPDREF

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_STR_POP_TOO_MANY, DUK_TVAL_SET_UNDEFINED, DUK_TVAL_SET_UNDEFINED_UPDREF, DUK_UNLIKELY, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk__defaultvalue_coerce_attempt(), duk__push_stash(), duk_safe_to_lstring(), and duk_to_object_class_string_top().

◆ duk_pop_2()

DUK_EXTERNAL void duk_pop_2 ( duk_context * ctx)

Definition at line 4294 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4294 {
4296 duk_pop_n(ctx, 2);
4297}
DUK_EXTERNAL void duk_pop_n(duk_context *ctx, duk_idx_t count)

References DUK_ASSERT_CTX_VALID, and duk_pop_n().

◆ duk_pop_3()

DUK_EXTERNAL void duk_pop_3 ( duk_context * ctx)

Definition at line 4299 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4299 {
4301 duk_pop_n(ctx, 3);
4302}

References DUK_ASSERT_CTX_VALID, and duk_pop_n().

◆ duk_pop_n()

DUK_EXTERNAL void duk_pop_n ( duk_context * ctx,
duk_idx_t count )

Definition at line 4215 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4215 {
4216 duk_hthread *thr = (duk_hthread *) ctx;
4217 duk_tval *tv;
4218
4220
4221 if (DUK_UNLIKELY(count < 0)) {
4223 return;
4224 }
4225
4227 if (DUK_UNLIKELY((duk_size_t) (thr->valstack_top - thr->valstack_bottom) < (duk_size_t) count)) {
4229 }
4230
4231 /*
4232 * Must be very careful here, every DECREF may cause reallocation
4233 * of our valstack.
4234 */
4235
4236 /* XXX: inlined DECREF macro would be nice here: no NULL check,
4237 * refzero queueing but no refzero algorithm run (= no pointer
4238 * instability), inline code.
4239 */
4240
4241 /* XXX: optimize loops */
4242
4243#if defined(DUK_USE_REFERENCE_COUNTING)
4244 while (count > 0) {
4245 count--;
4246 tv = --thr->valstack_top; /* tv points to element just below prev top */
4247 DUK_ASSERT(tv >= thr->valstack_bottom);
4248 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
4249 }
4250#else
4251 tv = thr->valstack_top;
4252 while (count > 0) {
4253 count--;
4254 tv--;
4255 DUK_ASSERT(tv >= thr->valstack_bottom);
4257 }
4258 thr->valstack_top = tv;
4259#endif
4260
4262}
#define DUK_STR_INVALID_COUNT

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_STR_INVALID_COUNT, DUK_STR_POP_TOO_MANY, DUK_TVAL_SET_UNDEFINED, DUK_TVAL_SET_UNDEFINED_UPDREF, DUK_UNLIKELY, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk_pop_2(), and duk_pop_3().

◆ duk_push_array()

DUK_EXTERNAL duk_idx_t duk_push_array ( duk_context * ctx)

Definition at line 3585 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3585 {
3586 duk_hthread *thr = (duk_hthread *) ctx;
3587 duk_hobject *obj;
3588 duk_idx_t ret;
3589
3591
3592 ret = duk_push_object_helper(ctx,
3597
3598 obj = duk_require_hobject(ctx, ret);
3599
3600 /*
3601 * An array must have a 'length' property (E5 Section 15.4.5.2).
3602 * The special array behavior flag must only be enabled once the
3603 * length property has been added.
3604 *
3605 * The internal property must be a number (and preferably a
3606 * fastint if fastint support is enabled).
3607 */
3608
3609 duk_push_int(ctx, 0);
3610#if defined(DUK_USE_FASTINT)
3611 DUK_ASSERT(DUK_TVAL_IS_FASTINT(duk_require_tval(ctx, -1)));
3612#endif
3613
3615 obj,
3619
3620 return ret;
3621}
#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h)
#define DUK_HOBJECT_CLASS_AS_FLAGS(v)
#define DUK_BIDX_ARRAY_PROTOTYPE
DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags)
#define DUK_HOBJECT_FLAG_EXTENSIBLE
#define DUK_HTHREAD_STRING_LENGTH(thr)
#define DUK_HOBJECT_FLAG_ARRAY_PART
DUK_EXTERNAL void duk_push_int(duk_context *ctx, duk_int_t val)
DUK_INTERNAL duk_idx_t duk_push_object_helper(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_BIDX_ARRAY_PROTOTYPE, DUK_HOBJECT_CLASS_ARRAY, DUK_HOBJECT_CLASS_AS_FLAGS, duk_hobject_define_property_internal(), DUK_HOBJECT_FLAG_ARRAY_PART, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_SET_EXOTIC_ARRAY, DUK_HTHREAD_STRING_LENGTH, DUK_PROPDESC_FLAGS_W, duk_push_int(), duk_push_object_helper(), duk_require_hobject(), and duk_require_tval().

◆ duk_push_boolean()

DUK_EXTERNAL void duk_push_boolean ( duk_context * ctx,
duk_bool_t val )

Definition at line 3000 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3000 {
3001 duk_hthread *thr;
3002 duk_tval *tv_slot;
3004
3006 thr = (duk_hthread *) ctx;
3008 b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */
3009 tv_slot = thr->valstack_top++;
3010 DUK_TVAL_SET_BOOLEAN(tv_slot, b);
3011}
#define DUK_TVAL_SET_BOOLEAN(tv, val)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_BOOLEAN, and duk_hthread::valstack_top.

◆ duk_push_buffer_object()

DUK_EXTERNAL void duk_push_buffer_object ( duk_context * ctx,
duk_idx_t idx_buffer,
duk_size_t byte_offset,
duk_size_t byte_length,
duk_uint_t flags )

Definition at line 3921 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3921 {
3922 duk_hthread *thr;
3923 duk_hbufferobject *h_bufobj;
3924 duk_hbuffer *h_val;
3925 duk_uint32_t tmp;
3926 duk_uint_t classnum;
3927 duk_uint_t protobidx;
3928 duk_uint_t lookupidx;
3929 duk_uint_t uint_offset, uint_length, uint_added;
3930
3932 thr = (duk_hthread *) ctx;
3933 DUK_UNREF(thr);
3934
3935 /* The underlying types for offset/length in duk_hbufferobject is
3936 * duk_uint_t; make sure argument values fit and that offset + length
3937 * does not wrap.
3938 */
3939 uint_offset = (duk_uint_t) byte_offset;
3940 uint_length = (duk_uint_t) byte_length;
3941 if (sizeof(duk_size_t) != sizeof(duk_uint_t)) {
3942 if ((duk_size_t) uint_offset != byte_offset || (duk_size_t) uint_length != byte_length) {
3943 goto range_error;
3944 }
3945 }
3946 uint_added = uint_offset + uint_length;
3947 if (uint_added < uint_offset) {
3948 goto range_error;
3949 }
3950 DUK_ASSERT(uint_added >= uint_offset && uint_added >= uint_length);
3951
3952 DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */
3953 lookupidx = flags & 0x0f; /* 4 low bits */
3954 if (lookupidx >= sizeof(duk__bufobj_flags_lookup) / sizeof(duk_uint32_t)) {
3955 goto arg_error;
3956 }
3957 tmp = duk__bufobj_flags_lookup[lookupidx];
3958 classnum = tmp >> 24;
3959 protobidx = (tmp >> 16) & 0xff;
3960
3961 h_val = duk_require_hbuffer(ctx, idx_buffer);
3962 DUK_ASSERT(h_val != NULL);
3963
3964 h_bufobj = duk_push_bufferobject_raw(ctx,
3968 protobidx);
3969 DUK_ASSERT(h_bufobj != NULL);
3970
3971 h_bufobj->buf = h_val;
3972 DUK_HBUFFER_INCREF(thr, h_val);
3973 h_bufobj->offset = uint_offset;
3974 h_bufobj->length = uint_length;
3975 h_bufobj->shift = (tmp >> 4) & 0x0f;
3976 h_bufobj->elem_type = (tmp >> 8) & 0xff;
3977 h_bufobj->is_view = tmp & 0x0f;
3979
3980#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
3981 /* TypedArray views need an automatic ArrayBuffer which must be
3982 * provided as .buffer property of the view. Just create a new
3983 * ArrayBuffer sharing the same underlying buffer.
3984 */
3985 if (flags & DUK_BUFOBJ_CREATE_ARRBUF) {
3986 h_bufobj = duk_push_bufferobject_raw(ctx,
3991
3992 DUK_ASSERT(h_bufobj != NULL);
3993
3994 h_bufobj->buf = h_val;
3995 DUK_HBUFFER_INCREF(thr, h_val);
3996 h_bufobj->offset = uint_offset;
3997 h_bufobj->length = uint_length;
3998 DUK_ASSERT(h_bufobj->shift == 0);
4000 DUK_ASSERT(h_bufobj->is_view == 0);
4002
4004 duk_compact(ctx, -1);
4005 }
4006#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
4007
4008 return;
4009
4010 range_error:
4012 return; /* not reached */
4013
4014 arg_error:
4016 return; /* not reached */
4017}
#define DUK_BIDX_ARRAYBUFFER_PROTOTYPE
#define DUK_ERROR_RANGE(thr, msg)
#define DUK_HBUFFER_INCREF(thr, h)
DUK_EXTERNAL void duk_compact(duk_context *ctx, duk_idx_t obj_index)
#define DUK_PROPDESC_FLAGS_NONE
#define DUK_HOBJECT_FLAG_BUFFEROBJECT
#define DUK_HOBJECT_CLASS_ARRAYBUFFER
#define DUK_HBUFFEROBJECT_ELEM_UINT8
#define DUK_BUFOBJ_CREATE_ARRBUF
static const duk_uint32_t duk__bufobj_flags_lookup[]
DUK_INTERNAL duk_hbuffer * duk_require_hbuffer(duk_context *ctx, duk_idx_t index)
DUK_INTERNAL duk_hbufferobject * duk_push_bufferobject_raw(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx)

References duk_hbufferobject::buf, duk__bufobj_flags_lookup, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_ASSERT_HBUFFEROBJECT_VALID, DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_BUFOBJ_CREATE_ARRBUF, duk_compact(), DUK_ERROR_RANGE, DUK_ERROR_TYPE, DUK_HBUFFER_INCREF, DUK_HBUFFEROBJECT_ELEM_UINT8, DUK_HOBJECT_CLASS_ARRAYBUFFER, DUK_HOBJECT_CLASS_AS_FLAGS, DUK_HOBJECT_FLAG_BUFFEROBJECT, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_PROPDESC_FLAGS_NONE, duk_push_bufferobject_raw(), duk_require_hbuffer(), DUK_STR_INVALID_CALL_ARGS, DUK_STRIDX_LC_BUFFER, DUK_UNREF, duk_xdef_prop_stridx(), duk_hbufferobject::elem_type, duk_hbufferobject::is_view, duk_hbufferobject::length, NULL, duk_hbufferobject::offset, and duk_hbufferobject::shift.

◆ duk_push_buffer_raw()

DUK_EXTERNAL void * duk_push_buffer_raw ( duk_context * ctx,
duk_size_t size,
duk_small_uint_t flags )

Definition at line 4101 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4101 {
4102 duk_hthread *thr = (duk_hthread *) ctx;
4103 duk_tval *tv_slot;
4104 duk_hbuffer *h;
4105 void *buf_data;
4106
4108
4109 /* check stack first */
4110 if (thr->valstack_top >= thr->valstack_end) {
4112 }
4113
4114 /* Check for maximum buffer length. */
4115 if (size > DUK_HBUFFER_MAX_BYTELEN) {
4117 }
4118
4119 h = duk_hbuffer_alloc(thr->heap, size, flags, &buf_data);
4120 if (!h) {
4122 }
4123
4124 tv_slot = thr->valstack_top;
4125 DUK_TVAL_SET_BUFFER(tv_slot, h);
4126 DUK_HBUFFER_INCREF(thr, h);
4127 thr->valstack_top++;
4128
4129 return (void *) buf_data;
4130}
#define DUK_HBUFFER_MAX_BYTELEN
#define DUK_TVAL_SET_BUFFER(tv, hptr)
#define DUK_STR_BUFFER_TOO_LONG
DUK_INTERNAL_DECL duk_hbuffer * duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata)

References DUK_ASSERT_CTX_VALID, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_API, DUK_ERROR_RANGE, duk_hbuffer_alloc(), DUK_HBUFFER_INCREF, DUK_HBUFFER_MAX_BYTELEN, DUK_STR_BUFFER_TOO_LONG, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_SET_BUFFER, duk_hthread::heap, duk_hthread::valstack_end, and duk_hthread::valstack_top.

◆ duk_push_bufferobject_raw()

DUK_INTERNAL duk_hbufferobject * duk_push_bufferobject_raw ( duk_context * ctx,
duk_uint_t hobject_flags_and_class,
duk_small_int_t prototype_bidx )

Definition at line 3862 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3862 {
3863 duk_hthread *thr = (duk_hthread *) ctx;
3864 duk_hbufferobject *obj;
3865 duk_tval *tv_slot;
3866
3867 DUK_ASSERT(ctx != NULL);
3868 DUK_ASSERT(prototype_bidx >= 0);
3869
3870 /* check stack first */
3871 if (thr->valstack_top >= thr->valstack_end) {
3873 }
3874
3875 obj = duk_hbufferobject_alloc(thr->heap, hobject_flags_and_class);
3876 if (!obj) {
3878 }
3879
3880 DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, thr->builtins[prototype_bidx]);
3882
3883 tv_slot = thr->valstack_top;
3884 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3885 DUK_HOBJECT_INCREF(thr, obj);
3886 thr->valstack_top++;
3887
3888 return obj;
3889}
DUK_INTERNAL duk_hbufferobject * duk_hbufferobject_alloc(duk_heap *heap, duk_uint_t hobject_flags)

References duk_hthread::builtins, DUK_ASSERT, DUK_ASSERT_HBUFFEROBJECT_VALID, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_API, duk_hbufferobject_alloc(), DUK_HOBJECT_INCREF, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_SET_OBJECT, duk_hthread::heap, NULL, duk_hthread::valstack_end, and duk_hthread::valstack_top.

Referenced by duk_push_buffer_object(), and duk_to_object().

◆ duk_push_c_function()

DUK_EXTERNAL duk_idx_t duk_push_c_function ( duk_context * ctx,
duk_c_function func,
duk_int_t nargs )

Definition at line 3777 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3777 {
3778 duk_uint_t flags;
3779
3781
3790
3791 return duk__push_c_function_raw(ctx, func, nargs, flags);
3792}
#define DUK_HOBJECT_FLAG_NEWENV
#define DUK_HOBJECT_FLAG_CONSTRUCTABLE
#define DUK_HOBJECT_FLAG_NOTAIL
#define DUK_HOBJECT_CLASS_FUNCTION
#define DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC
#define DUK_HOBJECT_FLAG_STRICT
DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_uint_t flags)

References duk__push_c_function_raw(), DUK_ASSERT_CTX_VALID, DUK_HOBJECT_CLASS_AS_FLAGS, DUK_HOBJECT_CLASS_FUNCTION, DUK_HOBJECT_FLAG_CONSTRUCTABLE, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_NATIVEFUNCTION, DUK_HOBJECT_FLAG_NEWENV, DUK_HOBJECT_FLAG_NOTAIL, and DUK_HOBJECT_FLAG_STRICT.

◆ duk_push_c_function_noconstruct_noexotic()

◆ duk_push_c_function_noexotic()

◆ duk_push_c_lightfunc()

DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc ( duk_context * ctx,
duk_c_function func,
duk_idx_t nargs,
duk_idx_t length,
duk_int_t magic )

Definition at line 3825 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3825 {
3826 duk_hthread *thr = (duk_hthread *) ctx;
3827 duk_tval tv_tmp;
3828 duk_small_uint_t lf_flags;
3829
3831
3832 /* check stack first */
3833 if (thr->valstack_top >= thr->valstack_end) {
3835 }
3836
3837 if (nargs >= DUK_LFUNC_NARGS_MIN && nargs <= DUK_LFUNC_NARGS_MAX) {
3838 /* as is */
3839 } else if (nargs == DUK_VARARGS) {
3841 } else {
3842 goto api_error;
3843 }
3844 if (!(length >= DUK_LFUNC_LENGTH_MIN && length <= DUK_LFUNC_LENGTH_MAX)) {
3845 goto api_error;
3846 }
3847 if (!(magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX)) {
3848 goto api_error;
3849 }
3850
3851 lf_flags = DUK_LFUNC_FLAGS_PACK(magic, length, nargs);
3852 DUK_TVAL_SET_LIGHTFUNC(&tv_tmp, func, lf_flags);
3853 duk_push_tval(ctx, &tv_tmp); /* XXX: direct valstack write */
3855 return ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
3856
3857 api_error:
3859 return 0; /* not reached */
3860}
#define DUK_LFUNC_NARGS_MAX
#define DUK_LFUNC_LENGTH_MAX
#define DUK_LFUNC_MAGIC_MIN
#define DUK_LFUNC_NARGS_VARARGS
#define DUK_LFUNC_FLAGS_PACK(magic, length, nargs)
#define DUK_LFUNC_LENGTH_MIN
#define DUK_LFUNC_NARGS_MIN
#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags)
#define DUK_LFUNC_MAGIC_MAX
DUK_INTERNAL void duk_push_tval(duk_context *ctx, duk_tval *tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_LFUNC_FLAGS_PACK, DUK_LFUNC_LENGTH_MAX, DUK_LFUNC_LENGTH_MIN, DUK_LFUNC_MAGIC_MAX, DUK_LFUNC_MAGIC_MIN, DUK_LFUNC_NARGS_MAX, DUK_LFUNC_NARGS_MIN, DUK_LFUNC_NARGS_VARARGS, duk_push_tval(), DUK_STR_INVALID_CALL_ARGS, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_SET_LIGHTFUNC, DUK_VARARGS, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

◆ duk_push_compiledfunction()

DUK_INTERNAL duk_idx_t duk_push_compiledfunction ( duk_context * ctx)

Definition at line 3686 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3686 {
3687 duk_hthread *thr = (duk_hthread *) ctx;
3689 duk_idx_t ret;
3690 duk_tval *tv_slot;
3691
3693
3694 /* check stack first */
3695 if (thr->valstack_top >= thr->valstack_end) {
3697 }
3698
3699 /* Template functions are not strictly constructable (they don't
3700 * have a "prototype" property for instance), so leave the
3701 * DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
3702 */
3703
3708 if (!obj) {
3710 }
3711
3712 DUK_DDD(DUK_DDDPRINT("created compiled function object with flags: 0x%08lx", (unsigned long) obj->obj.hdr.h_flags));
3713
3714 tv_slot = thr->valstack_top;
3715 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3716 DUK_HOBJECT_INCREF(thr, obj);
3717 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3718 thr->valstack_top++;
3719
3720 /* default prototype (Note: 'obj' must be reachable) */
3722
3723 return ret;
3724}
DUK_INTERNAL_DECL duk_hcompiledfunction * duk_hcompiledfunction_alloc(duk_heap *heap, duk_uint_t hobject_flags)

References duk_hthread::builtins, DUK_ASSERT_CTX_VALID, DUK_BIDX_FUNCTION_PROTOTYPE, DUK_DDD, DUK_DDDPRINT, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_API, duk_hcompiledfunction_alloc(), DUK_HOBJECT_CLASS_AS_FLAGS, DUK_HOBJECT_CLASS_FUNCTION, DUK_HOBJECT_FLAG_COMPILEDFUNCTION, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_INCREF, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_SET_OBJECT, duk_heaphdr::h_flags, duk_hobject::hdr, duk_hthread::heap, duk_hcompiledfunction::obj, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

◆ duk_push_current_function()

DUK_EXTERNAL void duk_push_current_function ( duk_context * ctx)

Definition at line 3347 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3347 {
3348 duk_hthread *thr = (duk_hthread *) ctx;
3349 duk_activation *act;
3350
3352 DUK_ASSERT(thr != NULL);
3355
3357 if (act) {
3358 duk_push_tval(ctx, &act->tv_func);
3359 } else {
3360 duk_push_undefined(ctx);
3361 }
3362}
DUK_INTERNAL_DECL duk_activation * duk_hthread_get_current_activation(duk_hthread *thr)
DUK_EXTERNAL void duk_push_undefined(duk_context *ctx)

References duk_hthread::callstack_size, duk_hthread::callstack_top, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, duk_hthread_get_current_activation(), duk_push_tval(), duk_push_undefined(), NULL, and duk_activation::tv_func.

◆ duk_push_current_thread()

DUK_EXTERNAL void duk_push_current_thread ( duk_context * ctx)

Definition at line 3364 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3364 {
3365 duk_hthread *thr = (duk_hthread *) ctx;
3366
3368 DUK_ASSERT(thr != NULL);
3369
3370 if (thr->heap->curr_thread) {
3372 } else {
3373 duk_push_undefined(ctx);
3374 }
3375}
DUK_INTERNAL void duk_push_hobject(duk_context *ctx, duk_hobject *h)

References duk_heap::curr_thread, DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_push_hobject(), duk_push_undefined(), duk_hthread::heap, and NULL.

◆ duk_push_error_object_raw()

DUK_EXTERNAL duk_idx_t duk_push_error_object_raw ( duk_context * ctx,
duk_errcode_t err_code,
const char * filename,
duk_int_t line,
const char * fmt,
... )

Definition at line 4071 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4071 {
4072 va_list ap;
4073 duk_idx_t ret;
4074
4076
4077 va_start(ap, fmt);
4078 ret = duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4079 va_end(ap);
4080 return ret;
4081}

References DUK_ASSERT_CTX_VALID, and duk_push_error_object_va_raw().

◆ duk_push_error_object_stash()

DUK_EXTERNAL duk_idx_t duk_push_error_object_stash ( duk_context * ctx,
duk_errcode_t err_code,
const char * fmt,
... )

Definition at line 4084 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4084 {
4085 const char *filename = duk_api_global_filename;
4087 va_list ap;
4088 duk_idx_t ret;
4089
4091
4094 va_start(ap, fmt);
4095 ret = duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4096 va_end(ap);
4097 return ret;
4098}

References duk_api_global_filename, duk_api_global_line, DUK_ASSERT_CTX_VALID, duk_push_error_object_va_raw(), and NULL.

◆ duk_push_error_object_va_raw()

DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw ( duk_context * ctx,
duk_errcode_t err_code,
const char * filename,
duk_int_t line,
const char * fmt,
va_list ap )

Definition at line 4019 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4019 {
4020 duk_hthread *thr = (duk_hthread *) ctx;
4021 duk_idx_t ret;
4023#ifdef DUK_USE_AUGMENT_ERROR_CREATE
4024 duk_bool_t noblame_fileline;
4025#endif
4026
4028 DUK_ASSERT(thr != NULL);
4029 DUK_UNREF(filename);
4030 DUK_UNREF(line);
4031
4032 /* Error code also packs a tracedata related flag. */
4033#ifdef DUK_USE_AUGMENT_ERROR_CREATE
4034 noblame_fileline = err_code & DUK_ERRCODE_FLAG_NOBLAME_FILELINE;
4035#endif
4036 err_code = err_code & (~DUK_ERRCODE_FLAG_NOBLAME_FILELINE);
4037
4038 /* error gets its 'name' from the prototype */
4039 proto = duk_error_prototype_from_code(thr, err_code);
4043 proto);
4044
4045 /* ... and its 'message' from an instance property */
4046 if (fmt) {
4047 duk_push_vsprintf(ctx, fmt, ap);
4049 } else {
4050 /* If no explicit message given, put error code into message field
4051 * (as a number). This is not fully in keeping with the Ecmascript
4052 * error model because messages are supposed to be strings (Error
4053 * constructors use ToString() on their argument). However, it's
4054 * probably more useful than having a separate 'code' property.
4055 */
4056 duk_push_int(ctx, err_code);
4058 }
4059
4060 /* XXX: .code = err_code disabled, not sure if useful */
4061
4062 /* Creation time error augmentation */
4063#ifdef DUK_USE_AUGMENT_ERROR_CREATE
4064 /* filename may be NULL in which case file/line is not recorded */
4065 duk_err_augment_error_create(thr, thr, filename, line, noblame_fileline); /* may throw an error */
4066#endif
4067
4068 return ret;
4069}
const char * proto
Definition civetweb.c:18378
DUK_INTERNAL_DECL duk_hobject * duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t err_code)
DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_bool_t noblame_fileline)
#define DUK_HOBJECT_CLASS_ERROR
#define DUK_PROPDESC_FLAGS_WC
#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE
DUK_INTERNAL duk_idx_t duk_push_object_helper_proto(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_hobject *proto)
DUK_EXTERNAL const char * duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_err_augment_error_create(), DUK_ERRCODE_FLAG_NOBLAME_FILELINE, duk_error_prototype_from_code(), DUK_HOBJECT_CLASS_AS_FLAGS, DUK_HOBJECT_CLASS_ERROR, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_PROPDESC_FLAGS_WC, duk_push_int(), duk_push_object_helper_proto(), duk_push_vsprintf(), DUK_STRIDX_MESSAGE, DUK_UNREF, duk_xdef_prop_stridx(), NULL, and proto.

Referenced by duk_error_raw(), duk_error_stash(), duk_error_va_raw(), duk_push_error_object_raw(), and duk_push_error_object_stash().

◆ duk_push_false()

DUK_EXTERNAL void duk_push_false ( duk_context * ctx)

Definition at line 3024 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3024 {
3025 duk_hthread *thr;
3026 duk_tval *tv_slot;
3027
3029 thr = (duk_hthread *) ctx;
3031 tv_slot = thr->valstack_top++;
3033}
#define DUK_TVAL_SET_BOOLEAN_FALSE(v)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_BOOLEAN_FALSE, and duk_hthread::valstack_top.

◆ duk_push_global_object()

DUK_EXTERNAL void duk_push_global_object ( duk_context * ctx)

Definition at line 3377 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3377 {
3379
3381}
DUK_INTERNAL void duk_push_hobject_bidx(duk_context *ctx, duk_small_int_t builtin_idx)

References DUK_ASSERT_CTX_VALID, DUK_BIDX_GLOBAL, and duk_push_hobject_bidx().

Referenced by duk_push_global_stash().

◆ duk_push_global_stash()

DUK_EXTERNAL void duk_push_global_stash ( duk_context * ctx)

Definition at line 3406 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3406 {
3409 duk__push_stash(ctx);
3410}
DUK_LOCAL void duk__push_stash(duk_context *ctx)
DUK_EXTERNAL void duk_push_global_object(duk_context *ctx)

References duk__push_stash(), DUK_ASSERT_CTX_VALID, and duk_push_global_object().

◆ duk_push_hbuffer()

DUK_INTERNAL void duk_push_hbuffer ( duk_context * ctx,
duk_hbuffer * h )

Definition at line 4194 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4194 {
4195 duk_tval tv;
4197 DUK_ASSERT(h != NULL);
4198 DUK_TVAL_SET_BUFFER(&tv, h);
4199 duk_push_tval(ctx, &tv);
4200}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_push_tval(), DUK_TVAL_SET_BUFFER, and NULL.

Referenced by duk_push_heapptr().

◆ duk_push_heap_stash()

DUK_EXTERNAL void duk_push_heap_stash ( duk_context * ctx)

◆ duk_push_heapptr()

DUK_EXTERNAL duk_idx_t duk_push_heapptr ( duk_context * ctx,
void * ptr )

Definition at line 4132 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4132 {
4133 duk_hthread *thr = (duk_hthread *) ctx;
4134 duk_idx_t ret;
4135
4137
4138 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
4139
4140 if (ptr == NULL) {
4141 goto push_undefined;
4142 }
4143
4144 switch ((int) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) ptr)) {
4145 case DUK_HTYPE_STRING:
4146 duk_push_hstring(ctx, (duk_hstring *) ptr);
4147 break;
4148 case DUK_HTYPE_OBJECT:
4149 duk_push_hobject(ctx, (duk_hobject *) ptr);
4150 break;
4151 case DUK_HTYPE_BUFFER:
4152 duk_push_hbuffer(ctx, (duk_hbuffer *) ptr);
4153 break;
4154 default:
4155 goto push_undefined;
4156 }
4157 return ret;
4158
4159 push_undefined:
4160 duk_push_undefined(ctx);
4161 return ret;
4162}
#define DUK_HEAPHDR_GET_TYPE(h)
DUK_INTERNAL void duk_push_hstring(duk_context *ctx, duk_hstring *h)
DUK_INTERNAL void duk_push_hbuffer(duk_context *ctx, duk_hbuffer *h)

References DUK_ASSERT_CTX_VALID, DUK_HEAPHDR_GET_TYPE, DUK_HTYPE_BUFFER, DUK_HTYPE_OBJECT, DUK_HTYPE_STRING, duk_push_hbuffer(), duk_push_hobject(), duk_push_hstring(), duk_push_undefined(), NULL, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

◆ duk_push_hobject()

◆ duk_push_hobject_bidx()

DUK_INTERNAL void duk_push_hobject_bidx ( duk_context * ctx,
duk_small_int_t builtin_idx )

Definition at line 4202 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4202 {
4203 duk_hthread *thr = (duk_hthread *) ctx;
4205 DUK_ASSERT(thr != NULL);
4206 DUK_ASSERT(builtin_idx >= 0 && builtin_idx < DUK_NUM_BUILTINS);
4207 DUK_ASSERT(thr->builtins[builtin_idx] != NULL);
4208 duk_push_hobject(ctx, thr->builtins[builtin_idx]);
4209}

References duk_hthread::builtins, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_NUM_BUILTINS, duk_push_hobject(), and NULL.

Referenced by duk_push_global_object().

◆ duk_push_hobject_class_string()

DUK_INTERNAL void duk_push_hobject_class_string ( duk_context * ctx,
duk_hobject * h )

Definition at line 2128 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2128 {
2129 duk_hthread *thr;
2130 duk_hstring *h_strclass;
2131
2133 DUK_ASSERT(h != NULL);
2134 thr = (duk_hthread *) ctx;
2135 DUK_UNREF(thr);
2136
2137 h_strclass = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h);
2138 DUK_ASSERT(h_strclass != NULL);
2139 duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
2140}
#define DUK_HOBJECT_GET_CLASS_STRING(heap, h)
DUK_EXTERNAL const char * duk_push_sprintf(duk_context *ctx, const char *fmt,...)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_HOBJECT_GET_CLASS_STRING, DUK_HSTRING_GET_DATA, duk_push_sprintf(), DUK_UNREF, duk_hthread::heap, and NULL.

Referenced by duk_push_string_tval_readable().

◆ duk_push_hstring()

DUK_INTERNAL void duk_push_hstring ( duk_context * ctx,
duk_hstring * h )

Definition at line 4171 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4171 {
4172 duk_tval tv;
4174 DUK_ASSERT(h != NULL);
4175 DUK_TVAL_SET_STRING(&tv, h);
4176 duk_push_tval(ctx, &tv);
4177}
#define DUK_TVAL_SET_STRING(tv, hptr)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_push_tval(), DUK_TVAL_SET_STRING, and NULL.

Referenced by duk_push_heapptr(), and duk_push_hstring_stridx().

◆ duk_push_hstring_stridx()

DUK_INTERNAL void duk_push_hstring_stridx ( duk_context * ctx,
duk_small_int_t stridx )

Definition at line 4179 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4179 {
4180 duk_hthread *thr = (duk_hthread *) ctx;
4181 DUK_UNREF(thr);
4182 DUK_ASSERT(stridx >= 0 && stridx < DUK_HEAP_NUM_STRINGS);
4183 duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
4184}
#define DUK_HTHREAD_GET_STRING(thr, idx)

References DUK_ASSERT, DUK_HEAP_NUM_STRINGS, DUK_HTHREAD_GET_STRING, duk_push_hstring(), and DUK_UNREF.

Referenced by duk_push_vsprintf(), duk_safe_to_lstring(), and duk_to_string().

◆ duk_push_int()

DUK_EXTERNAL void duk_push_int ( duk_context * ctx,
duk_int_t val )

Definition at line 3050 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3050 {
3051#if defined(DUK_USE_FASTINT)
3052 duk_hthread *thr;
3053 duk_tval *tv_slot;
3054
3056 thr = (duk_hthread *) ctx;
3058 tv_slot = thr->valstack_top++;
3059#if DUK_INT_MAX <= 0x7fffffffL
3060 DUK_TVAL_SET_FASTINT_I32(tv_slot, (duk_int32_t) val);
3061#else
3062 if (val >= DUK_FASTINT_MIN && val <= DUK_FASTINT_MAX) {
3063 DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val);
3064 } else {
3065 duk_double_t = (duk_double_t) val;
3066 DUK_TVAL_SET_NUMBER(tv_slot, d);
3067 }
3068#endif
3069#else /* DUK_USE_FASTINT */
3070 duk_hthread *thr;
3071 duk_tval *tv_slot;
3072 duk_double_t d;
3073
3075 thr = (duk_hthread *) ctx;
3077 d = (duk_double_t) val;
3078 tv_slot = thr->valstack_top++;
3079 DUK_TVAL_SET_NUMBER(tv_slot, d);
3080#endif /* DUK_USE_FASTINT */
3081}
#define DUK_TVAL_SET_FASTINT(tv, val)
#define DUK_TVAL_SET_FASTINT_I32(tv, val)
#define DUK_TVAL_SET_NUMBER(tv, val)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_FASTINT, DUK_TVAL_SET_FASTINT_I32, DUK_TVAL_SET_NUMBER, and duk_hthread::valstack_top.

Referenced by duk_push_array(), duk_push_error_object_va_raw(), and duk_to_object().

◆ duk_push_lightfunc_name()

DUK_INTERNAL void duk_push_lightfunc_name ( duk_context * ctx,
duk_tval * tv )

Definition at line 4469 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4469 {
4470 duk_c_function func;
4471
4473
4474 /* Lightfunc name, includes Duktape/C native function pointer, which
4475 * can often be used to locate the function from a symbol table.
4476 * The name also includes the 16-bit duk_tval flags field because it
4477 * includes the magic value. Because a single native function often
4478 * provides different functionality depending on the magic value, it
4479 * seems reasonably to include it in the name.
4480 *
4481 * On the other hand, a complicated name increases string table
4482 * pressure in low memory environments (but only when function name
4483 * is accessed).
4484 */
4485
4487 duk_push_sprintf(ctx, "light_");
4488 duk_push_string_funcptr(ctx, (duk_uint8_t *) &func, sizeof(func));
4489 duk_push_sprintf(ctx, "_%04x", (unsigned int) DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv));
4490 duk_concat(ctx, 3);
4491}
DUK_EXTERNAL void duk_concat(duk_context *ctx, duk_idx_t count)
#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv)
duk_ret_t(* duk_c_function)(duk_context *ctx)
DUK_INTERNAL void duk_push_string_funcptr(duk_context *ctx, duk_uint8_t *ptr, duk_size_t sz)

References DUK_ASSERT, duk_concat(), duk_push_sprintf(), duk_push_string_funcptr(), DUK_TVAL_GET_LIGHTFUNC_FLAGS, DUK_TVAL_GET_LIGHTFUNC_FUNCPTR, and DUK_TVAL_IS_LIGHTFUNC.

Referenced by duk_push_lightfunc_tostring(), and duk_to_object().

◆ duk_push_lightfunc_tostring()

DUK_INTERNAL void duk_push_lightfunc_tostring ( duk_context * ctx,
duk_tval * tv )

Definition at line 4493 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4493 {
4495
4496 duk_push_string(ctx, "function ");
4497 duk_push_lightfunc_name(ctx, tv);
4498 duk_push_string(ctx, "() {\"light\"}");
4499 duk_concat(ctx, 3);
4500}
DUK_EXTERNAL const char * duk_push_string(duk_context *ctx, const char *str)
DUK_INTERNAL void duk_push_lightfunc_name(duk_context *ctx, duk_tval *tv)

References DUK_ASSERT, duk_concat(), duk_push_lightfunc_name(), duk_push_string(), and DUK_TVAL_IS_LIGHTFUNC.

Referenced by duk_to_string().

◆ duk_push_lstring()

DUK_EXTERNAL const char * duk_push_lstring ( duk_context * ctx,
const char * str,
duk_size_t len )

Definition at line 3131 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3131 {
3132 duk_hthread *thr = (duk_hthread *) ctx;
3133 duk_hstring *h;
3134 duk_tval *tv_slot;
3135
3137
3138 /* check stack before interning (avoid hanging temp) */
3139 if (thr->valstack_top >= thr->valstack_end) {
3141 }
3142
3143 /* NULL with zero length represents an empty string; NULL with higher
3144 * length is also now trated like an empty string although it is
3145 * a bit dubious. This is unlike duk_push_string() which pushes a
3146 * 'null' if the input string is a NULL.
3147 */
3148 if (!str) {
3149 len = 0;
3150 }
3151
3152 /* Check for maximum string length */
3153 if (len > DUK_HSTRING_MAX_BYTELEN) {
3155 }
3156
3157 h = duk_heap_string_intern_checked(thr, (const duk_uint8_t *) str, (duk_uint32_t) len);
3158 DUK_ASSERT(h != NULL);
3159
3160 tv_slot = thr->valstack_top++;
3161 DUK_TVAL_SET_STRING(tv_slot, h);
3162 DUK_HSTRING_INCREF(thr, h); /* no side effects */
3163
3164 return (const char *) DUK_HSTRING_GET_DATA(h);
3165}
#define DUK_STR_STRING_TOO_LONG
DUK_INTERNAL_DECL duk_hstring * duk_heap_string_intern_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t len)
#define DUK_HSTRING_INCREF(thr, h)
#define DUK_HSTRING_MAX_BYTELEN

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_ERROR_RANGE, duk_heap_string_intern_checked(), DUK_HSTRING_GET_DATA, DUK_HSTRING_INCREF, DUK_HSTRING_MAX_BYTELEN, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_STR_STRING_TOO_LONG, DUK_TVAL_SET_STRING, NULL, duk_hthread::valstack_end, and duk_hthread::valstack_top.

Referenced by duk__push_hstring_readable_unicode(), duk_push_string(), duk_push_string_funcptr(), duk_push_vsprintf(), and duk_to_string().

◆ duk_push_nan()

DUK_EXTERNAL void duk_push_nan ( duk_context * ctx)

◆ duk_push_null()

DUK_EXTERNAL void duk_push_null ( duk_context * ctx)

Definition at line 2989 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2989 {
2990 duk_hthread *thr;
2991 duk_tval *tv_slot;
2992
2994 thr = (duk_hthread *) ctx;
2996 tv_slot = thr->valstack_top++;
2997 DUK_TVAL_SET_NULL(tv_slot);
2998}
#define DUK_TVAL_SET_NULL(tv)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_NULL, and duk_hthread::valstack_top.

Referenced by duk_push_string().

◆ duk_push_number()

DUK_EXTERNAL void duk_push_number ( duk_context * ctx,
duk_double_t val )

Definition at line 3036 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3036 {
3037 duk_hthread *thr;
3038 duk_tval *tv_slot;
3040
3042 thr = (duk_hthread *) ctx;
3044 du.d = val;
3046 tv_slot = thr->valstack_top++;
3047 DUK_TVAL_SET_NUMBER(tv_slot, du.d);
3048}

References duk_double_union::d, DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_DBLUNION_NORMALIZE_NAN_CHECK, DUK_TVAL_SET_NUMBER, and duk_hthread::valstack_top.

◆ duk_push_object()

◆ duk_push_object_helper()

DUK_INTERNAL duk_idx_t duk_push_object_helper ( duk_context * ctx,
duk_uint_t hobject_flags_and_class,
duk_small_int_t prototype_bidx )

Definition at line 3521 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3521 {
3522 duk_hthread *thr = (duk_hthread *) ctx;
3523 duk_tval *tv_slot;
3524 duk_hobject *h;
3525 duk_idx_t ret;
3526
3528 DUK_ASSERT(prototype_bidx == -1 ||
3529 (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS));
3530
3531 /* check stack first */
3532 if (thr->valstack_top >= thr->valstack_end) {
3534 }
3535
3536 h = duk_hobject_alloc(thr->heap, hobject_flags_and_class);
3537 if (!h) {
3539 }
3540
3541 DUK_DDD(DUK_DDDPRINT("created object with flags: 0x%08lx", (unsigned long) h->hdr.h_flags));
3542
3543 tv_slot = thr->valstack_top;
3544 DUK_TVAL_SET_OBJECT(tv_slot, h);
3545 DUK_HOBJECT_INCREF(thr, h); /* no side effects */
3546 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3547 thr->valstack_top++;
3548
3549 /* object is now reachable */
3550
3551 if (prototype_bidx >= 0) {
3552 DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, thr->builtins[prototype_bidx]);
3553 } else {
3554 DUK_ASSERT(prototype_bidx == -1);
3556 }
3557
3558 return ret;
3559}
DUK_INTERNAL_DECL duk_hobject * duk_hobject_alloc(duk_heap *heap, duk_uint_t hobject_flags)

References duk_hthread::builtins, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_DDD, DUK_DDDPRINT, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_API, duk_hobject_alloc(), DUK_HOBJECT_GET_PROTOTYPE, DUK_HOBJECT_INCREF, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, DUK_NUM_BUILTINS, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_SET_OBJECT, duk_heaphdr::h_flags, duk_hobject::hdr, duk_hthread::heap, NULL, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

Referenced by duk_push_array(), duk_push_object(), duk_push_object_helper_proto(), duk_push_object_internal(), and duk_to_object().

◆ duk_push_object_helper_proto()

DUK_INTERNAL duk_idx_t duk_push_object_helper_proto ( duk_context * ctx,
duk_uint_t hobject_flags_and_class,
duk_hobject * proto )

Definition at line 3561 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3561 {
3562 duk_hthread *thr = (duk_hthread *) ctx;
3563 duk_idx_t ret;
3564 duk_hobject *h;
3565
3567
3568 ret = duk_push_object_helper(ctx, hobject_flags_and_class, -1);
3569 h = duk_get_hobject(ctx, -1);
3570 DUK_ASSERT(h != NULL);
3573 return ret;
3574}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_hobject(), DUK_HOBJECT_GET_PROTOTYPE, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, duk_push_object_helper(), duk_hthread::heap, NULL, and proto.

Referenced by duk_push_error_object_va_raw().

◆ duk_push_object_internal()

◆ duk_push_pointer()

DUK_EXTERNAL void duk_push_pointer ( duk_context * ctx,
void * val )

Definition at line 3248 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3248 {
3249 duk_hthread *thr;
3250 duk_tval *tv_slot;
3251
3253 thr = (duk_hthread *) ctx;
3255 tv_slot = thr->valstack_top++;
3256 DUK_TVAL_SET_POINTER(tv_slot, val);
3257}
#define DUK_TVAL_SET_POINTER(tv, hptr)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_POINTER, and duk_hthread::valstack_top.

Referenced by duk_to_pointer().

◆ duk_push_sprintf()

DUK_EXTERNAL const char * duk_push_sprintf ( duk_context * ctx,
const char * fmt,
... )

Definition at line 3507 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3507 {
3508 va_list ap;
3509 const char *ret;
3510
3512
3513 /* allow fmt==NULL */
3514 va_start(ap, fmt);
3515 ret = duk_push_vsprintf(ctx, fmt, ap);
3516 va_end(ap);
3517
3518 return ret;
3519}

References DUK_ASSERT_CTX_VALID, and duk_push_vsprintf().

Referenced by duk_push_hobject_class_string(), duk_push_lightfunc_name(), duk_push_string_tval_readable(), duk_to_object_class_string_top(), and duk_to_string().

◆ duk_push_string()

DUK_EXTERNAL const char * duk_push_string ( duk_context * ctx,
const char * str )

Definition at line 3167 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3167 {
3169
3170 if (str) {
3171 return duk_push_lstring(ctx, str, DUK_STRLEN(str));
3172 } else {
3173 duk_push_null(ctx);
3174 return NULL;
3175 }
3176}
DUK_EXTERNAL void duk_push_null(duk_context *ctx)

References DUK_ASSERT_CTX_VALID, duk_push_lstring(), duk_push_null(), DUK_STRLEN, and NULL.

Referenced by duk_push_lightfunc_tostring(), and duk_push_string_tval_readable().

◆ duk_push_string_file_raw()

DUK_EXTERNAL const char * duk_push_string_file_raw ( duk_context * ctx,
const char * path,
duk_uint_t flags )

Definition at line 3183 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3183 {
3184 duk_hthread *thr = (duk_hthread *) ctx;
3185 duk_file *f = NULL;
3186 char *buf;
3187 long sz; /* ANSI C typing */
3188
3190
3191 if (!path) {
3192 goto fail;
3193 }
3194 f = DUK_FOPEN(path, "rb");
3195 if (!f) {
3196 goto fail;
3197 }
3198 if (DUK_FSEEK(f, 0, SEEK_END) < 0) {
3199 goto fail;
3200 }
3201 sz = DUK_FTELL(f);
3202 if (sz < 0) {
3203 goto fail;
3204 }
3205 if (DUK_FSEEK(f, 0, SEEK_SET) < 0) {
3206 goto fail;
3207 }
3208 buf = (char *) duk_push_fixed_buffer(ctx, (duk_size_t) sz);
3209 DUK_ASSERT(buf != NULL);
3210 if ((duk_size_t) DUK_FREAD(buf, 1, (size_t) sz, f) != (duk_size_t) sz) {
3211 goto fail;
3212 }
3213 (void) DUK_FCLOSE(f); /* ignore fclose() error */
3214 f = NULL;
3215 return duk_to_string(ctx, -1);
3216
3217 fail:
3218 if (f) {
3219 DUK_FCLOSE(f);
3220 }
3221
3222 if (flags != 0) {
3223 DUK_ASSERT(flags == DUK_STRING_PUSH_SAFE); /* only flag now */
3224 duk_push_undefined(ctx);
3225 } else {
3226 /* XXX: string not shared because it is conditional */
3227 DUK_ERROR_TYPE(thr, "read file error");
3228 }
3229 return NULL;
3230}
#define DUK_STRING_PUSH_SAFE
#define duk_push_fixed_buffer(ctx, size)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_TYPE, DUK_FCLOSE, DUK_FOPEN, DUK_FREAD, DUK_FSEEK, DUK_FTELL, duk_push_fixed_buffer, duk_push_undefined(), DUK_STRING_PUSH_SAFE, duk_to_string(), and NULL.

◆ duk_push_string_funcptr()

DUK_INTERNAL void duk_push_string_funcptr ( duk_context * ctx,
duk_uint8_t * ptr,
duk_size_t sz )

Definition at line 4509 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4509 {
4510 duk_uint8_t buf[32 * 2];
4511 duk_uint8_t *p, *q;
4514
4515 DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */
4516
4517 p = buf;
4518#if defined(DUK_USE_INTEGER_LE)
4519 q = ptr + sz;
4520#else
4521 q = ptr;
4522#endif
4523 for (i = 0; i < sz; i++) {
4524#if defined(DUK_USE_INTEGER_LE)
4525 t = *(--q);
4526#else
4527 t = *(q++);
4528#endif
4529 *p++ = duk_lc_digits[t >> 4];
4530 *p++ = duk_lc_digits[t & 0x0f];
4531 }
4532
4533 duk_push_lstring(ctx, (const char *) buf, sz * 2);
4534}

References DUK_ASSERT, duk_lc_digits, and duk_push_lstring().

Referenced by duk_push_lightfunc_name().

◆ duk_push_string_readable()

DUK_INTERNAL const char * duk_push_string_readable ( duk_context * ctx,
duk_idx_t index )

Definition at line 4650 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4650 {
4653}
DUK_INTERNAL const char * duk_push_string_tval_readable(duk_context *ctx, duk_tval *tv)

References DUK_ASSERT_CTX_VALID, duk_get_tval(), duk_push_string_tval_readable(), and index.

◆ duk_push_string_tval_readable()

DUK_INTERNAL const char * duk_push_string_tval_readable ( duk_context * ctx,
duk_tval * tv )

Definition at line 4603 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4603 {
4604 duk_hthread *thr;
4605
4607 thr = (duk_hthread *) ctx;
4608 DUK_UNREF(thr);
4609
4610 if (tv == NULL) {
4611 duk_push_string(ctx, "none");
4612 } else {
4613 switch (DUK_TVAL_GET_TAG(tv)) {
4614 case DUK_TAG_STRING: {
4616 break;
4617 }
4618 case DUK_TAG_OBJECT: {
4620 DUK_ASSERT(h != NULL);
4622 break;
4623 }
4624 case DUK_TAG_BUFFER: {
4625 /* XXX: Hex encoded, length limited buffer summary here? */
4627 DUK_ASSERT(h != NULL);
4628 duk_push_sprintf(ctx, "[buffer:%ld]", (long) DUK_HBUFFER_GET_SIZE(h));
4629 break;
4630 }
4631 case DUK_TAG_POINTER: {
4632 /* Surround with parentheses like in JX, ensures NULL pointer
4633 * is distinguishable from null value ("(null)" vs "null").
4634 */
4635 duk_push_tval(ctx, tv);
4636 duk_push_sprintf(ctx, "(%s)", duk_to_string(ctx, -1));
4637 duk_remove(ctx, -2);
4638 break;
4639 }
4640 default: {
4641 duk_push_tval(ctx, tv);
4642 break;
4643 }
4644 }
4645 }
4646
4647 return duk_to_string(ctx, -1);
4648}
DUK_LOCAL void duk__push_hstring_readable_unicode(duk_context *ctx, duk_hstring *h_input)
DUK_INTERNAL void duk_push_hobject_class_string(duk_context *ctx, duk_hobject *h)

References duk__push_hstring_readable_unicode(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_HBUFFER_GET_SIZE, duk_push_hobject_class_string(), duk_push_sprintf(), duk_push_string(), duk_push_tval(), duk_remove(), DUK_TAG_BUFFER, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, duk_to_string(), DUK_TVAL_GET_BUFFER, DUK_TVAL_GET_OBJECT, DUK_TVAL_GET_STRING, DUK_TVAL_GET_TAG, DUK_UNREF, and NULL.

Referenced by duk_push_string_readable().

◆ duk_push_this()

DUK_EXTERNAL void duk_push_this ( duk_context * ctx)

Definition at line 3298 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3298 {
3300
3301 duk__push_this_helper(ctx, 0 /*check_object_coercible*/);
3302}
DUK_LOCAL void duk__push_this_helper(duk_context *ctx, duk_small_uint_t check_object_coercible)

References duk__push_this_helper(), and DUK_ASSERT_CTX_VALID.

◆ duk_push_this_check_object_coercible()

DUK_INTERNAL void duk_push_this_check_object_coercible ( duk_context * ctx)

Definition at line 3304 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3304 {
3306
3307 duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
3308}

References duk__push_this_helper(), and DUK_ASSERT_CTX_VALID.

◆ duk_push_this_coercible_to_object()

DUK_INTERNAL duk_hobject * duk_push_this_coercible_to_object ( duk_context * ctx)

Definition at line 3310 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3310 {
3311 duk_hobject *h;
3312
3314
3315 duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
3316 duk_to_object(ctx, -1);
3317 h = duk_get_hobject(ctx, -1);
3318 DUK_ASSERT(h != NULL);
3319 return h;
3320}

References duk__push_this_helper(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_hobject(), duk_to_object(), and NULL.

◆ duk_push_this_coercible_to_string()

DUK_INTERNAL duk_hstring * duk_push_this_coercible_to_string ( duk_context * ctx)

Definition at line 3322 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3322 {
3323 duk_hstring *h;
3324
3326
3327 duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
3328 duk_to_string(ctx, -1);
3329 h = duk_get_hstring(ctx, -1);
3330 DUK_ASSERT(h != NULL);
3331 return h;
3332}
DUK_INTERNAL duk_hstring * duk_get_hstring(duk_context *ctx, duk_idx_t index)

References duk__push_this_helper(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_hstring(), duk_to_string(), and NULL.

◆ duk_push_thread_raw()

DUK_EXTERNAL duk_idx_t duk_push_thread_raw ( duk_context * ctx,
duk_uint_t flags )

Definition at line 3623 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3623 {
3624 duk_hthread *thr = (duk_hthread *) ctx;
3625 duk_hthread *obj;
3626 duk_idx_t ret;
3627 duk_tval *tv_slot;
3628
3630
3631 /* check stack first */
3632 if (thr->valstack_top >= thr->valstack_end) {
3634 }
3635
3636 obj = duk_hthread_alloc(thr->heap,
3640 if (!obj) {
3642 }
3644#if defined(DUK_USE_ROM_STRINGS)
3645 /* Nothing to initialize, strs[] is in ROM. */
3646#else
3647#if defined(DUK_USE_HEAPPTR16)
3648 obj->strs16 = thr->strs16;
3649#else
3650 obj->strs = thr->strs;
3651#endif
3652#endif
3653 DUK_DDD(DUK_DDDPRINT("created thread object with flags: 0x%08lx", (unsigned long) obj->obj.hdr.h_flags));
3654
3655 /* make the new thread reachable */
3656 tv_slot = thr->valstack_top;
3657 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3658 DUK_HTHREAD_INCREF(thr, obj);
3659 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3660 thr->valstack_top++;
3661
3662 /* important to do this *after* pushing, to make the thread reachable for gc */
3663 if (!duk_hthread_init_stacks(thr->heap, obj)) {
3665 }
3666
3667 /* initialize built-ins - either by copying or creating new ones */
3668 if (flags & DUK_THREAD_NEW_GLOBAL_ENV) {
3670 } else {
3672 }
3673
3674 /* default prototype (Note: 'obj' must be reachable) */
3676
3677 /* Initial stack size satisfies the stack spare constraints so there
3678 * is no need to require stack here.
3679 */
3682
3683 return ret;
3684}
DUK_INTERNAL_DECL void duk_hthread_create_builtin_objects(duk_hthread *thr)
DUK_INTERNAL_DECL duk_hthread * duk_hthread_alloc(duk_heap *heap, duk_uint_t hobject_flags)
#define DUK_HTHREAD_STATE_INACTIVE
#define DUK_HTHREAD_INCREF(thr, h)
DUK_INTERNAL_DECL duk_bool_t duk_hthread_init_stacks(duk_heap *heap, duk_hthread *thr)
#define DUK_HOBJECT_CLASS_THREAD
#define DUK_VALSTACK_INITIAL_SIZE
#define DUK_BIDX_THREAD_PROTOTYPE
#define DUK_VALSTACK_API_ENTRY_MINIMUM
DUK_INTERNAL_DECL void duk_hthread_copy_builtin_objects(duk_hthread *thr_from, duk_hthread *thr_to)
#define DUK_THREAD_NEW_GLOBAL_ENV

References duk_hthread::builtins, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_BIDX_THREAD_PROTOTYPE, DUK_DDD, DUK_DDDPRINT, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_API, DUK_HOBJECT_CLASS_AS_FLAGS, DUK_HOBJECT_CLASS_THREAD, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_THREAD, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, duk_hthread_alloc(), duk_hthread_copy_builtin_objects(), duk_hthread_create_builtin_objects(), DUK_HTHREAD_INCREF, duk_hthread_init_stacks(), DUK_HTHREAD_STATE_INACTIVE, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_THREAD_NEW_GLOBAL_ENV, DUK_TVAL_SET_OBJECT, DUK_VALSTACK_API_ENTRY_MINIMUM, DUK_VALSTACK_INITIAL_SIZE, DUK_VALSTACK_INTERNAL_EXTRA, duk_heaphdr::h_flags, duk_hobject::hdr, duk_hthread::heap, duk_hthread::obj, duk_hthread::state, duk_hthread::strs, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

◆ duk_push_thread_stash()

DUK_EXTERNAL void duk_push_thread_stash ( duk_context * ctx,
duk_context * target_ctx )

Definition at line 3412 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3412 {
3413 duk_hthread *thr = (duk_hthread *) ctx;
3415 if (!target_ctx) {
3417 return; /* not reached */
3418 }
3419 duk_push_hobject(ctx, (duk_hobject *) target_ctx);
3420 duk__push_stash(ctx);
3421}

References duk__push_stash(), DUK_ASSERT_CTX_VALID, DUK_ERROR_API, duk_push_hobject(), and DUK_STR_INVALID_CALL_ARGS.

◆ duk_push_true()

DUK_EXTERNAL void duk_push_true ( duk_context * ctx)

Definition at line 3013 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3013 {
3014 duk_hthread *thr;
3015 duk_tval *tv_slot;
3016
3018 thr = (duk_hthread *) ctx;
3020 tv_slot = thr->valstack_top++;
3022}
#define DUK_TVAL_SET_BOOLEAN_TRUE(v)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_BOOLEAN_TRUE, and duk_hthread::valstack_top.

◆ duk_push_tval()

DUK_INTERNAL void duk_push_tval ( duk_context * ctx,
duk_tval * tv )

◆ duk_push_uint()

DUK_EXTERNAL void duk_push_uint ( duk_context * ctx,
duk_uint_t val )

Definition at line 3083 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3083 {
3084#if defined(DUK_USE_FASTINT)
3085 duk_hthread *thr;
3086 duk_tval *tv_slot;
3087
3089 thr = (duk_hthread *) ctx;
3091 tv_slot = thr->valstack_top++;
3092#if DUK_UINT_MAX <= 0xffffffffUL
3093 DUK_TVAL_SET_FASTINT_U32(tv_slot, (duk_uint32_t) val);
3094#else
3095 if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */
3096 /* XXX: take advantage of val being unsigned, no need to mask */
3097 DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val);
3098 } else {
3099 duk_double_t = (duk_double_t) val;
3100 DUK_TVAL_SET_NUMBER(tv_slot, d);
3101 }
3102#endif
3103#else /* DUK_USE_FASTINT */
3104 duk_hthread *thr;
3105 duk_tval *tv_slot;
3106 duk_double_t d;
3107
3109 thr = (duk_hthread *) ctx;
3111 d = (duk_double_t) val;
3112 tv_slot = thr->valstack_top++;
3113 DUK_TVAL_SET_NUMBER(tv_slot, d);
3114#endif /* DUK_USE_FASTINT */
3115}
#define DUK_TVAL_SET_FASTINT_U32(tv, val)

References DUK__CHECK_SPACE, DUK_ASSERT_CTX_VALID, DUK_TVAL_SET_FASTINT, DUK_TVAL_SET_FASTINT_U32, DUK_TVAL_SET_NUMBER, and duk_hthread::valstack_top.

◆ duk_push_undefined()

DUK_EXTERNAL void duk_push_undefined ( duk_context * ctx)

Definition at line 2975 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2975 {
2976 duk_hthread *thr;
2977
2979 thr = (duk_hthread *) ctx;
2981
2982 /* Because value stack init policy is 'undefined above top',
2983 * we don't need to write, just assert.
2984 */
2985 thr->valstack_top++;
2987}

References DUK__CHECK_SPACE, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_TVAL_IS_UNDEFINED, and duk_hthread::valstack_top.

Referenced by duk_push_current_function(), duk_push_current_thread(), duk_push_heapptr(), and duk_push_string_file_raw().

◆ duk_push_vsprintf()

DUK_EXTERNAL const char * duk_push_vsprintf ( duk_context * ctx,
const char * fmt,
va_list ap )

Definition at line 3441 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3441 {
3442 duk_hthread *thr = (duk_hthread *) ctx;
3443 duk_uint8_t stack_buf[DUK_PUSH_SPRINTF_INITIAL_SIZE];
3445 duk_bool_t pushed_buf = 0;
3446 void *buf;
3447 duk_int_t len; /* XXX: duk_ssize_t */
3448 const char *res;
3449
3451
3452 /* special handling of fmt==NULL */
3453 if (!fmt) {
3454 duk_hstring *h_str;
3456 h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); /* rely on interning, must be this string */
3457 return (const char *) DUK_HSTRING_GET_DATA(h_str);
3458 }
3459
3460 /* initial estimate based on format string */
3461 sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */
3464 }
3465 DUK_ASSERT(sz > 0);
3466
3467 /* Try to make do with a stack buffer to avoid allocating a temporary buffer.
3468 * This works 99% of the time which is quite nice.
3469 */
3470 for (;;) {
3471 va_list ap_copy; /* copied so that 'ap' can be reused */
3472
3473 if (sz <= sizeof(stack_buf)) {
3474 buf = stack_buf;
3475 } else if (!pushed_buf) {
3476 pushed_buf = 1;
3477 buf = duk_push_dynamic_buffer(ctx, sz);
3478 } else {
3479 buf = duk_resize_buffer(ctx, -1, sz);
3480 }
3481 DUK_ASSERT(buf != NULL);
3482
3483 DUK_VA_COPY(ap_copy, ap);
3484 len = duk__try_push_vsprintf(ctx, buf, sz, fmt, ap_copy);
3485 va_end(ap_copy);
3486 if (len >= 0) {
3487 break;
3488 }
3489
3490 /* failed, resize and try again */
3491 sz = sz * 2;
3494 }
3495 }
3496
3497 /* Cannot use duk_to_string() on the buffer because it is usually
3498 * larger than 'len'. Also, 'buf' is usually a stack buffer.
3499 */
3500 res = duk_push_lstring(ctx, (const char *) buf, (duk_size_t) len); /* [ buf? res ] */
3501 if (pushed_buf) {
3502 duk_remove(ctx, -2);
3503 }
3504 return res;
3505}
#define DUK_VA_COPY(dest, src)
#define DUK_PUSH_SPRINTF_SANITY_LIMIT
#define DUK_PUSH_SPRINTF_INITIAL_SIZE
#define DUK_STRIDX_EMPTY_STRING
DUK_EXTERNAL void * duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size)
#define DUK_HTHREAD_STRING_EMPTY_STRING(thr)
#define DUK_STR_SPRINTF_TOO_LONG
#define duk_push_dynamic_buffer(ctx, size)
DUK_INTERNAL void duk_push_hstring_stridx(duk_context *ctx, duk_small_int_t stridx)
DUK_LOCAL duk_int_t duk__try_push_vsprintf(duk_context *ctx, void *buf, duk_size_t sz, const char *fmt, va_list ap)

References duk__try_push_vsprintf(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_HSTRING_GET_DATA, DUK_HTHREAD_STRING_EMPTY_STRING, duk_push_dynamic_buffer, duk_push_hstring_stridx(), duk_push_lstring(), DUK_PUSH_SPRINTF_INITIAL_SIZE, DUK_PUSH_SPRINTF_SANITY_LIMIT, duk_remove(), duk_resize_buffer(), DUK_STR_SPRINTF_TOO_LONG, DUK_STRIDX_EMPTY_STRING, DUK_STRLEN, DUK_VA_COPY, and NULL.

Referenced by duk_push_error_object_va_raw(), and duk_push_sprintf().

◆ duk_remove()

DUK_EXTERNAL void duk_remove ( duk_context * ctx,
duk_idx_t index )

Definition at line 947 of file duktape-1.5.2/src-separate/duk_api_stack.c.

947 {
948 duk_hthread *thr = (duk_hthread *) ctx;
949 duk_tval *p;
950 duk_tval *q;
951#ifdef DUK_USE_REFERENCE_COUNTING
952 duk_tval tv_tmp;
953#endif
954 duk_size_t nbytes;
955
957
958 p = duk_require_tval(ctx, index);
959 DUK_ASSERT(p != NULL);
960 q = duk_require_tval(ctx, -1);
961 DUK_ASSERT(q != NULL);
962
963 DUK_ASSERT(q >= p);
964
965 /* nbytes zero size case
966 * <--------->
967 * [ ... | p | x | x | q ] [ ... | p==q ]
968 * => [ ... | x | x | q ] [ ... ]
969 */
970
971#ifdef DUK_USE_REFERENCE_COUNTING
972 /* use a temp: decref only when valstack reachable values are correct */
973 DUK_TVAL_SET_TVAL(&tv_tmp, p);
974#endif
975
976 nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */
977 DUK_MEMMOVE((void *) p, (const void *) (p + 1), (size_t) nbytes); /* zero size not an issue: pointers are valid */
978
980 thr->valstack_top--;
981
982#ifdef DUK_USE_REFERENCE_COUNTING
983 DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */
984#endif
985}
#define DUK_TVAL_DECREF(thr, tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_MEMMOVE, duk_require_tval(), DUK_TVAL_DECREF, DUK_TVAL_SET_TVAL, DUK_TVAL_SET_UNDEFINED, index, NULL, and duk_hthread::valstack_top.

Referenced by duk__push_stash(), duk_push_string_tval_readable(), and duk_push_vsprintf().

◆ duk_replace()

DUK_EXTERNAL void duk_replace ( duk_context * ctx,
duk_idx_t to_index )

Definition at line 907 of file duktape-1.5.2/src-separate/duk_api_stack.c.

907 {
908 duk_hthread *thr = (duk_hthread *) ctx;
909 duk_tval *tv1;
910 duk_tval *tv2;
911 duk_tval tv_tmp;
912
914
915 tv1 = duk_require_tval(ctx, -1);
916 DUK_ASSERT(tv1 != NULL);
917 tv2 = duk_require_tval(ctx, to_index);
918 DUK_ASSERT(tv2 != NULL);
919
920 /* For tv1 == tv2, both pointing to stack top, the end result
921 * is same as duk_pop(ctx).
922 */
923 DUK_TVAL_SET_TVAL(&tv_tmp, tv2);
924 DUK_TVAL_SET_TVAL(tv2, tv1);
926 thr->valstack_top--;
927 DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */
928}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_DECREF, DUK_TVAL_SET_TVAL, DUK_TVAL_SET_UNDEFINED, NULL, and duk_hthread::valstack_top.

Referenced by duk__defaultvalue_coerce_attempt(), duk_safe_to_lstring(), duk_to_buffer_raw(), duk_to_object(), duk_to_pointer(), and duk_to_string().

◆ duk_require_boolean()

DUK_EXTERNAL duk_bool_t duk_require_boolean ( duk_context * ctx,
duk_idx_t index )

Definition at line 1107 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1107 {
1108 duk_hthread *thr = (duk_hthread *) ctx;
1109 duk_tval *tv;
1110
1112
1113 tv = duk_get_tval(ctx, index);
1114 if (tv && DUK_TVAL_IS_BOOLEAN(tv)) {
1116 DUK_ASSERT(ret == 0 || ret == 1);
1117 return ret;
1118 }
1120 return 0; /* not reachable */
1121}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_STR_NOT_BOOLEAN, DUK_TVAL_GET_BOOLEAN, DUK_TVAL_IS_BOOLEAN, and index.

◆ duk_require_buffer()

DUK_EXTERNAL void * duk_require_buffer ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size )

Definition at line 1328 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1328 {
1329 return duk__get_buffer_helper(ctx, index, out_size, 1 /*throw_flag*/);
1330}

References duk__get_buffer_helper(), and index.

◆ duk_require_buffer_data()

DUK_EXTERNAL void * duk_require_buffer_data ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size )

Definition at line 1390 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1390 {
1391 return duk__get_buffer_data_helper(ctx, index, out_size, 1 /*throw_flag*/);
1392}

References duk__get_buffer_data_helper(), and index.

◆ duk_require_c_function()

DUK_EXTERNAL duk_c_function duk_require_c_function ( duk_context * ctx,
duk_idx_t index )

Definition at line 1531 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1531 {
1532 duk_hthread *thr = (duk_hthread *) ctx;
1533 duk_c_function ret;
1534
1536
1537 ret = duk_get_c_function(ctx, index);
1538 if (!ret) {
1540 }
1541 return ret;
1542}
#define DUK_STR_NOT_NATIVEFUNCTION
DUK_EXTERNAL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_c_function(), DUK_STR_NOT_NATIVEFUNCTION, and index.

◆ duk_require_context()

DUK_EXTERNAL duk_context * duk_require_context ( duk_context * ctx,
duk_idx_t index )

Definition at line 1556 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1556 {
1558
1559 return (duk_context *) duk_require_hthread(ctx, index);
1560}
DUK_INTERNAL duk_hthread * duk_require_hthread(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, duk_require_hthread(), and index.

◆ duk_require_function()

DUK_EXTERNAL void duk_require_function ( duk_context * ctx,
duk_idx_t index )

Definition at line 1544 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1544 {
1545 if (!duk_is_function(ctx, index)) {
1547 }
1548}
DUK_EXTERNAL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index)

References DUK_ERROR_REQUIRE_TYPE_INDEX, duk_is_function(), DUK_STR_NOT_FUNCTION, and index.

◆ duk_require_hbuffer()

DUK_INTERNAL duk_hbuffer * duk_require_hbuffer ( duk_context * ctx,
duk_idx_t index )

◆ duk_require_hcompiledfunction()

◆ duk_require_heapptr()

DUK_EXTERNAL void * duk_require_heapptr ( duk_context * ctx,
duk_idx_t index )

Definition at line 1578 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1578 {
1579 duk_hthread *thr = (duk_hthread *) ctx;
1580 duk_tval *tv;
1581 void *ret;
1582
1584
1585 tv = duk_require_tval(ctx, index);
1586 DUK_ASSERT(tv != NULL);
1588 ret = (void *) DUK_TVAL_GET_HEAPHDR(tv);
1589 DUK_ASSERT(ret != NULL);
1590 return ret;
1591 }
1592
1594 return (void *) NULL; /* not reachable */
1595}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_require_tval(), DUK_STR_UNEXPECTED_TYPE, DUK_TVAL_GET_HEAPHDR, DUK_TVAL_IS_HEAP_ALLOCATED, index, and NULL.

◆ duk_require_hnativefunction()

◆ duk_require_hobject()

◆ duk_require_hobject_or_lfunc()

DUK_INTERNAL duk_hobject * duk_require_hobject_or_lfunc ( duk_context * ctx,
duk_idx_t index )

Definition at line 1630 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1630 {
1631 duk_hthread *thr = (duk_hthread *) ctx;
1632 duk_tval *tv;
1633
1635
1636 tv = duk_require_tval(ctx, index);
1637 DUK_ASSERT(tv != NULL);
1638 if (DUK_TVAL_IS_OBJECT(tv)) {
1639 return DUK_TVAL_GET_OBJECT(tv);
1640 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
1641 return NULL;
1642 }
1644 return NULL; /* not reachable */
1645}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_require_tval(), DUK_STR_NOT_OBJECT, DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_LIGHTFUNC, DUK_TVAL_IS_OBJECT, index, and NULL.

Referenced by duk_to_defaultvalue().

◆ duk_require_hobject_or_lfunc_coerce()

DUK_INTERNAL duk_hobject * duk_require_hobject_or_lfunc_coerce ( duk_context * ctx,
duk_idx_t index )

Definition at line 1651 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1651 {
1652 duk_hthread *thr = (duk_hthread *) ctx;
1653 duk_tval *tv;
1654
1656
1657 tv = duk_require_tval(ctx, index);
1658 if (DUK_TVAL_IS_OBJECT(tv)) {
1659 return DUK_TVAL_GET_OBJECT(tv);
1660 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
1661 duk_to_object(ctx, index);
1662 return duk_require_hobject(ctx, index);
1663 }
1665 return NULL; /* not reachable */
1666}

References DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_require_hobject(), duk_require_tval(), DUK_STR_NOT_OBJECT, duk_to_object(), DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_LIGHTFUNC, DUK_TVAL_IS_OBJECT, index, and NULL.

◆ duk_require_hobject_with_class()

◆ duk_require_hstring()

DUK_INTERNAL duk_hstring * duk_require_hstring ( duk_context * ctx,
duk_idx_t index )

◆ duk_require_hthread()

◆ duk_require_int()

DUK_EXTERNAL duk_int_t duk_require_int ( duk_context * ctx,
duk_idx_t index )

Definition at line 1179 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1179 {
1180 /* Custom coercion for API */
1182 return (duk_int_t) duk__api_coerce_d2i(ctx, index, 1 /*require*/);
1183}

References duk__api_coerce_d2i(), DUK_ASSERT_CTX_VALID, and index.

◆ duk_require_lstring()

DUK_EXTERNAL const char * duk_require_lstring ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_len )

Definition at line 1219 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1219 {
1220 duk_hthread *thr = (duk_hthread *) ctx;
1221 const char *ret;
1222
1224
1225 /* Note: this check relies on the fact that even a zero-size string
1226 * has a non-NULL pointer.
1227 */
1228 ret = duk_get_lstring(ctx, index, out_len);
1229 if (ret) {
1230 return ret;
1231 }
1233 return NULL; /* not reachable */
1234}

References DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_lstring(), DUK_STR_NOT_STRING, index, and NULL.

Referenced by duk_require_string(), and duk_to_lstring().

◆ duk_require_normalize_index()

DUK_EXTERNAL duk_idx_t duk_require_normalize_index ( duk_context * ctx,
duk_idx_t index )

Definition at line 219 of file duktape-1.5.2/src-separate/duk_api_stack.c.

219 {
220 duk_hthread *thr = (duk_hthread *) ctx;
221 duk_uidx_t vs_size;
222 duk_uidx_t uindex;
223
226
228 vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
229 DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */
230
231 if (index < 0) {
232 uindex = vs_size + (duk_uidx_t) index;
233 } else {
235 uindex = (duk_uidx_t) index;
236 }
237
238 /* DUK_INVALID_INDEX won't be accepted as a valid index. */
239 DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
240
241 if (DUK_LIKELY(uindex < vs_size)) {
242 return (duk_idx_t) uindex;
243 }
245 return 0; /* unreachable */
246}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_ERROR_API_INDEX, DUK_INVALID_INDEX, DUK_LIKELY, index, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk_safe_to_lstring(), duk_to_boolean(), duk_to_buffer_raw(), duk_to_defaultvalue(), duk_to_object(), duk_to_pointer(), duk_to_primitive(), and duk_to_string().

◆ duk_require_null()

DUK_EXTERNAL void duk_require_null ( duk_context * ctx,
duk_idx_t index )

Definition at line 1078 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1078 {
1079 duk_hthread *thr = (duk_hthread *) ctx;
1080 duk_tval *tv;
1081
1083
1084 tv = duk_get_tval(ctx, index);
1085 if (tv && DUK_TVAL_IS_NULL(tv)) {
1086 return;
1087 }
1089 return; /* not reachable */
1090}

References DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_STR_NOT_NULL, DUK_TVAL_IS_NULL, and index.

◆ duk_require_number()

DUK_EXTERNAL duk_double_t duk_require_number ( duk_context * ctx,
duk_idx_t index )

Definition at line 1144 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1144 {
1145 duk_hthread *thr = (duk_hthread *) ctx;
1146 duk_tval *tv;
1147
1149
1150 tv = duk_get_tval(ctx, index);
1151 if (tv && DUK_TVAL_IS_NUMBER(tv)) {
1152 duk_double_union ret;
1153 ret.d = DUK_TVAL_GET_NUMBER(tv);
1154
1155 /*
1156 * Number should already be in NaN-normalized form,
1157 * but let's normalize anyway.
1158 */
1159
1161 return ret.d;
1162 }
1164 return DUK_DOUBLE_NAN; /* not reachable */
1165}

References duk_double_union::d, DUK_ASSERT_CTX_VALID, DUK_DBLUNION_NORMALIZE_NAN_CHECK, DUK_DOUBLE_NAN, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_STR_NOT_NUMBER, DUK_TVAL_GET_NUMBER, DUK_TVAL_IS_NUMBER, and index.

◆ duk_require_pointer()

DUK_EXTERNAL void * duk_require_pointer ( duk_context * ctx,
duk_idx_t index )

Definition at line 1262 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1262 {
1263 duk_hthread *thr = (duk_hthread *) ctx;
1264 duk_tval *tv;
1265
1267
1268 /* Note: here we must be wary of the fact that a pointer may be
1269 * valid and be a NULL.
1270 */
1271 tv = duk_get_tval(ctx, index);
1272 if (tv && DUK_TVAL_IS_POINTER(tv)) {
1273 void *p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */
1274 return (void *) p;
1275 }
1277 return NULL; /* not reachable */
1278}

References DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_STR_NOT_POINTER, DUK_TVAL_GET_POINTER, DUK_TVAL_IS_POINTER, index, and NULL.

◆ duk_require_stack()

DUK_EXTERNAL void duk_require_stack ( duk_context * ctx,
duk_idx_t extra )

Definition at line 739 of file duktape-1.5.2/src-separate/duk_api_stack.c.

739 {
740 duk_hthread *thr = (duk_hthread *) ctx;
741 duk_size_t min_new_size;
742
744 DUK_ASSERT(thr != NULL);
745
746 if (DUK_UNLIKELY(extra < 0)) {
747 /* Clamping to zero makes the API more robust to calling code
748 * calculation errors.
749 */
750 extra = 0;
751 }
752
753 min_new_size = (thr->valstack_top - thr->valstack) + extra + DUK_VALSTACK_INTERNAL_EXTRA;
754 (void) duk_valstack_resize_raw(ctx,
755 min_new_size, /* min_new_size */
756 0 /* no shrink */ | /* flags */
757 0 /* no compact */ |
759}
#define DUK_VSRESIZE_FLAG_THROW

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_UNLIKELY, DUK_VALSTACK_INTERNAL_EXTRA, duk_valstack_resize_raw(), DUK_VSRESIZE_FLAG_THROW, NULL, duk_hthread::valstack, and duk_hthread::valstack_top.

◆ duk_require_stack_top()

DUK_EXTERNAL void duk_require_stack_top ( duk_context * ctx,
duk_idx_t top )

Definition at line 781 of file duktape-1.5.2/src-separate/duk_api_stack.c.

781 {
782 duk_size_t min_new_size;
783
785
786 if (DUK_UNLIKELY(top < 0)) {
787 /* Clamping to zero makes the API more robust to calling code
788 * calculation errors.
789 */
790 top = 0;
791 }
792
793 min_new_size = top + DUK_VALSTACK_INTERNAL_EXTRA;
794 (void) duk_valstack_resize_raw(ctx,
795 min_new_size, /* min_new_size */
796 0 /* no shrink */ | /* flags */
797 0 /* no compact */ |
799}

References DUK_ASSERT_CTX_VALID, DUK_UNLIKELY, DUK_VALSTACK_INTERNAL_EXTRA, duk_valstack_resize_raw(), and DUK_VSRESIZE_FLAG_THROW.

◆ duk_require_string()

DUK_EXTERNAL const char * duk_require_string ( duk_context * ctx,
duk_idx_t index )

Definition at line 1242 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1242 {
1244
1245 return duk_require_lstring(ctx, index, NULL);
1246}
DUK_EXTERNAL const char * duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)

References DUK_ASSERT_CTX_VALID, duk_require_lstring(), index, and NULL.

Referenced by duk_to_string().

◆ duk_require_top_index()

DUK_EXTERNAL duk_idx_t duk_require_top_index ( duk_context * ctx)

Definition at line 451 of file duktape-1.5.2/src-separate/duk_api_stack.c.

451 {
452 duk_hthread *thr = (duk_hthread *) ctx;
453 duk_idx_t ret;
454
456
457 ret = ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
458 if (DUK_UNLIKELY(ret < 0)) {
459 DUK_ERROR_API_INDEX(thr, -1);
460 return 0; /* unreachable */
461 }
462 return ret;
463}

References DUK_ASSERT_CTX_VALID, DUK_ERROR_API_INDEX, DUK_UNLIKELY, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

◆ duk_require_tval()

DUK_INTERNAL duk_tval * duk_require_tval ( duk_context * ctx,
duk_idx_t index )

Definition at line 276 of file duktape-1.5.2/src-separate/duk_api_stack.c.

276 {
277 duk_hthread *thr = (duk_hthread *) ctx;
278 duk_uidx_t vs_size;
279 duk_uidx_t uindex;
280
283
285 vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
286 DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */
287
288 /* Use unsigned arithmetic to optimize comparison. */
289 if (index < 0) {
290 uindex = vs_size + (duk_uidx_t) index;
291 } else {
293 uindex = (duk_uidx_t) index;
294 }
295
296 /* DUK_INVALID_INDEX won't be accepted as a valid index. */
297 DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
298
299 if (DUK_LIKELY(uindex < vs_size)) {
300 return thr->valstack_bottom + uindex;
301 }
303 return NULL;
304}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_ERROR_API_INDEX, DUK_INVALID_INDEX, DUK_LIKELY, index, NULL, duk_hthread::valstack_bottom, and duk_hthread::valstack_top.

Referenced by duk__to_int_uint_helper(), duk_copy(), duk_dup(), duk_get_hobject_or_lfunc_coerce(), duk_insert(), duk_instanceof(), duk_push_array(), duk_remove(), duk_replace(), duk_require_heapptr(), duk_require_hobject_or_lfunc(), duk_require_hobject_or_lfunc_coerce(), duk_swap(), duk_to_boolean(), duk_to_int32(), duk_to_int_clamped_raw(), duk_to_null(), duk_to_number(), duk_to_object(), duk_to_pointer(), duk_to_string(), duk_to_uint16(), duk_to_uint32(), and duk_to_undefined().

◆ duk_require_uint()

DUK_EXTERNAL duk_uint_t duk_require_uint ( duk_context * ctx,
duk_idx_t index )

Definition at line 1185 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1185 {
1186 /* Custom coercion for API */
1188 return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 1 /*require*/);
1189}

References duk__api_coerce_d2ui(), DUK_ASSERT_CTX_VALID, and index.

◆ duk_require_undefined()

DUK_EXTERNAL void duk_require_undefined ( duk_context * ctx,
duk_idx_t index )

Definition at line 1064 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1064 {
1065 duk_hthread *thr = (duk_hthread *) ctx;
1066 duk_tval *tv;
1067
1069
1070 tv = duk_get_tval(ctx, index);
1071 if (tv && DUK_TVAL_IS_UNDEFINED(tv)) {
1072 return;
1073 }
1075 return; /* not reachable */
1076}
#define DUK_STR_NOT_UNDEFINED

References DUK_ASSERT_CTX_VALID, DUK_ERROR_REQUIRE_TYPE_INDEX, duk_get_tval(), DUK_STR_NOT_UNDEFINED, DUK_TVAL_IS_UNDEFINED, and index.

◆ duk_require_valid_index()

DUK_EXTERNAL void duk_require_valid_index ( duk_context * ctx,
duk_idx_t index )

Definition at line 315 of file duktape-1.5.2/src-separate/duk_api_stack.c.

315 {
316 duk_hthread *thr = (duk_hthread *) ctx;
317
320
321 if (duk_normalize_index(ctx, index) < 0) {
323 return; /* unreachable */
324 }
325}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API_INDEX, DUK_INVALID_INDEX, duk_normalize_index(), and index.

◆ duk_safe_to_lstring()

DUK_EXTERNAL const char * duk_safe_to_lstring ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_len )

Definition at line 2056 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2056 {
2058
2060
2061 /* We intentionally ignore the duk_safe_call() return value and only
2062 * check the output type. This way we don't also need to check that
2063 * the returned value is indeed a string in the success case.
2064 */
2065
2066 duk_dup(ctx, index);
2067 (void) duk_safe_call(ctx, duk__safe_to_string_raw, 1 /*nargs*/, 1 /*nrets*/);
2068 if (!duk_is_string(ctx, -1)) {
2069 /* Error: try coercing error to string once. */
2070 (void) duk_safe_call(ctx, duk__safe_to_string_raw, 1 /*nargs*/, 1 /*nrets*/);
2071 if (!duk_is_string(ctx, -1)) {
2072 /* Double error */
2073 duk_pop(ctx);
2075 } else {
2076 ;
2077 }
2078 } else {
2079 ;
2080 }
2081 DUK_ASSERT(duk_is_string(ctx, -1));
2082 DUK_ASSERT(duk_get_string(ctx, -1) != NULL);
2083
2084 duk_replace(ctx, index);
2085 return duk_get_lstring(ctx, index, out_len);
2086}
DUK_EXTERNAL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets)
#define DUK_STRIDX_UC_ERROR
DUK_EXTERNAL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL const char * duk_get_string(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index)
DUK_LOCAL duk_ret_t duk__safe_to_string_raw(duk_context *ctx)

References duk__safe_to_string_raw(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_dup(), duk_get_lstring(), duk_get_string(), duk_is_string(), duk_pop(), duk_push_hstring_stridx(), duk_replace(), duk_require_normalize_index(), duk_safe_call(), DUK_STRIDX_UC_ERROR, index, and NULL.

◆ duk_set_length()

DUK_INTERNAL void duk_set_length ( duk_context * ctx,
duk_idx_t index,
duk_size_t length )

Definition at line 1751 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1751 {
1752 duk_hthread *thr = (duk_hthread *) ctx;
1753 duk_hobject *h;
1754
1756
1757 h = duk_get_hobject(ctx, index);
1758 if (!h) {
1759 return;
1760 }
1761
1762 duk_hobject_set_length(thr, h, (duk_uint32_t) length); /* XXX: typing */
1763}
DUK_INTERNAL_DECL void duk_hobject_set_length(duk_hthread *thr, duk_hobject *obj, duk_uint32_t length)

References DUK_ASSERT_CTX_VALID, duk_get_hobject(), duk_hobject_set_length(), and index.

◆ duk_set_top()

DUK_EXTERNAL void duk_set_top ( duk_context * ctx,
duk_idx_t index )

Definition at line 343 of file duktape-1.5.2/src-separate/duk_api_stack.c.

343 {
344 duk_hthread *thr = (duk_hthread *) ctx;
345 duk_uidx_t vs_size;
346 duk_uidx_t vs_limit;
347 duk_uidx_t uindex;
348 duk_tval *tv;
349
352
355 vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
356 vs_limit = (duk_uidx_t) (thr->valstack_end - thr->valstack_bottom);
357
358 if (index < 0) {
359 /* Negative indices are always within allocated stack but
360 * must not go below zero index.
361 */
362 uindex = vs_size + (duk_uidx_t) index;
363 } else {
364 /* Positive index can be higher than valstack top but must
365 * not go above allocated stack (equality is OK).
366 */
367 uindex = (duk_uidx_t) index;
368 }
369
370 /* DUK_INVALID_INDEX won't be accepted as a valid index. */
371 DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
372 DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_limit);
373
374#if defined(DUK_USE_VALSTACK_UNSAFE)
375 DUK_ASSERT(uindex <= vs_limit);
376 DUK_UNREF(vs_limit);
377#else
378 if (DUK_UNLIKELY(uindex > vs_limit)) {
380 return; /* unreachable */
381 }
382#endif
383 DUK_ASSERT(uindex <= vs_limit);
384
385 /* Handle change in value stack top. Respect value stack
386 * initialization policy: 'undefined' above top. Note that
387 * DECREF may cause a side effect that reallocates valstack,
388 * so must relookup after DECREF.
389 */
390
391 if (uindex >= vs_size) {
392 /* Stack size increases or stays the same. */
393#if defined(DUK_USE_ASSERTIONS)
394 duk_uidx_t count;
395
396 count = uindex - vs_size;
397 while (count != 0) {
398 count--;
399 tv = thr->valstack_top + count;
401 }
402#endif
403 thr->valstack_top = thr->valstack_bottom + uindex;
404 } else {
405 /* Stack size decreases. */
406#if defined(DUK_USE_REFERENCE_COUNTING)
407 duk_uidx_t count;
408
409 count = vs_size - uindex;
410 DUK_ASSERT(count > 0);
411 while (count > 0) {
412 count--;
413 tv = --thr->valstack_top; /* tv -> value just before prev top value; must relookup */
414 DUK_ASSERT(tv >= thr->valstack_bottom);
415 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
416 }
417#else /* DUK_USE_REFERENCE_COUNTING */
418 duk_uidx_t count;
419 duk_tval *tv_end;
420
421 count = vs_size - uindex;
422 tv = thr->valstack_top;
423 tv_end = tv - count;
424 DUK_ASSERT(tv > tv_end);
425 do {
426 tv--;
428 } while (tv != tv_end);
429 thr->valstack_top = tv_end;
430#endif /* DUK_USE_REFERENCE_COUNTING */
431 }
432}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API_INDEX, DUK_INVALID_INDEX, DUK_TVAL_IS_UNDEFINED, DUK_TVAL_SET_UNDEFINED, DUK_TVAL_SET_UNDEFINED_UPDREF, DUK_UNLIKELY, DUK_UNREF, index, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

◆ duk_strict_equals()

DUK_EXTERNAL duk_bool_t duk_strict_equals ( duk_context * ctx,
duk_idx_t index1,
duk_idx_t index2 )

Definition at line 4427 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4427 {
4428 duk_tval *tv1, *tv2;
4429
4431
4432 tv1 = duk_get_tval(ctx, index1);
4433 tv2 = duk_get_tval(ctx, index2);
4434 if ((tv1 == NULL) || (tv2 == NULL)) {
4435 return 0;
4436 }
4437
4438 /* No coercions or other side effects, so safe */
4439 return duk_js_strict_equals(tv1, tv2);
4440}
#define duk_js_strict_equals(tv_x, tv_y)

References DUK_ASSERT_CTX_VALID, duk_get_tval(), duk_js_strict_equals, and NULL.

◆ duk_swap()

DUK_EXTERNAL void duk_swap ( duk_context * ctx,
duk_idx_t index1,
duk_idx_t index2 )

Definition at line 805 of file duktape-1.5.2/src-separate/duk_api_stack.c.

805 {
806 duk_tval *tv1;
807 duk_tval *tv2;
808 duk_tval tv_tmp;
809
811
812 tv1 = duk_require_tval(ctx, index1);
813 DUK_ASSERT(tv1 != NULL);
814 tv2 = duk_require_tval(ctx, index2);
815 DUK_ASSERT(tv2 != NULL);
816
817 /* If tv1==tv2 this is a NOP, no check is needed */
818 DUK_TVAL_SET_TVAL(&tv_tmp, tv1);
819 DUK_TVAL_SET_TVAL(tv1, tv2);
820 DUK_TVAL_SET_TVAL(tv2, &tv_tmp);
821}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_SET_TVAL, and NULL.

Referenced by duk_swap_top().

◆ duk_swap_top()

DUK_EXTERNAL void duk_swap_top ( duk_context * ctx,
duk_idx_t index )

Definition at line 823 of file duktape-1.5.2/src-separate/duk_api_stack.c.

823 {
825
826 duk_swap(ctx, index, -1);
827}
DUK_EXTERNAL void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2)

References DUK_ASSERT_CTX_VALID, duk_swap(), and index.

◆ duk_throw()

DUK_EXTERNAL void duk_throw ( duk_context * ctx)

Definition at line 4308 of file duktape-1.5.2/src-separate/duk_api_stack.c.

4308 {
4309 duk_hthread *thr = (duk_hthread *) ctx;
4310
4311 DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
4313 DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
4314
4315 if (thr->valstack_top == thr->valstack_bottom) {
4317 }
4318
4319 /* Errors are augmented when they are created, not when they are
4320 * thrown or re-thrown. The current error handler, however, runs
4321 * just before an error is thrown.
4322 */
4323
4324 /* Sync so that augmentation sees up-to-date activations, NULL
4325 * thr->ptr_curr_pc so that it's not used if side effects occur
4326 * in augmentation or longjmp handling.
4327 */
4329
4330#if defined(DUK_USE_AUGMENT_ERROR_THROW)
4331 DUK_DDD(DUK_DDDPRINT("THROW ERROR (API): %!dT (before throw augment)", (duk_tval *) duk_get_tval(ctx, -1)));
4333#endif
4334 DUK_DDD(DUK_DDDPRINT("THROW ERROR (API): %!dT (after throw augment)", (duk_tval *) duk_get_tval(ctx, -1)));
4335
4337
4338 /* thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
4339 * need to check that here. If the value is NULL, a panic occurs because
4340 * we can't return.
4341 */
4342
4343 duk_err_longjmp(thr);
4345}
DUK_INTERNAL_DECL void duk_err_setup_heap_ljstate(duk_hthread *thr, duk_small_int_t lj_type)
DUK_INTERNAL void duk_err_longjmp(duk_hthread *thr)
DUK_INTERNAL_DECL void duk_hthread_sync_and_null_currpc(duk_hthread *thr)
DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr)

References DUK_ASSERT, DUK_DDD, DUK_DDDPRINT, duk_err_augment_error_throw(), duk_err_longjmp(), duk_err_setup_heap_ljstate(), DUK_ERROR_API, duk_get_tval(), duk_hthread_sync_and_null_currpc(), DUK_LJ_TYPE_THROW, DUK_STR_INVALID_CALL_ARGS, DUK_UNREACHABLE, duk_hthread::valstack, duk_hthread::valstack_bottom, duk_hthread::valstack_end, and duk_hthread::valstack_top.

Referenced by duk_error_raw(), duk_error_stash(), and duk_error_va_raw().

◆ duk_to_boolean()

DUK_EXTERNAL duk_bool_t duk_to_boolean ( duk_context * ctx,
duk_idx_t index )

Definition at line 1871 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1871 {
1872 duk_hthread *thr = (duk_hthread *) ctx;
1873 duk_tval *tv;
1874 duk_bool_t val;
1875
1877 DUK_UNREF(thr);
1878
1880
1881 tv = duk_require_tval(ctx, index);
1882 DUK_ASSERT(tv != NULL);
1883
1884 val = duk_js_toboolean(tv);
1885 DUK_ASSERT(val == 0 || val == 1);
1886
1887 /* Note: no need to re-lookup tv, conversion is side effect free */
1888 DUK_ASSERT(tv != NULL);
1889 DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */
1890 return val;
1891}
#define DUK_TVAL_SET_BOOLEAN_UPDREF
DUK_INTERNAL_DECL duk_bool_t duk_js_toboolean(duk_tval *tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_js_toboolean(), duk_require_normalize_index(), duk_require_tval(), DUK_TVAL_SET_BOOLEAN_UPDREF, DUK_UNREF, index, and NULL.

◆ duk_to_buffer_raw()

DUK_EXTERNAL void * duk_to_buffer_raw ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_size,
duk_uint_t mode )

Definition at line 2313 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2313 {
2314 duk_hthread *thr = (duk_hthread *) ctx;
2315 duk_hbuffer *h_buf;
2316 const duk_uint8_t *src_data;
2317 duk_size_t src_size;
2318 duk_uint8_t *dst_data;
2319
2321 DUK_UNREF(thr);
2322
2324
2325 h_buf = duk_get_hbuffer(ctx, index);
2326 if (h_buf != NULL) {
2327 /* Buffer is kept as is, with the fixed/dynamic nature of the
2328 * buffer only changed if requested. An external buffer
2329 * is converted into a non-external dynamic buffer in a
2330 * duk_to_dynamic_buffer() call.
2331 */
2332 duk_uint_t tmp;
2333 duk_uint8_t *tmp_ptr;
2334
2335 tmp_ptr = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf);
2336 src_data = (const duk_uint8_t *) tmp_ptr;
2337 src_size = DUK_HBUFFER_GET_SIZE(h_buf);
2338
2340 if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) ||
2341 mode == DUK_BUF_MODE_DONTCARE) {
2342 /* Note: src_data may be NULL if input is a zero-size
2343 * dynamic buffer.
2344 */
2345 dst_data = tmp_ptr;
2346 goto skip_copy;
2347 }
2348 } else {
2349 /* Non-buffer value is first ToString() coerced, then converted
2350 * to a buffer (fixed buffer is used unless a dynamic buffer is
2351 * explicitly requested).
2352 */
2353
2354 src_data = (const duk_uint8_t *) duk_to_lstring(ctx, index, &src_size);
2355 }
2356
2357 dst_data = (duk_uint8_t *) duk_push_buffer(ctx, src_size, (mode == DUK_BUF_MODE_DYNAMIC) /*dynamic*/);
2358 if (DUK_LIKELY(src_size > 0)) {
2359 /* When src_size == 0, src_data may be NULL (if source
2360 * buffer is dynamic), and dst_data may be NULL (if
2361 * target buffer is dynamic). Avoid zero-size memcpy()
2362 * with an invalid pointer.
2363 */
2364 DUK_MEMCPY((void *) dst_data, (const void *) src_data, (size_t) src_size);
2365 }
2366 duk_replace(ctx, index);
2367 skip_copy:
2368
2369 if (out_size) {
2370 *out_size = src_size;
2371 }
2372 return dst_data;
2373}
#define DUK_BUF_MODE_DONTCARE
#define DUK_BUF_MODE_DYNAMIC
#define duk_push_buffer(ctx, size, dynamic)
DUK_EXTERNAL const char * duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
DUK_INTERNAL duk_hbuffer * duk_get_hbuffer(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, DUK_BUF_MODE_DONTCARE, DUK_BUF_MODE_DYNAMIC, DUK_BUF_MODE_FIXED, duk_get_hbuffer(), DUK_HBUFFER_GET_DATA_PTR, DUK_HBUFFER_GET_SIZE, DUK_HBUFFER_HAS_DYNAMIC, DUK_HBUFFER_HAS_EXTERNAL, DUK_LIKELY, DUK_MEMCPY, duk_push_buffer, duk_replace(), duk_require_normalize_index(), duk_to_lstring(), DUK_UNREF, duk_hthread::heap, index, and NULL.

◆ duk_to_defaultvalue()

DUK_EXTERNAL void duk_to_defaultvalue ( duk_context * ctx,
duk_idx_t index,
duk_int_t hint )

Definition at line 1792 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1792 {
1793 duk_hthread *thr = (duk_hthread *) ctx;
1794 duk_hobject *obj;
1795 /* inline initializer for coercers[] is not allowed by old compilers like BCC */
1796 duk_small_int_t coercers[2];
1797
1799 DUK_ASSERT(thr != NULL);
1800
1801 coercers[0] = DUK_STRIDX_VALUE_OF;
1802 coercers[1] = DUK_STRIDX_TO_STRING;
1803
1806
1807 if (hint == DUK_HINT_NONE) {
1809 hint = DUK_HINT_STRING;
1810 } else {
1811 hint = DUK_HINT_NUMBER;
1812 }
1813 }
1814
1815 if (hint == DUK_HINT_STRING) {
1816 coercers[0] = DUK_STRIDX_TO_STRING;
1817 coercers[1] = DUK_STRIDX_VALUE_OF;
1818 }
1819
1820 if (duk__defaultvalue_coerce_attempt(ctx, index, coercers[0])) {
1821 return;
1822 }
1823
1824 if (duk__defaultvalue_coerce_attempt(ctx, index, coercers[1])) {
1825 return;
1826 }
1827
1829}
#define DUK_STR_DEFAULTVALUE_COERCE_FAILED
#define DUK_HOBJECT_CLASS_DATE
#define DUK_STRIDX_VALUE_OF
DUK_INTERNAL duk_hobject * duk_require_hobject_or_lfunc(duk_context *ctx, duk_idx_t index)
DUK_LOCAL duk_bool_t duk__defaultvalue_coerce_attempt(duk_context *ctx, duk_idx_t index, duk_small_int_t func_stridx)

References duk__defaultvalue_coerce_attempt(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_TYPE, DUK_HINT_NONE, DUK_HINT_NUMBER, DUK_HINT_STRING, DUK_HOBJECT_CLASS_DATE, DUK_HOBJECT_GET_CLASS_NUMBER, duk_require_hobject_or_lfunc(), duk_require_normalize_index(), DUK_STR_DEFAULTVALUE_COERCE_FAILED, DUK_STRIDX_TO_STRING, DUK_STRIDX_VALUE_OF, index, and NULL.

Referenced by duk_to_primitive().

◆ duk_to_hstring()

DUK_INTERNAL duk_hstring * duk_to_hstring ( duk_context * ctx,
duk_idx_t index )

Definition at line 2304 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2304 {
2305 duk_hstring *ret;
2307 duk_to_string(ctx, index);
2308 ret = duk_get_hstring(ctx, index);
2309 DUK_ASSERT(ret != NULL);
2310 return ret;
2311}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_hstring(), duk_to_string(), index, and NULL.

◆ duk_to_int()

DUK_EXTERNAL duk_int_t duk_to_int ( duk_context * ctx,
duk_idx_t index )

Definition at line 1936 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1936 {
1937 /* Value coercion (in stack): ToInteger(), E5 Section 9.4
1938 * API return value coercion: custom
1939 */
1942 return (duk_int_t) duk__api_coerce_d2i(ctx, index, 0 /*require*/);
1943}
DUK_INTERNAL_DECL duk_double_t duk_js_tointeger(duk_hthread *thr, duk_tval *tv)
DUK_LOCAL duk_double_t duk__to_int_uint_helper(duk_context *ctx, duk_idx_t index, duk__toint_coercer coerce_func)

References duk__api_coerce_d2i(), duk__to_int_uint_helper(), DUK_ASSERT_CTX_VALID, duk_js_tointeger(), and index.

◆ duk_to_int32()

DUK_EXTERNAL duk_int32_t duk_to_int32 ( duk_context * ctx,
duk_idx_t index )

Definition at line 1954 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1954 {
1955 duk_hthread *thr = (duk_hthread *) ctx;
1956 duk_tval *tv;
1957 duk_int32_t ret;
1958
1960
1961 tv = duk_require_tval(ctx, index);
1962 DUK_ASSERT(tv != NULL);
1963 ret = duk_js_toint32(thr, tv);
1964
1965 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
1966 tv = duk_require_tval(ctx, index);
1967 DUK_TVAL_SET_FASTINT_I32_UPDREF(thr, tv, ret); /* side effects */
1968 return ret;
1969}
DUK_INTERNAL_DECL duk_int32_t duk_js_toint32(duk_hthread *thr, duk_tval *tv)
#define DUK_TVAL_SET_FASTINT_I32_UPDREF

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_js_toint32(), duk_require_tval(), DUK_TVAL_SET_FASTINT_I32_UPDREF, index, and NULL.

◆ duk_to_int_check_range()

DUK_INTERNAL duk_int_t duk_to_int_check_range ( duk_context * ctx,
duk_idx_t index,
duk_int_t minval,
duk_int_t maxval )

Definition at line 2212 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2212 {
2213 return duk_to_int_clamped_raw(ctx, index, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */
2214}
DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped)

References duk_to_int_clamped_raw(), index, and NULL.

◆ duk_to_int_clamped()

DUK_INTERNAL duk_int_t duk_to_int_clamped ( duk_context * ctx,
duk_idx_t index,
duk_idx_t minval,
duk_idx_t maxval )

Definition at line 2207 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2207 {
2209 return duk_to_int_clamped_raw(ctx, index, minval, maxval, &dummy);
2210}

References duk_to_int_clamped_raw(), dummy, and index.

◆ duk_to_int_clamped_raw()

DUK_INTERNAL duk_int_t duk_to_int_clamped_raw ( duk_context * ctx,
duk_idx_t index,
duk_int_t minval,
duk_int_t maxval,
duk_bool_t * out_clamped )

Definition at line 2144 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2144 {
2145 duk_hthread *thr = (duk_hthread *) ctx;
2146 duk_tval *tv;
2147 duk_tval tv_tmp;
2148 duk_double_t d, dmin, dmax;
2149 duk_int_t res;
2150 duk_bool_t clamped = 0;
2151
2153
2154 tv = duk_require_tval(ctx, index);
2155 DUK_ASSERT(tv != NULL);
2156 d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */
2157
2158 dmin = (duk_double_t) minval;
2159 dmax = (duk_double_t) maxval;
2160
2161 if (d < dmin) {
2162 clamped = 1;
2163 res = minval;
2164 d = dmin;
2165 } else if (d > dmax) {
2166 clamped = 1;
2167 res = maxval;
2168 d = dmax;
2169 } else {
2170 res = (duk_int_t) d;
2171 }
2172 DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */
2173 /* 'd' and 'res' agree here */
2174
2175 /* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */
2176 tv = duk_get_tval(ctx, index);
2177 DUK_ASSERT(tv != NULL); /* not popped by side effect */
2178 DUK_TVAL_SET_TVAL(&tv_tmp, tv);
2179#if defined(DUK_USE_FASTINT)
2180#if (DUK_INT_MAX <= 0x7fffffffL)
2181 DUK_TVAL_SET_FASTINT_I32(tv, res);
2182#else
2183 /* Clamping needed if duk_int_t is 64 bits. */
2184 if (res >= DUK_FASTINT_MIN && res <= DUK_FASTINT_MAX) {
2185 DUK_TVAL_SET_FASTINT(tv, res);
2186 } else {
2187 DUK_TVAL_SET_NUMBER(tv, d);
2188 }
2189#endif
2190#else
2191 DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */
2192#endif
2193 DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */
2194
2195 if (out_clamped) {
2196 *out_clamped = clamped;
2197 } else {
2198 /* coerced value is updated to value stack even when RangeError thrown */
2199 if (clamped) {
2201 }
2202 }
2203
2204 return res;
2205}
#define DUK_STR_NUMBER_OUTSIDE_RANGE

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_RANGE, duk_get_tval(), duk_js_tointeger(), duk_require_tval(), DUK_STR_NUMBER_OUTSIDE_RANGE, DUK_TVAL_DECREF, DUK_TVAL_SET_FASTINT, DUK_TVAL_SET_FASTINT_I32, DUK_TVAL_SET_NUMBER, DUK_TVAL_SET_TVAL, DUK_UNREF, index, and NULL.

Referenced by duk_to_int_check_range(), and duk_to_int_clamped().

◆ duk_to_lstring()

DUK_EXTERNAL const char * duk_to_lstring ( duk_context * ctx,
duk_idx_t index,
duk_size_t * out_len )

Definition at line 2042 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2042 {
2044
2045 (void) duk_to_string(ctx, index);
2046 return duk_require_lstring(ctx, index, out_len);
2047}

References DUK_ASSERT_CTX_VALID, duk_require_lstring(), duk_to_string(), and index.

Referenced by duk_to_buffer_raw().

◆ duk_to_null()

DUK_EXTERNAL void duk_to_null ( duk_context * ctx,
duk_idx_t index )

Definition at line 1843 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1843 {
1844 duk_hthread *thr = (duk_hthread *) ctx;
1845 duk_tval *tv;
1846
1848 DUK_UNREF(thr);
1849
1850 tv = duk_require_tval(ctx, index);
1851 DUK_ASSERT(tv != NULL);
1852 DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */
1853}
#define DUK_TVAL_SET_NULL_UPDREF

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_SET_NULL_UPDREF, DUK_UNREF, index, and NULL.

◆ duk_to_number()

DUK_EXTERNAL duk_double_t duk_to_number ( duk_context * ctx,
duk_idx_t index )

Definition at line 1893 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1893 {
1894 duk_hthread *thr = (duk_hthread *) ctx;
1895 duk_tval *tv;
1896 duk_double_t d;
1897
1899
1900 tv = duk_require_tval(ctx, index);
1901 DUK_ASSERT(tv != NULL);
1902 /* XXX: fastint? */
1903 d = duk_js_tonumber(thr, tv);
1904
1905 /* Note: need to re-lookup because ToNumber() may have side effects */
1906 tv = duk_require_tval(ctx, index);
1907 DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */
1908 return d;
1909}
DUK_INTERNAL_DECL duk_double_t duk_js_tonumber(duk_hthread *thr, duk_tval *tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_js_tonumber(), duk_require_tval(), DUK_TVAL_SET_NUMBER_UPDREF, index, and NULL.

Referenced by duk_to_uint8clamped().

◆ duk_to_object()

DUK_EXTERNAL void duk_to_object ( duk_context * ctx,
duk_idx_t index )

Definition at line 2426 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2426 {
2427 duk_hthread *thr = (duk_hthread *) ctx;
2428 duk_tval *tv;
2429 duk_uint_t flags = 0; /* shared flags for a subset of types */
2431
2433
2435
2436 tv = duk_require_tval(ctx, index);
2437 DUK_ASSERT(tv != NULL);
2438
2439 switch (DUK_TVAL_GET_TAG(tv)) {
2440 case DUK_TAG_UNDEFINED:
2441 case DUK_TAG_NULL: {
2443 break;
2444 }
2445 case DUK_TAG_BOOLEAN: {
2449 goto create_object;
2450 }
2451 case DUK_TAG_STRING: {
2456 goto create_object;
2457 }
2458 case DUK_TAG_OBJECT: {
2459 /* nop */
2460 break;
2461 }
2462 case DUK_TAG_BUFFER: {
2463 /* A plain buffer coerces to a Duktape.Buffer because it's the
2464 * object counterpart of the plain buffer value. But it might
2465 * still make more sense to produce an ArrayBuffer here?
2466 */
2467
2468 duk_hbufferobject *h_bufobj;
2469 duk_hbuffer *h_val;
2470
2471 h_val = DUK_TVAL_GET_BUFFER(tv);
2472 DUK_ASSERT(h_val != NULL);
2473
2474 h_bufobj = duk_push_bufferobject_raw(ctx,
2479 DUK_ASSERT(h_bufobj != NULL);
2482
2483 h_bufobj->buf = h_val;
2484 DUK_HBUFFER_INCREF(thr, h_val);
2485 DUK_ASSERT(h_bufobj->offset == 0);
2486 h_bufobj->length = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_val);
2487 DUK_ASSERT(h_bufobj->shift == 0);
2489
2491 goto replace_value;
2492 }
2493 case DUK_TAG_POINTER: {
2497 goto create_object;
2498 }
2499 case DUK_TAG_LIGHTFUNC: {
2500 /* Lightfunc coerces to a Function instance with concrete
2501 * properties. Since 'length' is virtual for Duktape/C
2502 * functions, don't need to define that.
2503 *
2504 * The result is made extensible to mimic what happens to
2505 * strings:
2506 * > Object.isExtensible(Object('foo'))
2507 * true
2508 */
2509 duk_small_uint_t lf_flags;
2510 duk_idx_t nargs;
2511 duk_small_uint_t lf_len;
2512 duk_c_function func;
2514
2515 DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags);
2516
2517 nargs = (duk_idx_t) DUK_LFUNC_FLAGS_GET_NARGS(lf_flags);
2518 if (nargs == DUK_LFUNC_NARGS_VARARGS) {
2519 nargs = (duk_idx_t) DUK_VARARGS;
2520 }
2527 /* DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally */
2529 (void) duk__push_c_function_raw(ctx, func, nargs, flags);
2530
2531 lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
2532 if ((duk_idx_t) lf_len != nargs) {
2533 /* Explicit length is only needed if it differs from 'nargs'. */
2534 duk_push_int(ctx, (duk_int_t) lf_len);
2536 }
2537 duk_push_lightfunc_name(ctx, tv);
2539
2540 nf = duk_get_hnativefunction(ctx, -1);
2541 DUK_ASSERT(nf != NULL);
2542 nf->magic = (duk_int16_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
2543
2544 /* Enable DUKFUNC exotic behavior once properties are set up. */
2546 goto replace_value;
2547 }
2548#if defined(DUK_USE_FASTINT)
2549 case DUK_TAG_FASTINT:
2550#endif
2551 default: {
2557 goto create_object;
2558 }
2559 }
2560 return;
2561
2562 create_object:
2563 (void) duk_push_object_helper(ctx, flags, proto);
2564
2565 /* Note: Boolean prototype's internal value property is not writable,
2566 * but duk_xdef_prop_stridx() disregards the write protection. Boolean
2567 * instances are immutable.
2568 *
2569 * String and buffer special behaviors are already enabled which is not
2570 * ideal, but a write to the internal value is not affected by them.
2571 */
2572 duk_dup(ctx, index);
2574
2575 replace_value:
2576 duk_replace(ctx, index);
2577}
#define DUK_HOBJECT_CLASS_BOOLEAN
#define DUK_HOBJECT_CLASS_BUFFER
#define DUK_HOBJECT_CLASS_POINTER
#define DUK_BIDX_POINTER_PROTOTYPE
#define DUK_BIDX_STRING_PROTOTYPE
#define DUK_HOBJECT_CLASS_NUMBER
#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ
#define DUK_BIDX_NUMBER_PROTOTYPE
#define DUK_BIDX_BOOLEAN_PROTOTYPE
#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags)
#define DUK_BIDX_BUFFER_PROTOTYPE
#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags)
#define DUK_HOBJECT_SET_EXOTIC_DUKFUNC(h)
#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags)
#define DUK_HOBJECT_HAS_EXTENSIBLE(h)
#define DUK_HOBJECT_CLASS_STRING
DUK_INTERNAL duk_hnativefunction * duk_get_hnativefunction(duk_context *ctx, duk_idx_t index)

References duk_hbufferobject::buf, duk__push_c_function_raw(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_HBUFFEROBJECT_VALID, DUK_BIDX_BOOLEAN_PROTOTYPE, DUK_BIDX_BUFFER_PROTOTYPE, DUK_BIDX_NUMBER_PROTOTYPE, DUK_BIDX_POINTER_PROTOTYPE, DUK_BIDX_STRING_PROTOTYPE, duk_dup(), DUK_ERROR_TYPE, duk_get_hnativefunction(), DUK_HBUFFER_GET_SIZE, DUK_HBUFFER_INCREF, DUK_HBUFFEROBJECT_ELEM_UINT8, DUK_HOBJECT_CLASS_AS_FLAGS, DUK_HOBJECT_CLASS_BOOLEAN, DUK_HOBJECT_CLASS_BUFFER, DUK_HOBJECT_CLASS_FUNCTION, DUK_HOBJECT_CLASS_NUMBER, DUK_HOBJECT_CLASS_POINTER, DUK_HOBJECT_CLASS_STRING, DUK_HOBJECT_FLAG_BUFFEROBJECT, DUK_HOBJECT_FLAG_CONSTRUCTABLE, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_NATIVEFUNCTION, DUK_HOBJECT_FLAG_NEWENV, DUK_HOBJECT_FLAG_NOTAIL, DUK_HOBJECT_FLAG_STRICT, DUK_HOBJECT_HAS_EXTENSIBLE, DUK_HOBJECT_IS_BUFFEROBJECT, DUK_HOBJECT_SET_EXOTIC_DUKFUNC, DUK_LFUNC_FLAGS_GET_LENGTH, DUK_LFUNC_FLAGS_GET_MAGIC, DUK_LFUNC_FLAGS_GET_NARGS, DUK_LFUNC_NARGS_VARARGS, DUK_PROPDESC_FLAGS_NONE, duk_push_bufferobject_raw(), duk_push_int(), duk_push_lightfunc_name(), duk_push_object_helper(), duk_replace(), duk_require_normalize_index(), duk_require_tval(), DUK_STR_NOT_OBJECT_COERCIBLE, DUK_STRIDX_INT_VALUE, DUK_STRIDX_LENGTH, DUK_STRIDX_NAME, DUK_TAG_BOOLEAN, DUK_TAG_BUFFER, DUK_TAG_LIGHTFUNC, DUK_TAG_NULL, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, DUK_TAG_UNDEFINED, DUK_TVAL_GET_BUFFER, DUK_TVAL_GET_LIGHTFUNC, DUK_TVAL_GET_TAG, DUK_TVAL_IS_NUMBER, DUK_TVAL_IS_UNUSED, DUK_VARARGS, duk_xdef_prop_stridx(), duk_hbufferobject::elem_type, index, duk_hbufferobject::length, duk_hnativefunction::magic, NULL, duk_hbufferobject::offset, proto, and duk_hbufferobject::shift.

Referenced by duk_get_hobject_or_lfunc_coerce(), duk_push_this_coercible_to_object(), duk_require_hobject_or_lfunc_coerce(), and duk_to_object_class_string_top().

◆ duk_to_object_class_string_top()

DUK_INTERNAL void duk_to_object_class_string_top ( duk_context * ctx)

Definition at line 2098 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2098 {
2099 duk_hthread *thr;
2100 duk_uint_t typemask;
2101 duk_hstring *h_strclass;
2102
2104 thr = (duk_hthread *) ctx;
2105 DUK_UNREF(thr);
2106
2107 typemask = duk_get_type_mask(ctx, -1);
2108 if (typemask & DUK_TYPE_MASK_UNDEFINED) {
2109 h_strclass = DUK_HTHREAD_STRING_UC_UNDEFINED(thr);
2110 } else if (typemask & DUK_TYPE_MASK_NULL) {
2111 h_strclass = DUK_HTHREAD_STRING_UC_NULL(thr);
2112 } else {
2113 duk_hobject *h_obj;
2114
2115 duk_to_object(ctx, -1);
2116 h_obj = duk_get_hobject(ctx, -1);
2117 DUK_ASSERT(h_obj != NULL);
2118
2119 h_strclass = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h_obj);
2120 }
2121 DUK_ASSERT(h_strclass != NULL);
2122
2123 duk_pop(ctx);
2124 duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
2125}
#define DUK_HTHREAD_STRING_UC_UNDEFINED(thr)
#define DUK_HTHREAD_STRING_UC_NULL(thr)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_hobject(), duk_get_type_mask(), DUK_HOBJECT_GET_CLASS_STRING, DUK_HSTRING_GET_DATA, DUK_HTHREAD_STRING_UC_NULL, DUK_HTHREAD_STRING_UC_UNDEFINED, duk_pop(), duk_push_sprintf(), duk_to_object(), DUK_TYPE_MASK_NULL, DUK_TYPE_MASK_UNDEFINED, DUK_UNREF, duk_hthread::heap, and NULL.

◆ duk_to_pointer()

DUK_EXTERNAL void * duk_to_pointer ( duk_context * ctx,
duk_idx_t index )

Definition at line 2375 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2375 {
2376 duk_tval *tv;
2377 void *res;
2378
2380
2382
2383 tv = duk_require_tval(ctx, index);
2384 DUK_ASSERT(tv != NULL);
2385
2386 switch (DUK_TVAL_GET_TAG(tv)) {
2387 case DUK_TAG_UNDEFINED:
2388 case DUK_TAG_NULL:
2389 case DUK_TAG_BOOLEAN:
2390 res = NULL;
2391 break;
2392 case DUK_TAG_POINTER:
2393 res = DUK_TVAL_GET_POINTER(tv);
2394 break;
2395 case DUK_TAG_STRING:
2396 case DUK_TAG_OBJECT:
2397 case DUK_TAG_BUFFER:
2398 /* Heap allocated: return heap pointer which is NOT useful
2399 * for the caller, except for debugging.
2400 */
2401 res = (void *) DUK_TVAL_GET_HEAPHDR(tv);
2402 break;
2403 case DUK_TAG_LIGHTFUNC:
2404 /* Function pointers do not always cast correctly to void *
2405 * (depends on memory and segmentation model for instance),
2406 * so they coerce to NULL.
2407 */
2408 res = NULL;
2409 break;
2410#if defined(DUK_USE_FASTINT)
2411 case DUK_TAG_FASTINT:
2412#endif
2413 default:
2414 /* number */
2417 res = NULL;
2418 break;
2419 }
2420
2421 duk_push_pointer(ctx, res);
2422 duk_replace(ctx, index);
2423 return res;
2424}
DUK_EXTERNAL void duk_push_pointer(duk_context *ctx, void *val)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_push_pointer(), duk_replace(), duk_require_normalize_index(), duk_require_tval(), DUK_TAG_BOOLEAN, DUK_TAG_BUFFER, DUK_TAG_LIGHTFUNC, DUK_TAG_NULL, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, DUK_TAG_UNDEFINED, DUK_TVAL_GET_HEAPHDR, DUK_TVAL_GET_POINTER, DUK_TVAL_GET_TAG, DUK_TVAL_IS_NUMBER, DUK_TVAL_IS_UNUSED, index, and NULL.

◆ duk_to_primitive()

DUK_EXTERNAL void duk_to_primitive ( duk_context * ctx,
duk_idx_t index,
duk_int_t hint )

Definition at line 1856 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1856 {
1858 DUK_ASSERT(hint == DUK_HINT_NONE || hint == DUK_HINT_NUMBER || hint == DUK_HINT_STRING);
1859
1861
1864 /* everything except object stay as is */
1865 return;
1866 }
1867 duk_to_defaultvalue(ctx, index, hint);
1868}
DUK_EXTERNAL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask)
DUK_EXTERNAL void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_check_type_mask(), DUK_HINT_NONE, DUK_HINT_NUMBER, DUK_HINT_STRING, duk_require_normalize_index(), duk_to_defaultvalue(), DUK_TYPE_MASK_LIGHTFUNC, DUK_TYPE_MASK_OBJECT, and index.

Referenced by duk_to_string().

◆ duk_to_string()

DUK_EXTERNAL const char * duk_to_string ( duk_context * ctx,
duk_idx_t index )

Definition at line 2216 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2216 {
2217 duk_hthread *thr = (duk_hthread *) ctx;
2218 duk_tval *tv;
2219
2221 DUK_UNREF(thr);
2222
2224
2225 tv = duk_require_tval(ctx, index);
2226 DUK_ASSERT(tv != NULL);
2227
2228 switch (DUK_TVAL_GET_TAG(tv)) {
2229 case DUK_TAG_UNDEFINED: {
2231 break;
2232 }
2233 case DUK_TAG_NULL: {
2235 break;
2236 }
2237 case DUK_TAG_BOOLEAN: {
2238 if (DUK_TVAL_GET_BOOLEAN(tv)) {
2240 } else {
2242 }
2243 break;
2244 }
2245 case DUK_TAG_STRING: {
2246 /* nop */
2247 goto skip_replace;
2248 }
2249 case DUK_TAG_OBJECT: {
2251 return duk_to_string(ctx, index); /* Note: recursive call */
2252 }
2253 case DUK_TAG_BUFFER: {
2255
2256 /* Note: this allows creation of internal strings. */
2257
2258 DUK_ASSERT(h != NULL);
2259 duk_push_lstring(ctx,
2260 (const char *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h),
2262 break;
2263 }
2264 case DUK_TAG_POINTER: {
2265 void *ptr = DUK_TVAL_GET_POINTER(tv);
2266 if (ptr != NULL) {
2267 duk_push_sprintf(ctx, DUK_STR_FMT_PTR, (void *) ptr);
2268 } else {
2269 /* Represent a null pointer as 'null' to be consistent with
2270 * the JX format variant. Native '%p' format for a NULL
2271 * pointer may be e.g. '(nil)'.
2272 */
2274 }
2275 break;
2276 }
2277 case DUK_TAG_LIGHTFUNC: {
2278 /* Should match Function.prototype.toString() */
2280 break;
2281 }
2282#if defined(DUK_USE_FASTINT)
2283 case DUK_TAG_FASTINT:
2284#endif
2285 default: {
2286 /* number */
2289 duk_push_tval(ctx, tv);
2291 10 /*radix*/,
2292 0 /*precision:shortest*/,
2293 0 /*force_exponential*/);
2294 break;
2295 }
2296 }
2297
2298 duk_replace(ctx, index);
2299
2300 skip_replace:
2301 return duk_require_string(ctx, index);
2302}
DUK_INTERNAL_DECL void duk_numconv_stringify(duk_context *ctx, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags)
#define DUK_STRIDX_LC_UNDEFINED
DUK_EXTERNAL void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint)
DUK_INTERNAL void duk_push_lightfunc_tostring(duk_context *ctx, duk_tval *tv)
DUK_EXTERNAL const char * duk_require_string(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_HBUFFER_GET_DATA_PTR, DUK_HBUFFER_GET_SIZE, DUK_HINT_STRING, duk_numconv_stringify(), duk_push_hstring_stridx(), duk_push_lightfunc_tostring(), duk_push_lstring(), duk_push_sprintf(), duk_push_tval(), duk_replace(), duk_require_normalize_index(), duk_require_string(), duk_require_tval(), DUK_STR_FMT_PTR, DUK_STRIDX_FALSE, DUK_STRIDX_LC_NULL, DUK_STRIDX_LC_UNDEFINED, DUK_STRIDX_TRUE, DUK_TAG_BOOLEAN, DUK_TAG_BUFFER, DUK_TAG_LIGHTFUNC, DUK_TAG_NULL, DUK_TAG_OBJECT, DUK_TAG_POINTER, DUK_TAG_STRING, DUK_TAG_UNDEFINED, duk_to_primitive(), duk_to_string(), DUK_TVAL_GET_BOOLEAN, DUK_TVAL_GET_BUFFER, DUK_TVAL_GET_POINTER, DUK_TVAL_GET_TAG, DUK_TVAL_IS_NUMBER, DUK_TVAL_IS_UNUSED, DUK_UNREF, duk_hthread::heap, index, and NULL.

Referenced by duk__safe_to_string_raw(), duk_push_string_file_raw(), duk_push_string_tval_readable(), duk_push_this_coercible_to_string(), duk_to_hstring(), duk_to_lstring(), and duk_to_string().

◆ duk_to_uint()

DUK_EXTERNAL duk_uint_t duk_to_uint ( duk_context * ctx,
duk_idx_t index )

Definition at line 1945 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1945 {
1946 /* Value coercion (in stack): ToInteger(), E5 Section 9.4
1947 * API return value coercion: custom
1948 */
1951 return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 0 /*require*/);
1952}

References duk__api_coerce_d2ui(), duk__to_int_uint_helper(), DUK_ASSERT_CTX_VALID, duk_js_tointeger(), and index.

◆ duk_to_uint16()

DUK_EXTERNAL duk_uint16_t duk_to_uint16 ( duk_context * ctx,
duk_idx_t index )

Definition at line 1988 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1988 {
1989 duk_hthread *thr = (duk_hthread *) ctx;
1990 duk_tval *tv;
1991 duk_uint16_t ret;
1992
1994
1995 tv = duk_require_tval(ctx, index);
1996 DUK_ASSERT(tv != NULL);
1997 ret = duk_js_touint16(thr, tv);
1998
1999 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
2000 tv = duk_require_tval(ctx, index);
2001 DUK_TVAL_SET_FASTINT_U32_UPDREF(thr, tv, ret); /* side effects */
2002 return ret;
2003}
#define DUK_TVAL_SET_FASTINT_U32_UPDREF
DUK_INTERNAL_DECL duk_uint16_t duk_js_touint16(duk_hthread *thr, duk_tval *tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_js_touint16(), duk_require_tval(), DUK_TVAL_SET_FASTINT_U32_UPDREF, index, and NULL.

◆ duk_to_uint32()

DUK_EXTERNAL duk_uint32_t duk_to_uint32 ( duk_context * ctx,
duk_idx_t index )

Definition at line 1971 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1971 {
1972 duk_hthread *thr = (duk_hthread *) ctx;
1973 duk_tval *tv;
1974 duk_uint32_t ret;
1975
1977
1978 tv = duk_require_tval(ctx, index);
1979 DUK_ASSERT(tv != NULL);
1980 ret = duk_js_touint32(thr, tv);
1981
1982 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
1983 tv = duk_require_tval(ctx, index);
1984 DUK_TVAL_SET_FASTINT_U32_UPDREF(thr, tv, ret); /* side effects */
1985 return ret;
1986}
DUK_INTERNAL_DECL duk_uint32_t duk_js_touint32(duk_hthread *thr, duk_tval *tv)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_js_touint32(), duk_require_tval(), DUK_TVAL_SET_FASTINT_U32_UPDREF, index, and NULL.

◆ duk_to_uint8clamped()

DUK_INTERNAL duk_uint8_t duk_to_uint8clamped ( duk_context * ctx,
duk_idx_t index )

Definition at line 2007 of file duktape-1.5.2/src-separate/duk_api_stack.c.

2007 {
2008 duk_double_t d;
2009 duk_double_t t;
2010 duk_uint8_t ret;
2011
2012 /* XXX: Simplify this algorithm, should be possible to come up with
2013 * a shorter and faster algorithm by inspecting IEEE representation
2014 * directly.
2015 */
2016
2017 d = duk_to_number(ctx, index);
2018 if (d <= 0.0) {
2019 return 0;
2020 } else if (d >= 255) {
2021 return 255;
2022 } else if (DUK_ISNAN(d)) {
2023 /* Avoid NaN-to-integer coercion as it is compiler specific. */
2024 return 0;
2025 }
2026
2027 t = d - DUK_FLOOR(d);
2028 if (t == 0.5) {
2029 /* Exact halfway, round to even. */
2030 ret = (duk_uint8_t) d;
2031 ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
2032 * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
2033 */
2034 } else {
2035 /* Not halfway, round to nearest. */
2036 ret = (duk_uint8_t) (d + 0.5);
2037 }
2038 return ret;
2039}
DUK_EXTERNAL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index)

References DUK_FLOOR, DUK_ISNAN, duk_to_number(), and index.

◆ duk_to_undefined()

DUK_EXTERNAL void duk_to_undefined ( duk_context * ctx,
duk_idx_t index )

Definition at line 1831 of file duktape-1.5.2/src-separate/duk_api_stack.c.

1831 {
1832 duk_hthread *thr = (duk_hthread *) ctx;
1833 duk_tval *tv;
1834
1836 DUK_UNREF(thr);
1837
1838 tv = duk_require_tval(ctx, index);
1839 DUK_ASSERT(tv != NULL);
1840 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
1841}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_tval(), DUK_TVAL_SET_UNDEFINED_UPDREF, DUK_UNREF, index, and NULL.

◆ duk_valstack_resize_raw()

DUK_INTERNAL duk_bool_t duk_valstack_resize_raw ( duk_context * ctx,
duk_size_t min_new_size,
duk_small_uint_t flags )

Definition at line 618 of file duktape-1.5.2/src-separate/duk_api_stack.c.

620 {
621 duk_hthread *thr = (duk_hthread *) ctx;
622 duk_size_t old_size;
623 duk_size_t new_size;
624 duk_bool_t is_shrink = 0;
625 duk_small_uint_t shrink_flag = (flags & DUK_VSRESIZE_FLAG_SHRINK);
626 duk_small_uint_t compact_flag = (flags & DUK_VSRESIZE_FLAG_COMPACT);
627 duk_small_uint_t throw_flag = (flags & DUK_VSRESIZE_FLAG_THROW);
628
629 DUK_DDD(DUK_DDDPRINT("check valstack resize: min_new_size=%lu, curr_size=%ld, curr_top=%ld, "
630 "curr_bottom=%ld, shrink=%d, compact=%d, throw=%d",
631 (unsigned long) min_new_size,
632 (long) (thr->valstack_end - thr->valstack),
633 (long) (thr->valstack_top - thr->valstack),
634 (long) (thr->valstack_bottom - thr->valstack),
635 (int) shrink_flag, (int) compact_flag, (int) throw_flag));
636
638 DUK_ASSERT(thr != NULL);
639 DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
642
643#if defined(DUK_USE_PREFER_SIZE)
644 old_size = (duk_size_t) (thr->valstack_end - thr->valstack);
645#else
647 old_size = thr->valstack_size;
648#endif
649
650 if (min_new_size <= old_size) {
651 is_shrink = 1;
652 if (!shrink_flag ||
653 old_size - min_new_size < DUK_VALSTACK_SHRINK_THRESHOLD) {
654 DUK_DDD(DUK_DDDPRINT("no need to grow or shrink valstack"));
655 return 1;
656 }
657 }
658
659 new_size = min_new_size;
660 if (!compact_flag) {
661 if (is_shrink) {
662 /* shrink case; leave some spare */
663 new_size += DUK_VALSTACK_SHRINK_SPARE;
664 }
665
666 /* round up roughly to next 'grow step' */
667 new_size = (new_size / DUK_VALSTACK_GROW_STEP + 1) * DUK_VALSTACK_GROW_STEP;
668 }
669
670 DUK_DD(DUK_DDPRINT("want to %s valstack: %lu -> %lu elements (min_new_size %lu)",
671 (const char *) (new_size > old_size ? "grow" : "shrink"),
672 (unsigned long) old_size, (unsigned long) new_size,
673 (unsigned long) min_new_size));
674
675 if (new_size > thr->valstack_max) {
676 /* Note: may be triggered even if minimal new_size would not reach the limit,
677 * plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
678 */
679 if (throw_flag) {
681 } else {
682 return 0;
683 }
684 }
685
686 /*
687 * When resizing the valstack, a mark-and-sweep may be triggered for
688 * the allocation of the new valstack. If the mark-and-sweep needs
689 * to use our thread for something, it may cause *the same valstack*
690 * to be resized recursively. This happens e.g. when mark-and-sweep
691 * finalizers are called. This is taken into account carefully in
692 * duk__resize_valstack().
693 *
694 * 'new_size' is known to be <= valstack_max, which ensures that
695 * size_t and pointer arithmetic won't wrap in duk__resize_valstack().
696 */
697
698 if (!duk__resize_valstack(ctx, new_size)) {
699 if (is_shrink) {
700 DUK_DD(DUK_DDPRINT("valstack resize failed, but is a shrink, ignore"));
701 return 1;
702 }
703
704 DUK_DD(DUK_DDPRINT("valstack resize failed"));
705
706 if (throw_flag) {
708 } else {
709 return 0;
710 }
711 }
712
713 DUK_DDD(DUK_DDDPRINT("valstack resize successful"));
714 return 1;
715}
#define DUK_VALSTACK_SHRINK_THRESHOLD
#define DUK_STR_VALSTACK_LIMIT
#define DUK_VSRESIZE_FLAG_SHRINK
#define DUK_VSRESIZE_FLAG_COMPACT
#define DUK_VALSTACK_GROW_STEP
#define DUK_VALSTACK_SHRINK_SPARE
DUK_LOCAL duk_bool_t duk__resize_valstack(duk_context *ctx, duk_size_t new_size)

References duk__resize_valstack(), DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_DD, DUK_DDD, DUK_DDDPRINT, DUK_DDPRINT, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_RANGE, DUK_STR_VALSTACK_LIMIT, DUK_VALSTACK_GROW_STEP, DUK_VALSTACK_SHRINK_SPARE, DUK_VALSTACK_SHRINK_THRESHOLD, DUK_VSRESIZE_FLAG_COMPACT, DUK_VSRESIZE_FLAG_SHRINK, DUK_VSRESIZE_FLAG_THROW, NULL, duk_hthread::valstack, duk_hthread::valstack_bottom, duk_hthread::valstack_end, duk_hthread::valstack_max, duk_hthread::valstack_size, and duk_hthread::valstack_top.

Referenced by duk_check_stack(), duk_check_stack_top(), duk_require_stack(), and duk_require_stack_top().

◆ duk_xcopymove_raw()

DUK_EXTERNAL void duk_xcopymove_raw ( duk_context * to_ctx,
duk_context * from_ctx,
duk_idx_t count,
duk_bool_t is_copy )

Definition at line 991 of file duktape-1.5.2/src-separate/duk_api_stack.c.

991 {
992 duk_hthread *to_thr = (duk_hthread *) to_ctx;
993 duk_hthread *from_thr = (duk_hthread *) from_ctx;
994 void *src;
995 duk_size_t nbytes;
996 duk_tval *p;
997 duk_tval *q;
998
999 /* XXX: several pointer comparison issues here */
1000
1001 DUK_ASSERT_CTX_VALID(to_ctx);
1002 DUK_ASSERT_CTX_VALID(from_ctx);
1003 DUK_ASSERT(to_ctx != NULL);
1004 DUK_ASSERT(from_ctx != NULL);
1005
1006 if (to_ctx == from_ctx) {
1008 return;
1009 }
1010 if ((count < 0) ||
1011 (count > (duk_idx_t) to_thr->valstack_max)) {
1012 /* Maximum value check ensures 'nbytes' won't wrap below. */
1014 return;
1015 }
1016
1017 nbytes = sizeof(duk_tval) * count;
1018 if (nbytes == 0) {
1019 return;
1020 }
1021 DUK_ASSERT(to_thr->valstack_top <= to_thr->valstack_end);
1022 if ((duk_size_t) ((duk_uint8_t *) to_thr->valstack_end - (duk_uint8_t *) to_thr->valstack_top) < nbytes) {
1024 }
1025 src = (void *) ((duk_uint8_t *) from_thr->valstack_top - nbytes);
1026 if (src < (void *) from_thr->valstack_bottom) {
1028 }
1029
1030 /* copy values (no overlap even if to_ctx == from_ctx; that's not
1031 * allowed now anyway)
1032 */
1033 DUK_ASSERT(nbytes > 0);
1034 DUK_MEMCPY((void *) to_thr->valstack_top, (const void *) src, (size_t) nbytes);
1035
1036 p = to_thr->valstack_top;
1037 to_thr->valstack_top = (duk_tval *) (void *) (((duk_uint8_t *) p) + nbytes);
1038
1039 if (is_copy) {
1040 /* Incref copies, keep originals. */
1041 q = to_thr->valstack_top;
1042 while (p < q) {
1043 DUK_TVAL_INCREF(to_thr, p); /* no side effects */
1044 p++;
1045 }
1046 } else {
1047 /* No net refcount change. */
1048 p = from_thr->valstack_top;
1049 q = (duk_tval *) (void *) (((duk_uint8_t *) p) - nbytes);
1050 from_thr->valstack_top = q;
1051
1052 while (p > q) {
1053 p--;
1055 /* XXX: fast primitive to set a bunch of values to UNDEFINED */
1056 }
1057 }
1058}
#define DUK_STR_INVALID_CONTEXT

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_MEMCPY, DUK_STR_INVALID_CONTEXT, DUK_STR_INVALID_COUNT, DUK_STR_PUSH_BEYOND_ALLOC_STACK, DUK_TVAL_INCREF, DUK_TVAL_SET_UNDEFINED, NULL, duk_hthread::valstack_bottom, duk_hthread::valstack_end, duk_hthread::valstack_max, and duk_hthread::valstack_top.

Variable Documentation

◆ duk__bufobj_flags_lookup

const duk_uint32_t duk__bufobj_flags_lookup[]
static
Initial value:
= {
}
#define DUK_BIDX_UINT8ARRAY_PROTOTYPE
#define DUK_HOBJECT_CLASS_INT32ARRAY
#define DUK_HBUFFEROBJECT_ELEM_INT32
#define DUK_BIDX_INT8ARRAY_PROTOTYPE
#define DUK_HOBJECT_CLASS_INT16ARRAY
#define DUK_BIDX_DATAVIEW_PROTOTYPE
#define DUK_HBUFFEROBJECT_ELEM_INT16
#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY
#define DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE
#define DUK_BIDX_INT32ARRAY_PROTOTYPE
#define DUK_BIDX_FLOAT32ARRAY_PROTOTYPE
#define DUK_HOBJECT_CLASS_FLOAT32ARRAY
#define DUK_HOBJECT_CLASS_UINT8ARRAY
#define DUK_BIDX_UINT32ARRAY_PROTOTYPE
#define DUK_HBUFFEROBJECT_ELEM_UINT32
#define DUK_HBUFFEROBJECT_ELEM_UINT16
#define DUK_HOBJECT_CLASS_UINT32ARRAY
#define DUK_HOBJECT_CLASS_INT8ARRAY
#define DUK_BIDX_NODEJS_BUFFER_PROTOTYPE
#define DUK_HOBJECT_CLASS_UINT16ARRAY
#define DUK_HBUFFEROBJECT_ELEM_FLOAT32
#define DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
#define DUK_HOBJECT_CLASS_DATAVIEW
#define DUK_BIDX_INT16ARRAY_PROTOTYPE
#define DUK_BIDX_UINT16ARRAY_PROTOTYPE
#define DUK_HBUFFEROBJECT_ELEM_INT8
#define DUK__PACK_ARGS(classnum, protobidx, elemtype, elemshift, isview)

Definition at line 3898 of file duktape-1.5.2/src-separate/duk_api_stack.c.

3898 {
3912};
#define DUK_HBUFFEROBJECT_ELEM_FLOAT64
#define DUK_BIDX_FLOAT64ARRAY_PROTOTYPE
#define DUK_HOBJECT_CLASS_FLOAT64ARRAY

Referenced by duk_push_buffer_object().

◆ duk_api_global_filename

DUK_EXTERNAL const char* duk_api_global_filename = NULL

◆ duk_api_global_line

DUK_EXTERNAL duk_int_t duk_api_global_line = 0