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_buffer_data (duk_context *ctx, duk_idx_t idx)
 
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.8.0/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 3927 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3927#define DUK__PACK_ARGS(classnum,protobidx,elemtype,elemshift,isview) \
3928 (((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 1919 of file duktape-1.8.0/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.8.0/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.8.0/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 1779 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1779 {
1780 if (duk_get_prop_stridx(ctx, index, func_stridx)) {
1781 /* [ ... func ] */
1782 if (duk_is_callable(ctx, -1)) {
1783 duk_dup(ctx, index); /* -> [ ... func this ] */
1784 duk_call_method(ctx, 0); /* -> [ ... retval ] */
1785 if (duk_is_primitive(ctx, -1)) {
1786 duk_replace(ctx, index);
1787 return 1;
1788 }
1789 /* [ ... retval ]; popped below */
1790 }
1791 }
1792 duk_pop(ctx); /* [ ... func/retval ] -> [ ... ] */
1793 return 0;
1794}
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 1336 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1336 {
1337 duk_hthread *thr = (duk_hthread *) ctx;
1338 duk_tval *tv;
1339
1341 DUK_UNREF(thr);
1342
1343 if (out_size != NULL) {
1344 *out_size = 0;
1345 }
1346
1347 tv = duk_get_tval(ctx, index);
1348 if (tv == NULL) {
1349 goto fail;
1350 }
1351
1352 if (DUK_TVAL_IS_BUFFER(tv)) {
1354 DUK_ASSERT(h != NULL);
1355 if (out_size) {
1356 *out_size = DUK_HBUFFER_GET_SIZE(h);
1357 }
1358 return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */
1359 } else if (DUK_TVAL_IS_OBJECT(tv)) {
1361 DUK_ASSERT(h != NULL);
1363 /* XXX: this is probably a useful shared helper: for a
1364 * duk_hbufferobject, get a validated buffer pointer/length.
1365 */
1366 duk_hbufferobject *h_bufobj = (duk_hbufferobject *) h;
1368
1369 if (h_bufobj->buf != NULL &&
1371 duk_uint8_t *p;
1372
1373 p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf);
1374 if (out_size != NULL) {
1375 *out_size = (duk_size_t) h_bufobj->length;
1376 }
1377 return (void *) (p + h_bufobj->offset);
1378 }
1379 /* if slice not fully valid, treat as error */
1380 }
1381 }
1382
1383 fail:
1384 if (throw_flag) {
1386 }
1387 return NULL;
1388}
#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 1301 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 2597 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2597 {
2598 duk_hobject *obj;
2599
2601
2602 obj = duk_get_hobject(ctx, index);
2603 if (obj) {
2604 return (DUK_HEAPHDR_CHECK_FLAG_BITS((duk_heaphdr *) obj, flag_mask) ? 1 : 0);
2605 }
2606 return 0;
2607}
#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 3759 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3759 {
3760 duk_hthread *thr = (duk_hthread *) ctx;
3762 duk_idx_t ret;
3763 duk_tval *tv_slot;
3764 duk_int16_t func_nargs;
3765
3767
3768 /* check stack first */
3769 if (thr->valstack_top >= thr->valstack_end) {
3771 }
3772 if (func == NULL) {
3773 goto api_error;
3774 }
3775 if (nargs >= 0 && nargs < DUK_HNATIVEFUNCTION_NARGS_MAX) {
3776 func_nargs = (duk_int16_t) nargs;
3777 } else if (nargs == DUK_VARARGS) {
3779 } else {
3780 goto api_error;
3781 }
3782
3783 obj = duk_hnativefunction_alloc(thr->heap, flags);
3784 if (!obj) {
3786 }
3787
3788 obj->func = func;
3789 obj->nargs = func_nargs;
3790
3791 DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08lx, nargs=%ld",
3792 (unsigned long) obj->obj.hdr.h_flags, (long) obj->nargs));
3793
3794 tv_slot = thr->valstack_top;
3795 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3796 DUK_HOBJECT_INCREF(thr, obj);
3797 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3798 thr->valstack_top++;
3799
3800 /* default prototype (Note: 'obj' must be reachable) */
3802
3803 return ret;
3804
3805 api_error:
3807 return 0; /* not reached */
3808}
#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 4681 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4681 {
4682 duk_hthread *thr;
4683 const duk_uint8_t *p, *p_start, *p_end;
4685 2 /*quotes*/ + 3 /*periods*/];
4686 duk_uint8_t *q;
4688 duk_small_uint_t nchars;
4689
4691 DUK_ASSERT(h_input != NULL);
4692 thr = (duk_hthread *) ctx;
4693
4694 p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input);
4695 p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
4696 p = p_start;
4697 q = buf;
4698
4699 nchars = 0;
4700 *q++ = (duk_uint8_t) DUK_ASC_SINGLEQUOTE;
4701 for (;;) {
4702 if (p >= p_end) {
4703 break;
4704 }
4705 if (nchars == DUK__READABLE_STRING_MAXCHARS) {
4706 *q++ = (duk_uint8_t) DUK_ASC_PERIOD;
4707 *q++ = (duk_uint8_t) DUK_ASC_PERIOD;
4708 *q++ = (duk_uint8_t) DUK_ASC_PERIOD;
4709 break;
4710 }
4711 if (duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) {
4712 if (cp < 0x20 || cp == 0x7f || cp == DUK_ASC_SINGLEQUOTE || cp == DUK_ASC_BACKSLASH) {
4713 DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */
4714 DUK_ASSERT((cp >> 4) <= 0x0f);
4715 *q++ = (duk_uint8_t) DUK_ASC_BACKSLASH;
4716 *q++ = (duk_uint8_t) DUK_ASC_LC_X;
4717 *q++ = (duk_uint8_t) duk_lc_digits[cp >> 4];
4718 *q++ = (duk_uint8_t) duk_lc_digits[cp & 0x0f];
4719 } else {
4720 q += duk_unicode_encode_xutf8(cp, q);
4721 }
4722 } else {
4723 p++; /* advance manually */
4724 *q++ = (duk_uint8_t) DUK_ASC_QUESTION;
4725 }
4726 nchars++;
4727 }
4728 *q++ = (duk_uint8_t) DUK_ASC_SINGLEQUOTE;
4729
4730 duk_push_lstring(ctx, (const char *) buf, (duk_size_t) (q - buf));
4731}
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 3417 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3417 {
3420 DUK_DDD(DUK_DDDPRINT("creating heap/global/thread stash on first use"));
3421 duk_pop(ctx);
3423 duk_dup_top(ctx);
3424 duk_xdef_prop_stridx(ctx, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* [ ... parent stash stash ] -> [ ... parent stash ] */
3425 }
3426 duk_remove(ctx, -2);
3427}
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 3292 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3292 {
3293 duk_hthread *thr;
3294 duk_tval *tv_slot;
3295
3297 DUK_ASSERT_DISABLE(thr->callstack_top >= 0); /* avoid warning (unsigned) */
3298 thr = (duk_hthread *) ctx;
3301
3302 DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */
3303 tv_slot = thr->valstack_top++;
3304
3305 if (DUK_UNLIKELY(thr->callstack_top == 0)) {
3306 if (check_object_coercible) {
3307 goto type_error;
3308 }
3309 /* 'undefined' already on stack top */
3310 } else {
3311 duk_tval *tv;
3312
3313 /* 'this' binding is just before current activation's bottom */
3314 DUK_ASSERT(thr->valstack_bottom > thr->valstack);
3315 tv = thr->valstack_bottom - 1;
3316 if (check_object_coercible &&
3318 /* XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv) */
3319 goto type_error;
3320 }
3321
3322 DUK_TVAL_SET_TVAL(tv_slot, tv);
3323 DUK_TVAL_INCREF(thr, tv);
3324 }
3325 return;
3326
3327 type_error:
3329}
#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.8.0/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 2053 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2053 {
2055
2056 duk_to_string(ctx, -1);
2057 return 1;
2058}
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 2587 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2587 {
2588 duk_tval *tv;
2589
2590 tv = duk_get_tval(ctx, index);
2591 if (!tv) {
2592 return 0;
2593 }
2594 return (DUK_TVAL_GET_TAG(tv) == tag);
2595}

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 1921 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1921 {
1922 duk_hthread *thr = (duk_hthread *) ctx;
1923 duk_tval *tv;
1924 duk_double_t d;
1925
1927
1928 tv = duk_require_tval(ctx, index);
1929 DUK_ASSERT(tv != NULL);
1930 d = coerce_func(thr, tv);
1931
1932 /* XXX: fastint? */
1933
1934 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
1935 tv = duk_require_tval(ctx, index);
1936 DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */
1937 return d;
1938}
#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 3457 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3457 {
3458 duk_int_t len;
3459
3461 DUK_UNREF(ctx);
3462
3463 /* NUL terminator handling doesn't matter here */
3464 len = DUK_VSNPRINTF((char *) buf, sz, fmt, ap);
3465 if (len < (duk_int_t) sz) {
3466 /* Return value of 'sz' or more indicates output was (potentially)
3467 * truncated.
3468 */
3469 return (duk_int_t) len;
3470 }
3471 return -1;
3472}

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.8.0/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.8.0/src-separate/duk_api_stack.c.

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

References DUK_ASSERT_CTX_VALID, DUK_UNLIKELY, DUK_VALSTACK_INTERNAL_EXTRA, duk_valstack_resize_raw(), duk_hthread::valstack, and duk_hthread::valstack_bottom.

◆ 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 2672 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2672 {
2674
2675 return (duk_get_type(ctx, index) == type) ? 1 : 0;
2676}
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 2716 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2716 {
2717 duk_hthread *thr = (duk_hthread *) ctx;
2718
2720
2721 if (duk_get_type_mask(ctx, index) & mask) {
2722 return 1;
2723 }
2724 if (mask & DUK_TYPE_MASK_THROW) {
2727 }
2728 return 0;
2729}
#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 934 of file duktape-1.8.0/src-separate/duk_api_stack.c.

934 {
935 duk_hthread *thr = (duk_hthread *) ctx;
936 duk_tval *tv1;
937 duk_tval *tv2;
938
940 DUK_UNREF(thr); /* w/o refcounting */
941
942 tv1 = duk_require_tval(ctx, from_index);
943 DUK_ASSERT(tv1 != NULL);
944 tv2 = duk_require_tval(ctx, to_index);
945 DUK_ASSERT(tv2 != NULL);
946
947 /* For tv1 == tv2, this is a no-op (no explicit check needed). */
948 DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */
949}
#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 833 of file duktape-1.8.0/src-separate/duk_api_stack.c.

833 {
834 duk_hthread *thr;
835 duk_tval *tv_from;
836 duk_tval *tv_to;
837
839 thr = (duk_hthread *) ctx;
841
842 tv_from = duk_require_tval(ctx, from_index);
843 tv_to = thr->valstack_top++;
844 DUK_ASSERT(tv_from != NULL);
845 DUK_ASSERT(tv_to != NULL);
846 DUK_TVAL_SET_TVAL(tv_to, tv_from);
847 DUK_TVAL_INCREF(thr, tv_to); /* no side effects */
848}

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 850 of file duktape-1.8.0/src-separate/duk_api_stack.c.

850 {
851 duk_hthread *thr;
852 duk_tval *tv_from;
853 duk_tval *tv_to;
854
856 thr = (duk_hthread *) ctx;
858
859 if (thr->valstack_top - thr->valstack_bottom <= 0) {
860 DUK_ERROR_API_INDEX(thr, -1);
861 return; /* unreachable */
862 }
863 tv_from = thr->valstack_top - 1;
864 tv_to = thr->valstack_top++;
865 DUK_ASSERT(tv_from != NULL);
866 DUK_ASSERT(tv_to != NULL);
867 DUK_TVAL_SET_TVAL(tv_to, tv_from);
868 DUK_TVAL_INCREF(thr, tv_to); /* no side effects */
869}
#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 4539 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4539 {
4540 duk_hthread *thr = (duk_hthread *) ctx;
4541 duk_tval *tv1, *tv2;
4542
4544
4545 tv1 = duk_get_tval(ctx, index1);
4546 tv2 = duk_get_tval(ctx, index2);
4547 if ((tv1 == NULL) || (tv2 == NULL)) {
4548 return 0;
4549 }
4550
4551 /* Coercion may be needed, the helper handles that by pushing the
4552 * tagged values to the stack.
4553 */
4554 return duk_js_equals(thr, tv1, tv2);
4555}
#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 4504 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4504 {
4505 va_list ap;
4506
4508
4509 va_start(ap, fmt);
4510 duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4511 va_end(ap);
4512 duk_throw(ctx);
4513}
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 4516 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4516 {
4517 const char *filename;
4518 duk_int_t line;
4519 va_list ap;
4520
4522
4523 filename = duk_api_global_filename;
4524 line = duk_api_global_line;
4527
4528 va_start(ap, fmt);
4529 duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4530 va_end(ap);
4531 duk_throw(ctx);
4532}
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 4497 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4497 {
4499
4500 duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4501 duk_throw(ctx);
4502}

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 4477 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4477 {
4478 duk_hthread *thr = (duk_hthread *) ctx;
4479
4481 DUK_ASSERT(thr != NULL);
4482 DUK_ASSERT(thr->heap != NULL);
4483 DUK_ASSERT(thr->heap->fatal_func != NULL);
4484
4485 DUK_D(DUK_DPRINT("fatal error occurred, code %ld, message %s",
4486 (long) err_code, (const char *) err_msg));
4487
4488 /* fatal_func should be noreturn, but noreturn declarations on function
4489 * pointers has a very spotty support apparently so it's not currently
4490 * done.
4491 */
4492 thr->heap->fatal_func(ctx, err_code, err_msg);
4493
4494 DUK_PANIC(DUK_ERR_API_ERROR, "fatal handler returned");
4495}
#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 1096 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1096 {
1097 duk_bool_t ret = 0; /* default: false */
1098 duk_tval *tv;
1099
1101
1102 tv = duk_get_tval(ctx, index);
1103 if (tv && DUK_TVAL_IS_BOOLEAN(tv)) {
1104 ret = DUK_TVAL_GET_BOOLEAN(tv);
1105 }
1106
1107 DUK_ASSERT(ret == 0 || ret == 1);
1108 return ret;
1109}
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 3367 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3367 {
3368 duk_hthread *thr;
3369
3370 DUK_ASSERT(ctx != NULL);
3371 thr = (duk_hthread *) ctx;
3372
3373 DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */
3374 DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */
3375 DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */
3376
3377 return thr->valstack_bottom - 1;
3378}

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 1328 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1328 {
1329 return duk__get_buffer_helper(ctx, index, out_size, 0 /*throw_flag*/);
1330}
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 1390 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1390 {
1391 return duk__get_buffer_data_helper(ctx, index, out_size, 0 /*throw_flag*/);
1392}
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 1509 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1509 {
1510 duk_tval *tv;
1511 duk_hobject *h;
1513
1515
1516 tv = duk_get_tval(ctx, index);
1517 if (!tv) {
1518 return NULL;
1519 }
1520 if (!DUK_TVAL_IS_OBJECT(tv)) {
1521 return NULL;
1522 }
1523 h = DUK_TVAL_GET_OBJECT(tv);
1524 DUK_ASSERT(h != NULL);
1525
1527 return NULL;
1528 }
1530 f = (duk_hnativefunction *) h;
1531
1532 return f->func;
1533}
#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 1554 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1554 {
1556
1557 return (duk_context *) duk_get_hthread(ctx, index);
1558}
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 2949 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2949 {
2950 duk_hthread *thr = (duk_hthread *) ctx;
2951 duk_hobject *h;
2952 duk_uint_t sanity;
2953
2955
2956 h = duk_get_hobject(ctx, index);
2957
2959 do {
2960 if (!h) {
2961 return DUK_ERR_NONE;
2962 }
2963 if (h == thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE]) {
2964 return DUK_ERR_EVAL_ERROR;
2965 }
2967 return DUK_ERR_RANGE_ERROR;
2968 }
2971 }
2973 return DUK_ERR_SYNTAX_ERROR;
2974 }
2975 if (h == thr->builtins[DUK_BIDX_TYPE_ERROR_PROTOTYPE]) {
2976 return DUK_ERR_TYPE_ERROR;
2977 }
2978 if (h == thr->builtins[DUK_BIDX_URI_ERROR_PROTOTYPE]) {
2979 return DUK_ERR_URI_ERROR;
2980 }
2981 if (h == thr->builtins[DUK_BIDX_ERROR_PROTOTYPE]) {
2982 return DUK_ERR_ERROR;
2983 }
2984
2985 h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
2986 } while (--sanity > 0);
2987
2988 return DUK_ERR_NONE;
2989}
#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 1445 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1445 {
1447}
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 1566 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1566 {
1567 duk_tval *tv;
1568 void *ret;
1569
1571
1572 tv = duk_get_tval(ctx, index);
1573 if (tv && DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
1574 ret = (void *) DUK_TVAL_GET_HEAPHDR(tv);
1575 DUK_ASSERT(ret != NULL);
1576 return ret;
1577 }
1578
1579 return (void *) NULL;
1580}
#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 1614 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1614 {
1615 duk_tval *tv;
1616
1618
1619 tv = duk_require_tval(ctx, index);
1620 DUK_ASSERT(tv != NULL);
1621 if (DUK_TVAL_IS_OBJECT(tv)) {
1622 return DUK_TVAL_GET_OBJECT(tv);
1623 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
1624 duk_to_object(ctx, index);
1625 return duk_require_hobject(ctx, index);
1626 }
1627
1628 return NULL;
1629}
#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 1672 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1672 {
1673 duk_hobject *h;
1674
1676 DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */
1677 DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX);
1678
1680 if (h != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h) != classnum) {
1681 h = NULL;
1682 }
1683 return h;
1684}
#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 1458 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1458 {
1460 if (h != NULL && !DUK_HOBJECT_IS_THREAD(h)) {
1461 h = NULL;
1462 }
1463 return (duk_hthread *) h;
1464}
#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 1171 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1171 {
1172 /* Custom coercion for API */
1174 return (duk_int_t) duk__api_coerce_d2i(ctx, index, 0 /*require*/);
1175}
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 1706 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1706 {
1707 duk_tval *tv;
1708
1710
1711 tv = duk_get_tval(ctx, index);
1712 if (!tv) {
1713 return 0;
1714 }
1715
1716 switch (DUK_TVAL_GET_TAG(tv)) {
1717 case DUK_TAG_UNDEFINED:
1718 case DUK_TAG_NULL:
1719 case DUK_TAG_BOOLEAN:
1720 case DUK_TAG_POINTER:
1721 return 0;
1722 case DUK_TAG_STRING: {
1724 DUK_ASSERT(h != NULL);
1726 }
1727 case DUK_TAG_OBJECT: {
1729 DUK_ASSERT(h != NULL);
1730 return (duk_size_t) duk_hobject_get_length((duk_hthread *) ctx, h);
1731 }
1732 case DUK_TAG_BUFFER: {
1734 DUK_ASSERT(h != NULL);
1735 return (duk_size_t) DUK_HBUFFER_GET_SIZE(h);
1736 }
1737 case DUK_TAG_LIGHTFUNC: {
1738 duk_small_uint_t lf_flags;
1739 lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
1740 return (duk_size_t) DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
1741 }
1742#if defined(DUK_USE_FASTINT)
1743 case DUK_TAG_FASTINT:
1744#endif
1745 default:
1746 /* number */
1749 return 0;
1750 }
1751
1753}
#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 1195 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1195 {
1196 const char *ret;
1197 duk_tval *tv;
1198
1200
1201 /* default: NULL, length 0 */
1202 ret = NULL;
1203 if (out_len) {
1204 *out_len = 0;
1205 }
1206
1207 tv = duk_get_tval(ctx, index);
1208 if (tv && DUK_TVAL_IS_STRING(tv)) {
1209 /* Here we rely on duk_hstring instances always being zero
1210 * terminated even if the actual string is not.
1211 */
1213 DUK_ASSERT(h != NULL);
1214 ret = (const char *) DUK_HSTRING_GET_DATA(h);
1215 if (out_len) {
1216 *out_len = DUK_HSTRING_GET_BYTELEN(h);
1217 }
1218 }
1219
1220 return ret;
1221}
#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 1127 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1127 {
1128 duk_double_union ret;
1129 duk_tval *tv;
1130
1132
1133 ret.d = DUK_DOUBLE_NAN; /* default: NaN */
1134 tv = duk_get_tval(ctx, index);
1135 if (tv && DUK_TVAL_IS_NUMBER(tv)) {
1136 ret.d = DUK_TVAL_GET_NUMBER(tv);
1137 }
1138
1139 /*
1140 * Number should already be in NaN-normalized form, but let's
1141 * normalize anyway.
1142 */
1143
1145 return ret.d;
1146}
#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 1252 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1252 {
1253 duk_tval *tv;
1254
1256
1257 tv = duk_get_tval(ctx, index);
1258 if (tv && DUK_TVAL_IS_POINTER(tv)) {
1259 void *p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */
1260 return (void *) p;
1261 }
1262
1263 return NULL;
1264}
#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 1240 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1240 {
1242
1243 return duk_get_lstring(ctx, index, NULL);
1244}
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.8.0/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.8.0/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.8.0/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_buffer_data(), 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 2609 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 2678 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2678 {
2679 duk_tval *tv;
2680
2682
2683 tv = duk_get_tval(ctx, index);
2684 if (!tv) {
2685 return DUK_TYPE_MASK_NONE;
2686 }
2687 switch (DUK_TVAL_GET_TAG(tv)) {
2688 case DUK_TAG_UNDEFINED:
2690 case DUK_TAG_NULL:
2691 return DUK_TYPE_MASK_NULL;
2692 case DUK_TAG_BOOLEAN:
2693 return DUK_TYPE_MASK_BOOLEAN;
2694 case DUK_TAG_STRING:
2695 return DUK_TYPE_MASK_STRING;
2696 case DUK_TAG_OBJECT:
2697 return DUK_TYPE_MASK_OBJECT;
2698 case DUK_TAG_BUFFER:
2699 return DUK_TYPE_MASK_BUFFER;
2700 case DUK_TAG_POINTER:
2701 return DUK_TYPE_MASK_POINTER;
2702 case DUK_TAG_LIGHTFUNC:
2704#if defined(DUK_USE_FASTINT)
2705 case DUK_TAG_FASTINT:
2706#endif
2707 default:
2708 /* Note: number has no explicit tag (in 8-byte representation) */
2711 return DUK_TYPE_MASK_NUMBER;
2712 }
2714}
#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 1177 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1177 {
1178 /* Custom coercion for API */
1180 return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 0 /*require*/);
1181}
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 871 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 4576 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4576 {
4577 duk_tval *tv1, *tv2;
4578
4580
4581 /* Index validation is strict, which differs from duk_equals().
4582 * The strict behavior mimics how instanceof itself works, e.g.
4583 * it is a TypeError if rval is not a -callable- object. It would
4584 * be somewhat inconsistent if rval would be allowed to be
4585 * non-existent without a TypeError.
4586 */
4587 tv1 = duk_require_tval(ctx, index1);
4588 DUK_ASSERT(tv1 != NULL);
4589 tv2 = duk_require_tval(ctx, index2);
4590 DUK_ASSERT(tv2 != NULL);
4591
4592 return duk_js_instanceof((duk_hthread *) ctx, tv1, tv2);
4593}
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 2851 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2851 {
2852 duk_hobject *obj;
2853
2855
2856 obj = duk_get_hobject(ctx, index);
2857 if (obj) {
2859 }
2860 return 0;
2861}
#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 2755 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2755 {
2757 return duk__tag_check(ctx, index, DUK_TAG_BOOLEAN);
2758}
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 2893 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2893 {
2896 index,
2898}
#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_buffer_data()

DUK_EXTERNAL duk_bool_t duk_is_buffer_data ( duk_context * ctx,
duk_idx_t idx )

Definition at line 2813 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2813 {
2814 duk_tval *tv;
2815
2817
2818 tv = duk_get_tval(ctx, idx);
2819 if (tv == NULL) {
2820 return 0;
2821 }
2822 if (DUK_TVAL_IS_BUFFER(tv)) {
2823 return 1;
2824 } else if (DUK_TVAL_IS_OBJECT(tv)) {
2826 DUK_ASSERT(h != NULL);
2828 return 1;
2829 }
2830 }
2831 return 0;
2832}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_get_tval(), DUK_HOBJECT_IS_BUFFEROBJECT, DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_BUFFER, DUK_TVAL_IS_OBJECT, and NULL.

◆ 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 2921 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2921 {
2922 duk_tval *tv;
2923
2925
2926 tv = duk_get_tval(ctx, index);
2927 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
2929 DUK_ASSERT(h != NULL);
2930 return (DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h) ? 1 : 0);
2931 }
2932 return 0;
2933}
#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 2935 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2935 {
2936 duk_tval *tv;
2937
2939
2940 tv = duk_get_tval(ctx, index);
2941 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
2943 DUK_ASSERT(h != NULL);
2944 return (DUK_HBUFFER_HAS_DYNAMIC(h) && DUK_HBUFFER_HAS_EXTERNAL(h) ? 1 : 0);
2945 }
2946 return 0;
2947}

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 2907 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2907 {
2908 duk_tval *tv;
2909
2911
2912 tv = duk_get_tval(ctx, index);
2913 if (tv && DUK_TVAL_IS_BUFFER(tv)) {
2915 DUK_ASSERT(h != NULL);
2916 return (DUK_HBUFFER_HAS_DYNAMIC(h) ? 0 : 1);
2917 }
2918 return 0;
2919}

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 2779 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 2736 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2736 {
2738 return duk__tag_check(ctx, index, DUK_TAG_NULL);
2739}

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 2741 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2741 {
2742 duk_tval *tv;
2743 duk_small_uint_t tag;
2744
2746
2747 tv = duk_get_tval(ctx, index);
2748 if (!tv) {
2749 return 0;
2750 }
2751 tag = DUK_TVAL_GET_TAG(tv);
2752 return (tag == DUK_TAG_UNDEFINED) || (tag == DUK_TAG_NULL);
2753}

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 2760 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 2797 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2797 {
2799 return duk__tag_check(ctx, index, DUK_TAG_STRING);
2800}

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.8.0/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.8.0/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 4403 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4403 {
4404 duk_hthread *thr = (duk_hthread *) ctx;
4405 duk_tval *tv;
4407
4409 if (DUK_UNLIKELY(thr->valstack_top == thr->valstack_bottom)) {
4411 }
4412
4413 tv = --thr->valstack_top; /* tv points to element just below prev top */
4414 DUK_ASSERT(tv >= thr->valstack_bottom);
4415#ifdef DUK_USE_REFERENCE_COUNTING
4416 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
4417#else
4419#endif
4421}
#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 4424 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4424 {
4426 duk_pop_n(ctx, 2);
4427}
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 4429 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4429 {
4431 duk_pop_n(ctx, 3);
4432}

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 4345 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4345 {
4346 duk_hthread *thr = (duk_hthread *) ctx;
4347 duk_tval *tv;
4348
4350
4351 if (DUK_UNLIKELY(count < 0)) {
4353 return;
4354 }
4355
4357 if (DUK_UNLIKELY((duk_size_t) (thr->valstack_top - thr->valstack_bottom) < (duk_size_t) count)) {
4359 }
4360
4361 /*
4362 * Must be very careful here, every DECREF may cause reallocation
4363 * of our valstack.
4364 */
4365
4366 /* XXX: inlined DECREF macro would be nice here: no NULL check,
4367 * refzero queueing but no refzero algorithm run (= no pointer
4368 * instability), inline code.
4369 */
4370
4371 /* XXX: optimize loops */
4372
4373#if defined(DUK_USE_REFERENCE_COUNTING)
4374 while (count > 0) {
4375 count--;
4376 tv = --thr->valstack_top; /* tv points to element just below prev top */
4377 DUK_ASSERT(tv >= thr->valstack_bottom);
4378 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
4379 }
4380#else
4381 tv = thr->valstack_top;
4382 while (count > 0) {
4383 count--;
4384 tv--;
4385 DUK_ASSERT(tv >= thr->valstack_bottom);
4387 }
4388 thr->valstack_top = tv;
4389#endif
4390
4392}
#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 3618 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3618 {
3619 duk_hthread *thr = (duk_hthread *) ctx;
3620 duk_hobject *obj;
3621 duk_idx_t ret;
3622
3624
3625 ret = duk_push_object_helper(ctx,
3630
3631 obj = duk_require_hobject(ctx, ret);
3632
3633 /*
3634 * An array must have a 'length' property (E5 Section 15.4.5.2).
3635 * The special array behavior flag must only be enabled once the
3636 * length property has been added.
3637 *
3638 * The internal property must be a number (and preferably a
3639 * fastint if fastint support is enabled).
3640 */
3641
3642 duk_push_int(ctx, 0);
3643#if defined(DUK_USE_FASTINT)
3644 DUK_ASSERT(DUK_TVAL_IS_FASTINT(duk_require_tval(ctx, -1)));
3645#endif
3646
3648 obj,
3652
3653 return ret;
3654}
#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 3033 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3033 {
3034 duk_hthread *thr;
3035 duk_tval *tv_slot;
3037
3039 thr = (duk_hthread *) ctx;
3041 b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */
3042 tv_slot = thr->valstack_top++;
3043 DUK_TVAL_SET_BOOLEAN(tv_slot, b);
3044}
#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 3954 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3954 {
3955 duk_hthread *thr;
3956 duk_hbufferobject *h_bufobj;
3957 duk_hbuffer *h_val;
3958 duk_uint32_t tmp;
3959 duk_uint_t classnum;
3960 duk_uint_t protobidx;
3961 duk_uint_t lookupidx;
3962 duk_uint_t uint_offset, uint_length, uint_added;
3963
3965 thr = (duk_hthread *) ctx;
3966 DUK_UNREF(thr);
3967
3968 /* The underlying types for offset/length in duk_hbufferobject is
3969 * duk_uint_t; make sure argument values fit and that offset + length
3970 * does not wrap.
3971 */
3972 uint_offset = (duk_uint_t) byte_offset;
3973 uint_length = (duk_uint_t) byte_length;
3974 if (sizeof(duk_size_t) != sizeof(duk_uint_t)) {
3975 if ((duk_size_t) uint_offset != byte_offset || (duk_size_t) uint_length != byte_length) {
3976 goto range_error;
3977 }
3978 }
3979 uint_added = uint_offset + uint_length;
3980 if (uint_added < uint_offset) {
3981 goto range_error;
3982 }
3983 DUK_ASSERT(uint_added >= uint_offset && uint_added >= uint_length);
3984
3985 DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */
3986 lookupidx = flags & 0x0f; /* 4 low bits */
3987 if (lookupidx >= sizeof(duk__bufobj_flags_lookup) / sizeof(duk_uint32_t)) {
3988 goto arg_error;
3989 }
3990 tmp = duk__bufobj_flags_lookup[lookupidx];
3991 classnum = tmp >> 24;
3992 protobidx = (tmp >> 16) & 0xff;
3993
3994 h_val = duk_require_hbuffer(ctx, idx_buffer);
3995 DUK_ASSERT(h_val != NULL);
3996
3997 h_bufobj = duk_push_bufferobject_raw(ctx,
4001 protobidx);
4002 DUK_ASSERT(h_bufobj != NULL);
4003
4004 h_bufobj->buf = h_val;
4005 DUK_HBUFFER_INCREF(thr, h_val);
4006 h_bufobj->offset = uint_offset;
4007 h_bufobj->length = uint_length;
4008 h_bufobj->shift = (tmp >> 4) & 0x0f;
4009 h_bufobj->elem_type = (tmp >> 8) & 0xff;
4010 h_bufobj->is_view = tmp & 0x0f;
4012
4013#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
4014 /* TypedArray views need an automatic ArrayBuffer which must be
4015 * provided as .buffer property of the view. Just create a new
4016 * ArrayBuffer sharing the same underlying buffer.
4017 *
4018 * The ArrayBuffer offset is always set to zero, so that if one
4019 * accesses the ArrayBuffer at the view's .byteOffset, the value
4020 * matches the view at index 0.
4021 */
4022 if (flags & DUK_BUFOBJ_CREATE_ARRBUF) {
4023 h_bufobj = duk_push_bufferobject_raw(ctx,
4028
4029 DUK_ASSERT(h_bufobj != NULL);
4030
4031 h_bufobj->buf = h_val;
4032 DUK_HBUFFER_INCREF(thr, h_val);
4033 h_bufobj->offset = 0;
4034 h_bufobj->length = uint_offset + uint_length; /* Wrap checked above. */
4035 DUK_ASSERT(h_bufobj->shift == 0);
4037 DUK_ASSERT(h_bufobj->is_view == 0);
4039
4041 duk_compact(ctx, -1);
4042 }
4043#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
4044
4045 return;
4046
4047 range_error:
4049 return; /* not reached */
4050
4051 arg_error:
4053 return; /* not reached */
4054}
#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 4138 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4138 {
4139 duk_hthread *thr = (duk_hthread *) ctx;
4140 duk_tval *tv_slot;
4141 duk_hbuffer *h;
4142 void *buf_data;
4143
4145
4146 /* check stack first */
4147 if (thr->valstack_top >= thr->valstack_end) {
4149 }
4150
4151 /* Check for maximum buffer length. */
4152 if (size > DUK_HBUFFER_MAX_BYTELEN) {
4154 }
4155
4156 h = duk_hbuffer_alloc(thr->heap, size, flags, &buf_data);
4157 if (!h) {
4159 }
4160
4161 tv_slot = thr->valstack_top;
4162 DUK_TVAL_SET_BUFFER(tv_slot, h);
4163 DUK_HBUFFER_INCREF(thr, h);
4164 thr->valstack_top++;
4165
4166 return (void *) buf_data;
4167}
#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 3895 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3895 {
3896 duk_hthread *thr = (duk_hthread *) ctx;
3897 duk_hbufferobject *obj;
3898 duk_tval *tv_slot;
3899
3900 DUK_ASSERT(ctx != NULL);
3901 DUK_ASSERT(prototype_bidx >= 0);
3902
3903 /* check stack first */
3904 if (thr->valstack_top >= thr->valstack_end) {
3906 }
3907
3908 obj = duk_hbufferobject_alloc(thr->heap, hobject_flags_and_class);
3909 if (!obj) {
3911 }
3912
3913 DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, thr->builtins[prototype_bidx]);
3915
3916 tv_slot = thr->valstack_top;
3917 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3918 DUK_HOBJECT_INCREF(thr, obj);
3919 thr->valstack_top++;
3920
3921 return obj;
3922}
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 3810 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3810 {
3811 duk_uint_t flags;
3812
3814
3823
3824 return duk__push_c_function_raw(ctx, func, nargs, flags);
3825}
#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 3858 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3858 {
3859 duk_hthread *thr = (duk_hthread *) ctx;
3860 duk_tval tv_tmp;
3861 duk_small_uint_t lf_flags;
3862
3864
3865 /* check stack first */
3866 if (thr->valstack_top >= thr->valstack_end) {
3868 }
3869
3870 if (nargs >= DUK_LFUNC_NARGS_MIN && nargs <= DUK_LFUNC_NARGS_MAX) {
3871 /* as is */
3872 } else if (nargs == DUK_VARARGS) {
3874 } else {
3875 goto api_error;
3876 }
3877 if (!(length >= DUK_LFUNC_LENGTH_MIN && length <= DUK_LFUNC_LENGTH_MAX)) {
3878 goto api_error;
3879 }
3880 if (!(magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX)) {
3881 goto api_error;
3882 }
3883
3884 lf_flags = DUK_LFUNC_FLAGS_PACK(magic, length, nargs);
3885 DUK_TVAL_SET_LIGHTFUNC(&tv_tmp, func, lf_flags);
3886 duk_push_tval(ctx, &tv_tmp); /* XXX: direct valstack write */
3888 return ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
3889
3890 api_error:
3892 return 0; /* not reached */
3893}
#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 3719 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3719 {
3720 duk_hthread *thr = (duk_hthread *) ctx;
3722 duk_idx_t ret;
3723 duk_tval *tv_slot;
3724
3726
3727 /* check stack first */
3728 if (thr->valstack_top >= thr->valstack_end) {
3730 }
3731
3732 /* Template functions are not strictly constructable (they don't
3733 * have a "prototype" property for instance), so leave the
3734 * DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
3735 */
3736
3741 if (!obj) {
3743 }
3744
3745 DUK_DDD(DUK_DDDPRINT("created compiled function object with flags: 0x%08lx", (unsigned long) obj->obj.hdr.h_flags));
3746
3747 tv_slot = thr->valstack_top;
3748 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3749 DUK_HOBJECT_INCREF(thr, obj);
3750 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3751 thr->valstack_top++;
3752
3753 /* default prototype (Note: 'obj' must be reachable) */
3755
3756 return ret;
3757}
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 3380 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3380 {
3381 duk_hthread *thr = (duk_hthread *) ctx;
3382 duk_activation *act;
3383
3385 DUK_ASSERT(thr != NULL);
3388
3390 if (act) {
3391 duk_push_tval(ctx, &act->tv_func);
3392 } else {
3393 duk_push_undefined(ctx);
3394 }
3395}
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 3397 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3397 {
3398 duk_hthread *thr = (duk_hthread *) ctx;
3399
3401 DUK_ASSERT(thr != NULL);
3402
3403 if (thr->heap->curr_thread) {
3405 } else {
3406 duk_push_undefined(ctx);
3407 }
3408}
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 4108 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4108 {
4109 va_list ap;
4110 duk_idx_t ret;
4111
4113
4114 va_start(ap, fmt);
4115 ret = duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4116 va_end(ap);
4117 return ret;
4118}

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 4121 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4121 {
4122 const char *filename = duk_api_global_filename;
4124 va_list ap;
4125 duk_idx_t ret;
4126
4128
4131 va_start(ap, fmt);
4132 ret = duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
4133 va_end(ap);
4134 return ret;
4135}

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 4056 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4056 {
4057 duk_hthread *thr = (duk_hthread *) ctx;
4058 duk_idx_t ret;
4060#ifdef DUK_USE_AUGMENT_ERROR_CREATE
4061 duk_bool_t noblame_fileline;
4062#endif
4063
4065 DUK_ASSERT(thr != NULL);
4066 DUK_UNREF(filename);
4067 DUK_UNREF(line);
4068
4069 /* Error code also packs a tracedata related flag. */
4070#ifdef DUK_USE_AUGMENT_ERROR_CREATE
4071 noblame_fileline = err_code & DUK_ERRCODE_FLAG_NOBLAME_FILELINE;
4072#endif
4073 err_code = err_code & (~DUK_ERRCODE_FLAG_NOBLAME_FILELINE);
4074
4075 /* error gets its 'name' from the prototype */
4076 proto = duk_error_prototype_from_code(thr, err_code);
4080 proto);
4081
4082 /* ... and its 'message' from an instance property */
4083 if (fmt) {
4084 duk_push_vsprintf(ctx, fmt, ap);
4086 } else {
4087 /* If no explicit message given, put error code into message field
4088 * (as a number). This is not fully in keeping with the Ecmascript
4089 * error model because messages are supposed to be strings (Error
4090 * constructors use ToString() on their argument). However, it's
4091 * probably more useful than having a separate 'code' property.
4092 */
4093 duk_push_int(ctx, err_code);
4095 }
4096
4097 /* XXX: .code = err_code disabled, not sure if useful */
4098
4099 /* Creation time error augmentation */
4100#ifdef DUK_USE_AUGMENT_ERROR_CREATE
4101 /* filename may be NULL in which case file/line is not recorded */
4102 duk_err_augment_error_create(thr, thr, filename, line, noblame_fileline); /* may throw an error */
4103#endif
4104
4105 return ret;
4106}
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 3057 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3057 {
3058 duk_hthread *thr;
3059 duk_tval *tv_slot;
3060
3062 thr = (duk_hthread *) ctx;
3064 tv_slot = thr->valstack_top++;
3066}
#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 3410 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3410 {
3412
3414}
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 3439 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3439 {
3442 duk__push_stash(ctx);
3443}
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 4324 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4324 {
4325 duk_tval tv;
4327 DUK_ASSERT(h != NULL);
4328 DUK_TVAL_SET_BUFFER(&tv, h);
4329 duk_push_tval(ctx, &tv);
4330}

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 4251 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4251 {
4252 duk_hthread *thr = (duk_hthread *) ctx;
4253 duk_idx_t ret;
4254
4256
4257 /* Reviving an object using a heap pointer is a dangerous API
4258 * operation: if the application doesn't guarantee that the
4259 * pointer target is always reachable, difficult-to-diagnose
4260 * problems may ensue. Try to validate the 'ptr' argument to
4261 * the extent possible.
4262 */
4263
4264#if defined(DUK_USE_ASSERTIONS)
4265 duk__validate_push_heapptr(ctx, ptr);
4266#endif
4267
4268 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
4269
4270 if (ptr == NULL) {
4271 goto push_undefined;
4272 }
4273
4274 switch ((int) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) ptr)) {
4275 case DUK_HTYPE_STRING:
4276 duk_push_hstring(ctx, (duk_hstring *) ptr);
4277 break;
4278 case DUK_HTYPE_OBJECT:
4279 duk_push_hobject(ctx, (duk_hobject *) ptr);
4280 break;
4281 case DUK_HTYPE_BUFFER:
4282 duk_push_hbuffer(ctx, (duk_hbuffer *) ptr);
4283 break;
4284 default:
4285 goto push_undefined;
4286 }
4287 return ret;
4288
4289 push_undefined:
4290 duk_push_undefined(ctx);
4291 return ret;
4292}
#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 4332 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4332 {
4333 duk_hthread *thr = (duk_hthread *) ctx;
4335 DUK_ASSERT(thr != NULL);
4336 DUK_ASSERT(builtin_idx >= 0 && builtin_idx < DUK_NUM_BUILTINS);
4337 DUK_ASSERT(thr->builtins[builtin_idx] != NULL);
4338 duk_push_hobject(ctx, thr->builtins[builtin_idx]);
4339}

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 2132 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2132 {
2133 duk_hthread *thr;
2134 duk_hstring *h_strclass;
2135
2137 DUK_ASSERT(h != NULL);
2138 thr = (duk_hthread *) ctx;
2139 DUK_UNREF(thr);
2140
2141 h_strclass = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h);
2142 DUK_ASSERT(h_strclass != NULL);
2143 duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
2144}
#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 4301 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4301 {
4302 duk_tval tv;
4304 DUK_ASSERT(h != NULL);
4305 DUK_TVAL_SET_STRING(&tv, h);
4306 duk_push_tval(ctx, &tv);
4307}
#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 4309 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4309 {
4310 duk_hthread *thr = (duk_hthread *) ctx;
4311 DUK_UNREF(thr);
4312 DUK_ASSERT(stridx >= 0 && stridx < DUK_HEAP_NUM_STRINGS);
4313 duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
4314}
#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 3083 of file duktape-1.8.0/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_INT_MAX <= 0x7fffffffL
3093 DUK_TVAL_SET_FASTINT_I32(tv_slot, (duk_int32_t) val);
3094#else
3095 if (val >= DUK_FASTINT_MIN && val <= DUK_FASTINT_MAX) {
3096 DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val);
3097 } else {
3098 duk_double_t = (duk_double_t) val;
3099 DUK_TVAL_SET_NUMBER(tv_slot, d);
3100 }
3101#endif
3102#else /* DUK_USE_FASTINT */
3103 duk_hthread *thr;
3104 duk_tval *tv_slot;
3105 duk_double_t d;
3106
3108 thr = (duk_hthread *) ctx;
3110 d = (duk_double_t) val;
3111 tv_slot = thr->valstack_top++;
3112 DUK_TVAL_SET_NUMBER(tv_slot, d);
3113#endif /* DUK_USE_FASTINT */
3114}
#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 4599 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4599 {
4600 duk_c_function func;
4601
4603
4604 /* Lightfunc name, includes Duktape/C native function pointer, which
4605 * can often be used to locate the function from a symbol table.
4606 * The name also includes the 16-bit duk_tval flags field because it
4607 * includes the magic value. Because a single native function often
4608 * provides different functionality depending on the magic value, it
4609 * seems reasonably to include it in the name.
4610 *
4611 * On the other hand, a complicated name increases string table
4612 * pressure in low memory environments (but only when function name
4613 * is accessed).
4614 */
4615
4617 duk_push_sprintf(ctx, "light_");
4618 duk_push_string_funcptr(ctx, (duk_uint8_t *) &func, sizeof(func));
4619 duk_push_sprintf(ctx, "_%04x", (unsigned int) DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv));
4620 duk_concat(ctx, 3);
4621}
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 4623 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4623 {
4625
4626 duk_push_string(ctx, "function ");
4627 duk_push_lightfunc_name(ctx, tv);
4628 duk_push_string(ctx, "() {\"light\"}");
4629 duk_concat(ctx, 3);
4630}
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 3164 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3164 {
3165 duk_hthread *thr = (duk_hthread *) ctx;
3166 duk_hstring *h;
3167 duk_tval *tv_slot;
3168
3170
3171 /* check stack before interning (avoid hanging temp) */
3172 if (thr->valstack_top >= thr->valstack_end) {
3174 }
3175
3176 /* NULL with zero length represents an empty string; NULL with higher
3177 * length is also now trated like an empty string although it is
3178 * a bit dubious. This is unlike duk_push_string() which pushes a
3179 * 'null' if the input string is a NULL.
3180 */
3181 if (!str) {
3182 len = 0;
3183 }
3184
3185 /* Check for maximum string length */
3186 if (len > DUK_HSTRING_MAX_BYTELEN) {
3188 }
3189
3190 h = duk_heap_string_intern_checked(thr, (const duk_uint8_t *) str, (duk_uint32_t) len);
3191 DUK_ASSERT(h != NULL);
3192
3193 tv_slot = thr->valstack_top++;
3194 DUK_TVAL_SET_STRING(tv_slot, h);
3195 DUK_HSTRING_INCREF(thr, h); /* no side effects */
3196
3197 return (const char *) DUK_HSTRING_GET_DATA(h);
3198}
#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 3022 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3022 {
3023 duk_hthread *thr;
3024 duk_tval *tv_slot;
3025
3027 thr = (duk_hthread *) ctx;
3029 tv_slot = thr->valstack_top++;
3030 DUK_TVAL_SET_NULL(tv_slot);
3031}
#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 3069 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3069 {
3070 duk_hthread *thr;
3071 duk_tval *tv_slot;
3073
3075 thr = (duk_hthread *) ctx;
3077 du.d = val;
3079 tv_slot = thr->valstack_top++;
3080 DUK_TVAL_SET_NUMBER(tv_slot, du.d);
3081}

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 3554 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3554 {
3555 duk_hthread *thr = (duk_hthread *) ctx;
3556 duk_tval *tv_slot;
3557 duk_hobject *h;
3558 duk_idx_t ret;
3559
3561 DUK_ASSERT(prototype_bidx == -1 ||
3562 (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS));
3563
3564 /* check stack first */
3565 if (thr->valstack_top >= thr->valstack_end) {
3567 }
3568
3569 h = duk_hobject_alloc(thr->heap, hobject_flags_and_class);
3570 if (!h) {
3572 }
3573
3574 DUK_DDD(DUK_DDDPRINT("created object with flags: 0x%08lx", (unsigned long) h->hdr.h_flags));
3575
3576 tv_slot = thr->valstack_top;
3577 DUK_TVAL_SET_OBJECT(tv_slot, h);
3578 DUK_HOBJECT_INCREF(thr, h); /* no side effects */
3579 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3580 thr->valstack_top++;
3581
3582 /* object is now reachable */
3583
3584 if (prototype_bidx >= 0) {
3585 DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, thr->builtins[prototype_bidx]);
3586 } else {
3587 DUK_ASSERT(prototype_bidx == -1);
3589 }
3590
3591 return ret;
3592}
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 3594 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3594 {
3595 duk_hthread *thr = (duk_hthread *) ctx;
3596 duk_idx_t ret;
3597 duk_hobject *h;
3598
3600
3601 ret = duk_push_object_helper(ctx, hobject_flags_and_class, -1);
3602 h = duk_get_hobject(ctx, -1);
3603 DUK_ASSERT(h != NULL);
3606 return ret;
3607}

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 3281 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3281 {
3282 duk_hthread *thr;
3283 duk_tval *tv_slot;
3284
3286 thr = (duk_hthread *) ctx;
3288 tv_slot = thr->valstack_top++;
3289 DUK_TVAL_SET_POINTER(tv_slot, val);
3290}
#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 3540 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3540 {
3541 va_list ap;
3542 const char *ret;
3543
3545
3546 /* allow fmt==NULL */
3547 va_start(ap, fmt);
3548 ret = duk_push_vsprintf(ctx, fmt, ap);
3549 va_end(ap);
3550
3551 return ret;
3552}

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 3200 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3200 {
3202
3203 if (str) {
3204 return duk_push_lstring(ctx, str, DUK_STRLEN(str));
3205 } else {
3206 duk_push_null(ctx);
3207 return NULL;
3208 }
3209}
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 3216 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3216 {
3217 duk_hthread *thr = (duk_hthread *) ctx;
3218 duk_file *f = NULL;
3219 char *buf;
3220 long sz; /* ANSI C typing */
3221
3223
3224 if (!path) {
3225 goto fail;
3226 }
3227 f = DUK_FOPEN(path, "rb");
3228 if (!f) {
3229 goto fail;
3230 }
3231 if (DUK_FSEEK(f, 0, SEEK_END) < 0) {
3232 goto fail;
3233 }
3234 sz = DUK_FTELL(f);
3235 if (sz < 0) {
3236 goto fail;
3237 }
3238 if (DUK_FSEEK(f, 0, SEEK_SET) < 0) {
3239 goto fail;
3240 }
3241 buf = (char *) duk_push_fixed_buffer(ctx, (duk_size_t) sz);
3242 DUK_ASSERT(buf != NULL);
3243 if ((duk_size_t) DUK_FREAD(buf, 1, (size_t) sz, f) != (duk_size_t) sz) {
3244 goto fail;
3245 }
3246 (void) DUK_FCLOSE(f); /* ignore fclose() error */
3247 f = NULL;
3248 return duk_to_string(ctx, -1);
3249
3250 fail:
3251 if (f) {
3252 DUK_FCLOSE(f);
3253 }
3254
3255 if (flags != 0) {
3256 DUK_ASSERT(flags == DUK_STRING_PUSH_SAFE); /* only flag now */
3257 duk_push_undefined(ctx);
3258 } else {
3259 /* XXX: string not shared because it is conditional */
3260 DUK_ERROR_TYPE(thr, "read file error");
3261 }
3262 return NULL;
3263}
#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 4639 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4639 {
4640 duk_uint8_t buf[32 * 2];
4641 duk_uint8_t *p, *q;
4644
4645 DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */
4646
4647 p = buf;
4648#if defined(DUK_USE_INTEGER_LE)
4649 q = ptr + sz;
4650#else
4651 q = ptr;
4652#endif
4653 for (i = 0; i < sz; i++) {
4654#if defined(DUK_USE_INTEGER_LE)
4655 t = *(--q);
4656#else
4657 t = *(q++);
4658#endif
4659 *p++ = duk_lc_digits[t >> 4];
4660 *p++ = duk_lc_digits[t & 0x0f];
4661 }
4662
4663 duk_push_lstring(ctx, (const char *) buf, sz * 2);
4664}

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 4780 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4780 {
4783}
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 4733 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4733 {
4734 duk_hthread *thr;
4735
4737 thr = (duk_hthread *) ctx;
4738 DUK_UNREF(thr);
4739
4740 if (tv == NULL) {
4741 duk_push_string(ctx, "none");
4742 } else {
4743 switch (DUK_TVAL_GET_TAG(tv)) {
4744 case DUK_TAG_STRING: {
4746 break;
4747 }
4748 case DUK_TAG_OBJECT: {
4750 DUK_ASSERT(h != NULL);
4752 break;
4753 }
4754 case DUK_TAG_BUFFER: {
4755 /* XXX: Hex encoded, length limited buffer summary here? */
4757 DUK_ASSERT(h != NULL);
4758 duk_push_sprintf(ctx, "[buffer:%ld]", (long) DUK_HBUFFER_GET_SIZE(h));
4759 break;
4760 }
4761 case DUK_TAG_POINTER: {
4762 /* Surround with parentheses like in JX, ensures NULL pointer
4763 * is distinguishable from null value ("(null)" vs "null").
4764 */
4765 duk_push_tval(ctx, tv);
4766 duk_push_sprintf(ctx, "(%s)", duk_to_string(ctx, -1));
4767 duk_remove(ctx, -2);
4768 break;
4769 }
4770 default: {
4771 duk_push_tval(ctx, tv);
4772 break;
4773 }
4774 }
4775 }
4776
4777 return duk_to_string(ctx, -1);
4778}
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 3331 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3331 {
3333
3334 duk__push_this_helper(ctx, 0 /*check_object_coercible*/);
3335}
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 3337 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3337 {
3339
3340 duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
3341}

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 3343 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3343 {
3344 duk_hobject *h;
3345
3347
3348 duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
3349 duk_to_object(ctx, -1);
3350 h = duk_get_hobject(ctx, -1);
3351 DUK_ASSERT(h != NULL);
3352 return h;
3353}

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 3355 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3355 {
3356 duk_hstring *h;
3357
3359
3360 duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
3361 duk_to_string(ctx, -1);
3362 h = duk_get_hstring(ctx, -1);
3363 DUK_ASSERT(h != NULL);
3364 return h;
3365}
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 3656 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3656 {
3657 duk_hthread *thr = (duk_hthread *) ctx;
3658 duk_hthread *obj;
3659 duk_idx_t ret;
3660 duk_tval *tv_slot;
3661
3663
3664 /* check stack first */
3665 if (thr->valstack_top >= thr->valstack_end) {
3667 }
3668
3669 obj = duk_hthread_alloc(thr->heap,
3673 if (!obj) {
3675 }
3677#if defined(DUK_USE_ROM_STRINGS)
3678 /* Nothing to initialize, strs[] is in ROM. */
3679#else
3680#if defined(DUK_USE_HEAPPTR16)
3681 obj->strs16 = thr->strs16;
3682#else
3683 obj->strs = thr->strs;
3684#endif
3685#endif
3686 DUK_DDD(DUK_DDDPRINT("created thread object with flags: 0x%08lx", (unsigned long) obj->obj.hdr.h_flags));
3687
3688 /* make the new thread reachable */
3689 tv_slot = thr->valstack_top;
3690 DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
3691 DUK_HTHREAD_INCREF(thr, obj);
3692 ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
3693 thr->valstack_top++;
3694
3695 /* important to do this *after* pushing, to make the thread reachable for gc */
3696 if (!duk_hthread_init_stacks(thr->heap, obj)) {
3698 }
3699
3700 /* initialize built-ins - either by copying or creating new ones */
3701 if (flags & DUK_THREAD_NEW_GLOBAL_ENV) {
3703 } else {
3705 }
3706
3707 /* default prototype (Note: 'obj' must be reachable) */
3709
3710 /* Initial stack size satisfies the stack spare constraints so there
3711 * is no need to require stack here.
3712 */
3715
3716 return ret;
3717}
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 3445 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3445 {
3446 duk_hthread *thr = (duk_hthread *) ctx;
3448 if (!target_ctx) {
3450 return; /* not reached */
3451 }
3452 duk_push_hobject(ctx, (duk_hobject *) target_ctx);
3453 duk__push_stash(ctx);
3454}

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 3046 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3046 {
3047 duk_hthread *thr;
3048 duk_tval *tv_slot;
3049
3051 thr = (duk_hthread *) ctx;
3053 tv_slot = thr->valstack_top++;
3055}
#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 3116 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3116 {
3117#if defined(DUK_USE_FASTINT)
3118 duk_hthread *thr;
3119 duk_tval *tv_slot;
3120
3122 thr = (duk_hthread *) ctx;
3124 tv_slot = thr->valstack_top++;
3125#if DUK_UINT_MAX <= 0xffffffffUL
3126 DUK_TVAL_SET_FASTINT_U32(tv_slot, (duk_uint32_t) val);
3127#else
3128 if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */
3129 /* XXX: take advantage of val being unsigned, no need to mask */
3130 DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val);
3131 } else {
3132 duk_double_t = (duk_double_t) val;
3133 DUK_TVAL_SET_NUMBER(tv_slot, d);
3134 }
3135#endif
3136#else /* DUK_USE_FASTINT */
3137 duk_hthread *thr;
3138 duk_tval *tv_slot;
3139 duk_double_t d;
3140
3142 thr = (duk_hthread *) ctx;
3144 d = (duk_double_t) val;
3145 tv_slot = thr->valstack_top++;
3146 DUK_TVAL_SET_NUMBER(tv_slot, d);
3147#endif /* DUK_USE_FASTINT */
3148}
#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 3008 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3008 {
3009 duk_hthread *thr;
3010
3012 thr = (duk_hthread *) ctx;
3014
3015 /* Because value stack init policy is 'undefined above top',
3016 * we don't need to write, just assert.
3017 */
3018 thr->valstack_top++;
3020}

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 3474 of file duktape-1.8.0/src-separate/duk_api_stack.c.

3474 {
3475 duk_hthread *thr = (duk_hthread *) ctx;
3476 duk_uint8_t stack_buf[DUK_PUSH_SPRINTF_INITIAL_SIZE];
3478 duk_bool_t pushed_buf = 0;
3479 void *buf;
3480 duk_int_t len; /* XXX: duk_ssize_t */
3481 const char *res;
3482
3484
3485 /* special handling of fmt==NULL */
3486 if (!fmt) {
3487 duk_hstring *h_str;
3489 h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); /* rely on interning, must be this string */
3490 return (const char *) DUK_HSTRING_GET_DATA(h_str);
3491 }
3492
3493 /* initial estimate based on format string */
3494 sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */
3497 }
3498 DUK_ASSERT(sz > 0);
3499
3500 /* Try to make do with a stack buffer to avoid allocating a temporary buffer.
3501 * This works 99% of the time which is quite nice.
3502 */
3503 for (;;) {
3504 va_list ap_copy; /* copied so that 'ap' can be reused */
3505
3506 if (sz <= sizeof(stack_buf)) {
3507 buf = stack_buf;
3508 } else if (!pushed_buf) {
3509 pushed_buf = 1;
3510 buf = duk_push_dynamic_buffer(ctx, sz);
3511 } else {
3512 buf = duk_resize_buffer(ctx, -1, sz);
3513 }
3514 DUK_ASSERT(buf != NULL);
3515
3516 DUK_VA_COPY(ap_copy, ap);
3517 len = duk__try_push_vsprintf(ctx, buf, sz, fmt, ap_copy);
3518 va_end(ap_copy);
3519 if (len >= 0) {
3520 break;
3521 }
3522
3523 /* failed, resize and try again */
3524 sz = sz * 2;
3527 }
3528 }
3529
3530 /* Cannot use duk_to_string() on the buffer because it is usually
3531 * larger than 'len'. Also, 'buf' is usually a stack buffer.
3532 */
3533 res = duk_push_lstring(ctx, (const char *) buf, (duk_size_t) len); /* [ buf? res ] */
3534 if (pushed_buf) {
3535 duk_remove(ctx, -2);
3536 }
3537 return res;
3538}
#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 951 of file duktape-1.8.0/src-separate/duk_api_stack.c.

951 {
952 duk_hthread *thr = (duk_hthread *) ctx;
953 duk_tval *p;
954 duk_tval *q;
955#ifdef DUK_USE_REFERENCE_COUNTING
956 duk_tval tv_tmp;
957#endif
958 duk_size_t nbytes;
959
961
962 p = duk_require_tval(ctx, index);
963 DUK_ASSERT(p != NULL);
964 q = duk_require_tval(ctx, -1);
965 DUK_ASSERT(q != NULL);
966
967 DUK_ASSERT(q >= p);
968
969 /* nbytes zero size case
970 * <--------->
971 * [ ... | p | x | x | q ] [ ... | p==q ]
972 * => [ ... | x | x | q ] [ ... ]
973 */
974
975#ifdef DUK_USE_REFERENCE_COUNTING
976 /* use a temp: decref only when valstack reachable values are correct */
977 DUK_TVAL_SET_TVAL(&tv_tmp, p);
978#endif
979
980 nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */
981 DUK_MEMMOVE((void *) p, (const void *) (p + 1), (size_t) nbytes); /* zero size not an issue: pointers are valid */
982
984 thr->valstack_top--;
985
986#ifdef DUK_USE_REFERENCE_COUNTING
987 DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */
988#endif
989}
#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 911 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 1111 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 1332 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1332 {
1333 return duk__get_buffer_helper(ctx, index, out_size, 1 /*throw_flag*/);
1334}

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 1394 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1394 {
1395 return duk__get_buffer_data_helper(ctx, index, out_size, 1 /*throw_flag*/);
1396}

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 1535 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1535 {
1536 duk_hthread *thr = (duk_hthread *) ctx;
1537 duk_c_function ret;
1538
1540
1541 ret = duk_get_c_function(ctx, index);
1542 if (!ret) {
1544 }
1545 return ret;
1546}
#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 1560 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1560 {
1562
1563 return (duk_context *) duk_require_hthread(ctx, index);
1564}
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 1548 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1548 {
1549 if (!duk_is_function(ctx, index)) {
1551 }
1552}
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 1582 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1582 {
1583 duk_hthread *thr = (duk_hthread *) ctx;
1584 duk_tval *tv;
1585 void *ret;
1586
1588
1589 tv = duk_require_tval(ctx, index);
1590 DUK_ASSERT(tv != NULL);
1592 ret = (void *) DUK_TVAL_GET_HEAPHDR(tv);
1593 DUK_ASSERT(ret != NULL);
1594 return ret;
1595 }
1596
1598 return (void *) NULL; /* not reachable */
1599}

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 1634 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1634 {
1635 duk_hthread *thr = (duk_hthread *) ctx;
1636 duk_tval *tv;
1637
1639
1640 tv = duk_require_tval(ctx, index);
1641 DUK_ASSERT(tv != NULL);
1642 if (DUK_TVAL_IS_OBJECT(tv)) {
1643 return DUK_TVAL_GET_OBJECT(tv);
1644 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
1645 return NULL;
1646 }
1648 return NULL; /* not reachable */
1649}

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 1655 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1655 {
1656 duk_hthread *thr = (duk_hthread *) ctx;
1657 duk_tval *tv;
1658
1660
1661 tv = duk_require_tval(ctx, index);
1662 if (DUK_TVAL_IS_OBJECT(tv)) {
1663 return DUK_TVAL_GET_OBJECT(tv);
1664 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
1665 duk_to_object(ctx, index);
1666 return duk_require_hobject(ctx, index);
1667 }
1669 return NULL; /* not reachable */
1670}

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 1183 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1183 {
1184 /* Custom coercion for API */
1186 return (duk_int_t) duk__api_coerce_d2i(ctx, index, 1 /*require*/);
1187}

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 1223 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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.8.0/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 1082 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1082 {
1083 duk_hthread *thr = (duk_hthread *) ctx;
1084 duk_tval *tv;
1085
1087
1088 tv = duk_get_tval(ctx, index);
1089 if (tv && DUK_TVAL_IS_NULL(tv)) {
1090 return;
1091 }
1093 return; /* not reachable */
1094}

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 1148 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 1266 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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.8.0/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 783 of file duktape-1.8.0/src-separate/duk_api_stack.c.

783 {
784 duk_hthread *thr;
785 duk_size_t min_new_size;
786
788 thr = (duk_hthread *) ctx;
789
790 if (DUK_UNLIKELY(top < 0)) {
791 /* Clamping to zero makes the API more robust to calling code
792 * calculation errors.
793 */
794 top = 0;
795 }
796
797 min_new_size = (thr->valstack_bottom - thr->valstack) + top + DUK_VALSTACK_INTERNAL_EXTRA;
798 (void) duk_valstack_resize_raw(ctx,
799 min_new_size, /* min_new_size */
800 0 /* no shrink */ | /* flags */
801 0 /* no compact */ |
803}

References DUK_ASSERT_CTX_VALID, DUK_UNLIKELY, DUK_VALSTACK_INTERNAL_EXTRA, duk_valstack_resize_raw(), DUK_VSRESIZE_FLAG_THROW, duk_hthread::valstack, and duk_hthread::valstack_bottom.

◆ duk_require_string()

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

Definition at line 1246 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1246 {
1248
1249 return duk_require_lstring(ctx, index, NULL);
1250}
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.8.0/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.8.0/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 1189 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1189 {
1190 /* Custom coercion for API */
1192 return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 1 /*require*/);
1193}

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 1068 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1068 {
1069 duk_hthread *thr = (duk_hthread *) ctx;
1070 duk_tval *tv;
1071
1073
1074 tv = duk_get_tval(ctx, index);
1075 if (tv && DUK_TVAL_IS_UNDEFINED(tv)) {
1076 return;
1077 }
1079 return; /* not reachable */
1080}
#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.8.0/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 2060 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2060 {
2062
2064
2065 /* We intentionally ignore the duk_safe_call() return value and only
2066 * check the output type. This way we don't also need to check that
2067 * the returned value is indeed a string in the success case.
2068 */
2069
2070 duk_dup(ctx, index);
2071 (void) duk_safe_call(ctx, duk__safe_to_string_raw, 1 /*nargs*/, 1 /*nrets*/);
2072 if (!duk_is_string(ctx, -1)) {
2073 /* Error: try coercing error to string once. */
2074 (void) duk_safe_call(ctx, duk__safe_to_string_raw, 1 /*nargs*/, 1 /*nrets*/);
2075 if (!duk_is_string(ctx, -1)) {
2076 /* Double error */
2077 duk_pop(ctx);
2079 } else {
2080 ;
2081 }
2082 } else {
2083 ;
2084 }
2085 DUK_ASSERT(duk_is_string(ctx, -1));
2086 DUK_ASSERT(duk_get_string(ctx, -1) != NULL);
2087
2088 duk_replace(ctx, index);
2089 return duk_get_lstring(ctx, index, out_len);
2090}
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 1755 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1755 {
1756 duk_hthread *thr = (duk_hthread *) ctx;
1757 duk_hobject *h;
1758
1760
1761 h = duk_get_hobject(ctx, index);
1762 if (!h) {
1763 return;
1764 }
1765
1766 duk_hobject_set_length(thr, h, (duk_uint32_t) length); /* XXX: typing */
1767}
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.8.0/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 4557 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4557 {
4558 duk_tval *tv1, *tv2;
4559
4561
4562 tv1 = duk_get_tval(ctx, index1);
4563 tv2 = duk_get_tval(ctx, index2);
4564 if ((tv1 == NULL) || (tv2 == NULL)) {
4565 return 0;
4566 }
4567
4568 /* No coercions or other side effects, so safe */
4569 return duk_js_strict_equals(tv1, tv2);
4570}
#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 809 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

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 827 of file duktape-1.8.0/src-separate/duk_api_stack.c.

827 {
829
830 duk_swap(ctx, index, -1);
831}
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 4438 of file duktape-1.8.0/src-separate/duk_api_stack.c.

4438 {
4439 duk_hthread *thr = (duk_hthread *) ctx;
4440
4441 DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
4443 DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
4444
4445 if (thr->valstack_top == thr->valstack_bottom) {
4447 }
4448
4449 /* Errors are augmented when they are created, not when they are
4450 * thrown or re-thrown. The current error handler, however, runs
4451 * just before an error is thrown.
4452 */
4453
4454 /* Sync so that augmentation sees up-to-date activations, NULL
4455 * thr->ptr_curr_pc so that it's not used if side effects occur
4456 * in augmentation or longjmp handling.
4457 */
4459
4460#if defined(DUK_USE_AUGMENT_ERROR_THROW)
4461 DUK_DDD(DUK_DDDPRINT("THROW ERROR (API): %!dT (before throw augment)", (duk_tval *) duk_get_tval(ctx, -1)));
4463#endif
4464 DUK_DDD(DUK_DDDPRINT("THROW ERROR (API): %!dT (after throw augment)", (duk_tval *) duk_get_tval(ctx, -1)));
4465
4467
4468 /* thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
4469 * need to check that here. If the value is NULL, a panic occurs because
4470 * we can't return.
4471 */
4472
4473 duk_err_longjmp(thr);
4475}
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 1875 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1875 {
1876 duk_hthread *thr = (duk_hthread *) ctx;
1877 duk_tval *tv;
1878 duk_bool_t val;
1879
1881 DUK_UNREF(thr);
1882
1884
1885 tv = duk_require_tval(ctx, index);
1886 DUK_ASSERT(tv != NULL);
1887
1888 val = duk_js_toboolean(tv);
1889 DUK_ASSERT(val == 0 || val == 1);
1890
1891 /* Note: no need to re-lookup tv, conversion is side effect free */
1892 DUK_ASSERT(tv != NULL);
1893 DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */
1894 return val;
1895}
#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 2317 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

1796 {
1797 duk_hthread *thr = (duk_hthread *) ctx;
1798 duk_hobject *obj;
1799 /* inline initializer for coercers[] is not allowed by old compilers like BCC */
1800 duk_small_int_t coercers[2];
1801
1803 DUK_ASSERT(thr != NULL);
1804
1805 coercers[0] = DUK_STRIDX_VALUE_OF;
1806 coercers[1] = DUK_STRIDX_TO_STRING;
1807
1810
1811 if (hint == DUK_HINT_NONE) {
1813 hint = DUK_HINT_STRING;
1814 } else {
1815 hint = DUK_HINT_NUMBER;
1816 }
1817 }
1818
1819 if (hint == DUK_HINT_STRING) {
1820 coercers[0] = DUK_STRIDX_TO_STRING;
1821 coercers[1] = DUK_STRIDX_VALUE_OF;
1822 }
1823
1824 if (duk__defaultvalue_coerce_attempt(ctx, index, coercers[0])) {
1825 return;
1826 }
1827
1828 if (duk__defaultvalue_coerce_attempt(ctx, index, coercers[1])) {
1829 return;
1830 }
1831
1833}
#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 2308 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2308 {
2309 duk_hstring *ret;
2311 duk_to_string(ctx, index);
2312 ret = duk_get_hstring(ctx, index);
2313 DUK_ASSERT(ret != NULL);
2314 return ret;
2315}

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 1940 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1940 {
1941 /* Value coercion (in stack): ToInteger(), E5 Section 9.4
1942 * API return value coercion: custom
1943 */
1946 return (duk_int_t) duk__api_coerce_d2i(ctx, index, 0 /*require*/);
1947}
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 1958 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1958 {
1959 duk_hthread *thr = (duk_hthread *) ctx;
1960 duk_tval *tv;
1961 duk_int32_t ret;
1962
1964
1965 tv = duk_require_tval(ctx, index);
1966 DUK_ASSERT(tv != NULL);
1967 ret = duk_js_toint32(thr, tv);
1968
1969 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
1970 tv = duk_require_tval(ctx, index);
1971 DUK_TVAL_SET_FASTINT_I32_UPDREF(thr, tv, ret); /* side effects */
1972 return ret;
1973}
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 2216 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2216 {
2217 return duk_to_int_clamped_raw(ctx, index, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */
2218}
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 2211 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2211 {
2213 return duk_to_int_clamped_raw(ctx, index, minval, maxval, &dummy);
2214}

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 2148 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

2046 {
2048
2049 (void) duk_to_string(ctx, index);
2050 return duk_require_lstring(ctx, index, out_len);
2051}

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 1847 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1847 {
1848 duk_hthread *thr = (duk_hthread *) ctx;
1849 duk_tval *tv;
1850
1852 DUK_UNREF(thr);
1853
1854 tv = duk_require_tval(ctx, index);
1855 DUK_ASSERT(tv != NULL);
1856 DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */
1857}
#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 1897 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1897 {
1898 duk_hthread *thr = (duk_hthread *) ctx;
1899 duk_tval *tv;
1900 duk_double_t d;
1901
1903
1904 tv = duk_require_tval(ctx, index);
1905 DUK_ASSERT(tv != NULL);
1906 /* XXX: fastint? */
1907 d = duk_js_tonumber(thr, tv);
1908
1909 /* Note: need to re-lookup because ToNumber() may have side effects */
1910 tv = duk_require_tval(ctx, index);
1911 DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */
1912 return d;
1913}
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 2430 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2430 {
2431 duk_hthread *thr = (duk_hthread *) ctx;
2432 duk_tval *tv;
2433 duk_uint_t flags = 0; /* shared flags for a subset of types */
2435
2437
2439
2440 tv = duk_require_tval(ctx, index);
2441 DUK_ASSERT(tv != NULL);
2442
2443 switch (DUK_TVAL_GET_TAG(tv)) {
2444 case DUK_TAG_UNDEFINED:
2445 case DUK_TAG_NULL: {
2447 break;
2448 }
2449 case DUK_TAG_BOOLEAN: {
2453 goto create_object;
2454 }
2455 case DUK_TAG_STRING: {
2460 goto create_object;
2461 }
2462 case DUK_TAG_OBJECT: {
2463 /* nop */
2464 break;
2465 }
2466 case DUK_TAG_BUFFER: {
2467 /* A plain buffer coerces to a Duktape.Buffer because it's the
2468 * object counterpart of the plain buffer value. But it might
2469 * still make more sense to produce an ArrayBuffer here?
2470 */
2471
2472 duk_hbufferobject *h_bufobj;
2473 duk_hbuffer *h_val;
2474
2475 h_val = DUK_TVAL_GET_BUFFER(tv);
2476 DUK_ASSERT(h_val != NULL);
2477
2478 h_bufobj = duk_push_bufferobject_raw(ctx,
2483 DUK_ASSERT(h_bufobj != NULL);
2486
2487 h_bufobj->buf = h_val;
2488 DUK_HBUFFER_INCREF(thr, h_val);
2489 DUK_ASSERT(h_bufobj->offset == 0);
2490 h_bufobj->length = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_val);
2491 DUK_ASSERT(h_bufobj->shift == 0);
2493
2495 goto replace_value;
2496 }
2497 case DUK_TAG_POINTER: {
2501 goto create_object;
2502 }
2503 case DUK_TAG_LIGHTFUNC: {
2504 /* Lightfunc coerces to a Function instance with concrete
2505 * properties. Since 'length' is virtual for Duktape/C
2506 * functions, don't need to define that.
2507 *
2508 * The result is made extensible to mimic what happens to
2509 * strings:
2510 * > Object.isExtensible(Object('foo'))
2511 * true
2512 */
2513 duk_small_uint_t lf_flags;
2514 duk_idx_t nargs;
2515 duk_small_uint_t lf_len;
2516 duk_c_function func;
2518
2519 DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags);
2520
2521 nargs = (duk_idx_t) DUK_LFUNC_FLAGS_GET_NARGS(lf_flags);
2522 if (nargs == DUK_LFUNC_NARGS_VARARGS) {
2523 nargs = (duk_idx_t) DUK_VARARGS;
2524 }
2531 /* DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally */
2533 (void) duk__push_c_function_raw(ctx, func, nargs, flags);
2534
2535 lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
2536 if ((duk_idx_t) lf_len != nargs) {
2537 /* Explicit length is only needed if it differs from 'nargs'. */
2538 duk_push_int(ctx, (duk_int_t) lf_len);
2540 }
2541 duk_push_lightfunc_name(ctx, tv);
2543
2544 nf = duk_get_hnativefunction(ctx, -1);
2545 DUK_ASSERT(nf != NULL);
2546 nf->magic = (duk_int16_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
2547
2548 /* Enable DUKFUNC exotic behavior once properties are set up. */
2550 goto replace_value;
2551 }
2552#if defined(DUK_USE_FASTINT)
2553 case DUK_TAG_FASTINT:
2554#endif
2555 default: {
2561 goto create_object;
2562 }
2563 }
2564 return;
2565
2566 create_object:
2567 (void) duk_push_object_helper(ctx, flags, proto);
2568
2569 /* Note: Boolean prototype's internal value property is not writable,
2570 * but duk_xdef_prop_stridx() disregards the write protection. Boolean
2571 * instances are immutable.
2572 *
2573 * String and buffer special behaviors are already enabled which is not
2574 * ideal, but a write to the internal value is not affected by them.
2575 */
2576 duk_dup(ctx, index);
2578
2579 replace_value:
2580 duk_replace(ctx, index);
2581}
#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 2102 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2102 {
2103 duk_hthread *thr;
2104 duk_uint_t typemask;
2105 duk_hstring *h_strclass;
2106
2108 thr = (duk_hthread *) ctx;
2109 DUK_UNREF(thr);
2110
2111 typemask = duk_get_type_mask(ctx, -1);
2112 if (typemask & DUK_TYPE_MASK_UNDEFINED) {
2113 h_strclass = DUK_HTHREAD_STRING_UC_UNDEFINED(thr);
2114 } else if (typemask & DUK_TYPE_MASK_NULL) {
2115 h_strclass = DUK_HTHREAD_STRING_UC_NULL(thr);
2116 } else {
2117 duk_hobject *h_obj;
2118
2119 duk_to_object(ctx, -1);
2120 h_obj = duk_get_hobject(ctx, -1);
2121 DUK_ASSERT(h_obj != NULL);
2122
2123 h_strclass = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h_obj);
2124 }
2125 DUK_ASSERT(h_strclass != NULL);
2126
2127 duk_pop(ctx);
2128 duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
2129}
#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 2379 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2379 {
2380 duk_tval *tv;
2381 void *res;
2382
2384
2386
2387 tv = duk_require_tval(ctx, index);
2388 DUK_ASSERT(tv != NULL);
2389
2390 switch (DUK_TVAL_GET_TAG(tv)) {
2391 case DUK_TAG_UNDEFINED:
2392 case DUK_TAG_NULL:
2393 case DUK_TAG_BOOLEAN:
2394 res = NULL;
2395 break;
2396 case DUK_TAG_POINTER:
2397 res = DUK_TVAL_GET_POINTER(tv);
2398 break;
2399 case DUK_TAG_STRING:
2400 case DUK_TAG_OBJECT:
2401 case DUK_TAG_BUFFER:
2402 /* Heap allocated: return heap pointer which is NOT useful
2403 * for the caller, except for debugging.
2404 */
2405 res = (void *) DUK_TVAL_GET_HEAPHDR(tv);
2406 break;
2407 case DUK_TAG_LIGHTFUNC:
2408 /* Function pointers do not always cast correctly to void *
2409 * (depends on memory and segmentation model for instance),
2410 * so they coerce to NULL.
2411 */
2412 res = NULL;
2413 break;
2414#if defined(DUK_USE_FASTINT)
2415 case DUK_TAG_FASTINT:
2416#endif
2417 default:
2418 /* number */
2421 res = NULL;
2422 break;
2423 }
2424
2425 duk_push_pointer(ctx, res);
2426 duk_replace(ctx, index);
2427 return res;
2428}
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 1860 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1860 {
1862 DUK_ASSERT(hint == DUK_HINT_NONE || hint == DUK_HINT_NUMBER || hint == DUK_HINT_STRING);
1863
1865
1868 /* everything except object stay as is */
1869 return;
1870 }
1871 duk_to_defaultvalue(ctx, index, hint);
1872}
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 2220 of file duktape-1.8.0/src-separate/duk_api_stack.c.

2220 {
2221 duk_hthread *thr = (duk_hthread *) ctx;
2222 duk_tval *tv;
2223
2225 DUK_UNREF(thr);
2226
2228
2229 tv = duk_require_tval(ctx, index);
2230 DUK_ASSERT(tv != NULL);
2231
2232 switch (DUK_TVAL_GET_TAG(tv)) {
2233 case DUK_TAG_UNDEFINED: {
2235 break;
2236 }
2237 case DUK_TAG_NULL: {
2239 break;
2240 }
2241 case DUK_TAG_BOOLEAN: {
2242 if (DUK_TVAL_GET_BOOLEAN(tv)) {
2244 } else {
2246 }
2247 break;
2248 }
2249 case DUK_TAG_STRING: {
2250 /* nop */
2251 goto skip_replace;
2252 }
2253 case DUK_TAG_OBJECT: {
2255 return duk_to_string(ctx, index); /* Note: recursive call */
2256 }
2257 case DUK_TAG_BUFFER: {
2259
2260 /* Note: this allows creation of internal strings. */
2261
2262 DUK_ASSERT(h != NULL);
2263 duk_push_lstring(ctx,
2264 (const char *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h),
2266 break;
2267 }
2268 case DUK_TAG_POINTER: {
2269 void *ptr = DUK_TVAL_GET_POINTER(tv);
2270 if (ptr != NULL) {
2271 duk_push_sprintf(ctx, DUK_STR_FMT_PTR, (void *) ptr);
2272 } else {
2273 /* Represent a null pointer as 'null' to be consistent with
2274 * the JX format variant. Native '%p' format for a NULL
2275 * pointer may be e.g. '(nil)'.
2276 */
2278 }
2279 break;
2280 }
2281 case DUK_TAG_LIGHTFUNC: {
2282 /* Should match Function.prototype.toString() */
2284 break;
2285 }
2286#if defined(DUK_USE_FASTINT)
2287 case DUK_TAG_FASTINT:
2288#endif
2289 default: {
2290 /* number */
2293 duk_push_tval(ctx, tv);
2295 10 /*radix*/,
2296 0 /*precision:shortest*/,
2297 0 /*force_exponential*/);
2298 break;
2299 }
2300 }
2301
2302 duk_replace(ctx, index);
2303
2304 skip_replace:
2305 return duk_require_string(ctx, index);
2306}
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 1949 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1949 {
1950 /* Value coercion (in stack): ToInteger(), E5 Section 9.4
1951 * API return value coercion: custom
1952 */
1955 return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 0 /*require*/);
1956}

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 1992 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1992 {
1993 duk_hthread *thr = (duk_hthread *) ctx;
1994 duk_tval *tv;
1995 duk_uint16_t ret;
1996
1998
1999 tv = duk_require_tval(ctx, index);
2000 DUK_ASSERT(tv != NULL);
2001 ret = duk_js_touint16(thr, tv);
2002
2003 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
2004 tv = duk_require_tval(ctx, index);
2005 DUK_TVAL_SET_FASTINT_U32_UPDREF(thr, tv, ret); /* side effects */
2006 return ret;
2007}
#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 1975 of file duktape-1.8.0/src-separate/duk_api_stack.c.

1975 {
1976 duk_hthread *thr = (duk_hthread *) ctx;
1977 duk_tval *tv;
1978 duk_uint32_t ret;
1979
1981
1982 tv = duk_require_tval(ctx, index);
1983 DUK_ASSERT(tv != NULL);
1984 ret = duk_js_touint32(thr, tv);
1985
1986 /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
1987 tv = duk_require_tval(ctx, index);
1988 DUK_TVAL_SET_FASTINT_U32_UPDREF(thr, tv, ret); /* side effects */
1989 return ret;
1990}
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 2011 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

1835 {
1836 duk_hthread *thr = (duk_hthread *) ctx;
1837 duk_tval *tv;
1838
1840 DUK_UNREF(thr);
1841
1842 tv = duk_require_tval(ctx, index);
1843 DUK_ASSERT(tv != NULL);
1844 DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
1845}

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.8.0/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 995 of file duktape-1.8.0/src-separate/duk_api_stack.c.

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

3931 {
3945};
#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