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

Go to the source code of this file.

Functions

DUK_LOCAL void duk__call_prop_prep_stack (duk_context *ctx, duk_idx_t normalized_obj_index, duk_idx_t nargs)
 
DUK_EXTERNAL void duk_call (duk_context *ctx, duk_idx_t nargs)
 
DUK_EXTERNAL void duk_call_method (duk_context *ctx, duk_idx_t nargs)
 
DUK_EXTERNAL void duk_call_prop (duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs)
 
DUK_EXTERNAL duk_int_t duk_pcall (duk_context *ctx, duk_idx_t nargs)
 
DUK_EXTERNAL duk_int_t duk_pcall_method (duk_context *ctx, duk_idx_t nargs)
 
DUK_LOCAL duk_ret_t duk__pcall_prop_raw (duk_context *ctx)
 
DUK_EXTERNAL duk_int_t duk_pcall_prop (duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs)
 
DUK_EXTERNAL duk_int_t duk_safe_call (duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets)
 
DUK_EXTERNAL void duk_new (duk_context *ctx, duk_idx_t nargs)
 
DUK_LOCAL duk_ret_t duk__pnew_helper (duk_context *ctx)
 
DUK_EXTERNAL duk_int_t duk_pnew (duk_context *ctx, duk_idx_t nargs)
 
DUK_EXTERNAL duk_bool_t duk_is_constructor_call (duk_context *ctx)
 
DUK_EXTERNAL duk_bool_t duk_is_strict_call (duk_context *ctx)
 
DUK_EXTERNAL duk_int_t duk_get_current_magic (duk_context *ctx)
 
DUK_EXTERNAL duk_int_t duk_get_magic (duk_context *ctx, duk_idx_t index)
 
DUK_EXTERNAL void duk_set_magic (duk_context *ctx, duk_idx_t index, duk_int_t magic)
 

Function Documentation

◆ duk__call_prop_prep_stack()

DUK_LOCAL void duk__call_prop_prep_stack ( duk_context * ctx,
duk_idx_t normalized_obj_index,
duk_idx_t nargs )

Definition at line 12 of file duktape-1.5.2/src-separate/duk_api_call.c.

12 {
14
15 DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_index=%ld, nargs=%ld, stacktop=%ld",
16 (long) normalized_obj_index, (long) nargs, (long) duk_get_top(ctx)));
17
18 /* [... key arg1 ... argN] */
19
20 /* duplicate key */
21 duk_dup(ctx, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */
22 duk_get_prop(ctx, normalized_obj_index);
23
24 DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
25
26 /* [... key arg1 ... argN func] */
27
28 duk_replace(ctx, -nargs - 2);
29
30 /* [... func arg1 ... argN] */
31
32 duk_dup(ctx, normalized_obj_index);
33 duk_insert(ctx, -nargs - 1);
34
35 /* [... func this arg1 ... argN] */
36}
#define DUK_ASSERT_CTX_VALID(ctx)
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_insert(duk_context *ctx, duk_idx_t to_index)
DUK_EXTERNAL duk_idx_t duk_get_top(duk_context *ctx)
DUK_EXTERNAL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index)
DUK_INTERNAL_DECL duk_tval * duk_get_tval(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT_CTX_VALID, DUK_DDD, DUK_DDDPRINT, duk_dup(), duk_get_prop(), duk_get_top(), duk_get_tval(), duk_insert(), and duk_replace().

Referenced by duk__pcall_prop_raw(), and duk_call_prop().

◆ duk__pcall_prop_raw()

DUK_LOCAL duk_ret_t duk__pcall_prop_raw ( duk_context * ctx)

Definition at line 166 of file duktape-1.5.2/src-separate/duk_api_call.c.

166 {
167 duk_idx_t obj_index;
168 duk_idx_t nargs;
169
170 /* Get the original arguments. Note that obj_index may be a relative
171 * index so the stack must have the same top when we use it.
172 */
173
175
176 obj_index = (duk_idx_t) duk_get_int(ctx, -2);
177 nargs = (duk_idx_t) duk_get_int(ctx, -1);
178 duk_pop_2(ctx);
179
180 obj_index = duk_require_normalize_index(ctx, obj_index); /* make absolute */
181 duk__call_prop_prep_stack(ctx, obj_index, nargs);
182 duk_call_method(ctx, nargs);
183 return 1;
184}
DUK_EXTERNAL void duk_pop_2(duk_context *ctx)
DUK_EXTERNAL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index)
DUK_LOCAL void duk__call_prop_prep_stack(duk_context *ctx, duk_idx_t normalized_obj_index, duk_idx_t nargs)
DUK_EXTERNAL void duk_call_method(duk_context *ctx, duk_idx_t nargs)

References duk__call_prop_prep_stack(), DUK_ASSERT_CTX_VALID, duk_call_method(), duk_get_int(), duk_pop_2(), and duk_require_normalize_index().

Referenced by duk_pcall_prop().

◆ duk__pnew_helper()

DUK_LOCAL duk_ret_t duk__pnew_helper ( duk_context * ctx)

Definition at line 423 of file duktape-1.5.2/src-separate/duk_api_call.c.

423 {
424 duk_uint_t nargs;
425
426 nargs = duk_to_uint(ctx, -1);
427 duk_pop(ctx);
428
429 duk_new(ctx, nargs);
430 return 1;
431}
duk_uint_fast32_t duk_uint_t
DUK_EXTERNAL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL void duk_pop(duk_context *ctx)
DUK_EXTERNAL void duk_new(duk_context *ctx, duk_idx_t nargs)

References duk_new(), duk_pop(), and duk_to_uint().

Referenced by duk_pnew().

◆ duk_call()

DUK_EXTERNAL void duk_call ( duk_context * ctx,
duk_idx_t nargs )

Definition at line 38 of file duktape-1.5.2/src-separate/duk_api_call.c.

38 {
39 duk_hthread *thr = (duk_hthread *) ctx;
40 duk_small_uint_t call_flags;
41 duk_idx_t idx_func;
42
44 DUK_ASSERT(thr != NULL);
45
46 idx_func = duk_get_top(ctx) - nargs - 1;
47 if (idx_func < 0 || nargs < 0) {
48 /* note that we can't reliably pop anything here */
50 }
51
52 /* XXX: awkward; we assume there is space for this, overwrite
53 * directly instead?
54 */
56 duk_insert(ctx, idx_func + 1);
57
58 call_flags = 0; /* not protected, respect reclimit, not constructor */
59
60 duk_handle_call_unprotected(thr, /* thread */
61 nargs, /* num_stack_args */
62 call_flags); /* call_flags */
63}
unsigned int duk_small_uint_t
#define DUK_STR_INVALID_CALL_ARGS
#define DUK_ERROR_API(thr, msg)
DUK_INTERNAL_DECL void duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t num_stack_args, duk_small_uint_t call_flags)
DUK_EXTERNAL void duk_push_undefined(duk_context *ctx)
#define NULL
Definition gmacros.h:924

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, duk_get_top(), duk_handle_call_unprotected(), duk_insert(), duk_push_undefined(), DUK_STR_INVALID_CALL_ARGS, and NULL.

◆ duk_call_method()

DUK_EXTERNAL void duk_call_method ( duk_context * ctx,
duk_idx_t nargs )

Definition at line 65 of file duktape-1.5.2/src-separate/duk_api_call.c.

65 {
66 duk_hthread *thr = (duk_hthread *) ctx;
67 duk_small_uint_t call_flags;
68 duk_idx_t idx_func;
69
71 DUK_ASSERT(thr != NULL);
72
73 idx_func = duk_get_top(ctx) - nargs - 2; /* must work for nargs <= 0 */
74 if (idx_func < 0 || nargs < 0) {
75 /* note that we can't reliably pop anything here */
77 }
78
79 call_flags = 0; /* not protected, respect reclimit, not constructor */
80
81 duk_handle_call_unprotected(thr, /* thread */
82 nargs, /* num_stack_args */
83 call_flags); /* call_flags */
84}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, duk_get_top(), duk_handle_call_unprotected(), DUK_STR_INVALID_CALL_ARGS, and NULL.

Referenced by duk__pcall_prop_raw(), and duk_call_prop().

◆ duk_call_prop()

DUK_EXTERNAL void duk_call_prop ( duk_context * ctx,
duk_idx_t obj_index,
duk_idx_t nargs )

Definition at line 86 of file duktape-1.5.2/src-separate/duk_api_call.c.

86 {
87 /*
88 * XXX: if duk_handle_call() took values through indices, this could be
89 * made much more sensible. However, duk_handle_call() needs to fudge
90 * the 'this' and 'func' values to handle bound function chains, which
91 * is now done "in-place", so this is not a trivial change.
92 */
93
95
96 obj_index = duk_require_normalize_index(ctx, obj_index); /* make absolute */
97
98 duk__call_prop_prep_stack(ctx, obj_index, nargs);
99
100 duk_call_method(ctx, nargs);
101}

References duk__call_prop_prep_stack(), DUK_ASSERT_CTX_VALID, duk_call_method(), and duk_require_normalize_index().

◆ duk_get_current_magic()

DUK_EXTERNAL duk_int_t duk_get_current_magic ( duk_context * ctx)

Definition at line 493 of file duktape-1.5.2/src-separate/duk_api_call.c.

493 {
494 duk_hthread *thr = (duk_hthread *) ctx;
495 duk_activation *act;
496 duk_hobject *func;
497
499 DUK_ASSERT(thr != NULL);
501
503 if (act) {
504 func = DUK_ACT_GET_FUNC(act);
505 if (!func) {
506 duk_tval *tv = &act->tv_func;
507 duk_small_uint_t lf_flags;
508 lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
509 return (duk_int_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
510 }
511 DUK_ASSERT(func != NULL);
512
515 return (duk_int_t) nf->magic;
516 }
517 }
518 return 0;
519}
duk_int_fast32_t duk_int_t
#define DUK_ASSERT_DISABLE(x)
#define DUK_HOBJECT_IS_NATIVEFUNCTION(h)
#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags)
#define DUK_ACT_GET_FUNC(act)
#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv)
DUK_INTERNAL_DECL duk_activation * duk_hthread_get_current_activation(duk_hthread *thr)

References duk_hthread::callstack_top, DUK_ACT_GET_FUNC, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, DUK_HOBJECT_IS_NATIVEFUNCTION, duk_hthread_get_current_activation(), DUK_LFUNC_FLAGS_GET_MAGIC, DUK_TVAL_GET_LIGHTFUNC_FLAGS, duk_hnativefunction::magic, NULL, and duk_activation::tv_func.

◆ duk_get_magic()

DUK_EXTERNAL duk_int_t duk_get_magic ( duk_context * ctx,
duk_idx_t index )

Definition at line 521 of file duktape-1.5.2/src-separate/duk_api_call.c.

521 {
522 duk_hthread *thr = (duk_hthread *) ctx;
523 duk_tval *tv;
524 duk_hobject *h;
525
527
528 tv = duk_require_tval(ctx, index);
529 if (DUK_TVAL_IS_OBJECT(tv)) {
530 h = DUK_TVAL_GET_OBJECT(tv);
531 DUK_ASSERT(h != NULL);
533 goto type_error;
534 }
535 return (duk_int_t) ((duk_hnativefunction *) h)->magic;
536 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
538 return (duk_int_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
539 }
540
541 /* fall through */
542 type_error:
544 return 0;
545}
guint index
#define DUK_ERROR_TYPE(thr, msg)
#define DUK_TVAL_GET_OBJECT(tv)
#define DUK_TVAL_IS_OBJECT(tv)
#define DUK_TVAL_IS_LIGHTFUNC(tv)
#define DUK_HOBJECT_HAS_NATIVEFUNCTION(h)
DUK_INTERNAL_DECL duk_tval * duk_require_tval(duk_context *ctx, duk_idx_t index)
#define DUK_STR_UNEXPECTED_TYPE

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_TYPE, DUK_HOBJECT_HAS_NATIVEFUNCTION, DUK_LFUNC_FLAGS_GET_MAGIC, duk_require_tval(), DUK_STR_UNEXPECTED_TYPE, DUK_TVAL_GET_LIGHTFUNC_FLAGS, DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_LIGHTFUNC, DUK_TVAL_IS_OBJECT, index, and NULL.

◆ duk_is_constructor_call()

DUK_EXTERNAL duk_bool_t duk_is_constructor_call ( duk_context * ctx)

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

451 {
452 duk_hthread *thr = (duk_hthread *) ctx;
453 duk_activation *act;
454
456 DUK_ASSERT(thr != NULL);
458
460 DUK_ASSERT(act != NULL); /* because callstack_top > 0 */
461 return ((act->flags & DUK_ACT_FLAG_CONSTRUCT) != 0 ? 1 : 0);
462}
#define DUK_ACT_FLAG_CONSTRUCT

References duk_hthread::callstack_top, DUK_ACT_FLAG_CONSTRUCT, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, duk_hthread_get_current_activation(), duk_activation::flags, and NULL.

◆ duk_is_strict_call()

DUK_EXTERNAL duk_bool_t duk_is_strict_call ( duk_context * ctx)

Definition at line 464 of file duktape-1.5.2/src-separate/duk_api_call.c.

464 {
465 duk_hthread *thr = (duk_hthread *) ctx;
466 duk_activation *act;
467
468 /* For user code this could just return 1 (strict) always
469 * because all Duktape/C functions are considered strict,
470 * and strict is also the default when nothing is running.
471 * However, Duktape may call this function internally when
472 * the current activation is an Ecmascript function, so
473 * this cannot be replaced by a 'return 1' without fixing
474 * the internal call sites.
475 */
476
478 DUK_ASSERT(thr != NULL);
480
482 if (act == NULL) {
483 /* Strict by default. */
484 return 1;
485 }
486 return ((act->flags & DUK_ACT_FLAG_STRICT) != 0 ? 1 : 0);
487}

References duk_hthread::callstack_top, DUK_ACT_FLAG_STRICT, DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ASSERT_DISABLE, duk_hthread_get_current_activation(), duk_activation::flags, and NULL.

◆ duk_new()

DUK_EXTERNAL void duk_new ( duk_context * ctx,
duk_idx_t nargs )

Definition at line 225 of file duktape-1.5.2/src-separate/duk_api_call.c.

225 {
226 /*
227 * There are two [[Construct]] operations in the specification:
228 *
229 * - E5 Section 13.2.2: for Function objects
230 * - E5 Section 15.3.4.5.2: for "bound" Function objects
231 *
232 * The chain of bound functions is resolved in Section 15.3.4.5.2,
233 * with arguments "piling up" until the [[Construct]] internal
234 * method is called on the final, actual Function object. Note
235 * that the "prototype" property is looked up *only* from the
236 * final object, *before* calling the constructor.
237 *
238 * Currently we follow the bound function chain here to get the
239 * "prototype" property value from the final, non-bound function.
240 * However, we let duk_handle_call() handle the argument "piling"
241 * when the constructor is called. The bound function chain is
242 * thus now processed twice.
243 *
244 * When constructing new Array instances, an unnecessary object is
245 * created and discarded now: the standard [[Construct]] creates an
246 * object, and calls the Array constructor. The Array constructor
247 * returns an Array instance, which is used as the result value for
248 * the "new" operation; the object created before the Array constructor
249 * call is discarded.
250 *
251 * This would be easy to fix, e.g. by knowing that the Array constructor
252 * will always create a replacement object and skip creating the fallback
253 * object in that case.
254 *
255 * Note: functions called via "new" need to know they are called as a
256 * constructor. For instance, built-in constructors behave differently
257 * depending on how they are called.
258 */
259
260 /* XXX: merge this with duk_js_call.c, as this function implements
261 * core semantics (or perhaps merge the two files altogether).
262 */
263
264 duk_hthread *thr = (duk_hthread *) ctx;
266 duk_hobject *cons;
267 duk_hobject *fallback;
268 duk_idx_t idx_cons;
269 duk_small_uint_t call_flags;
270
272
273 /* [... constructor arg1 ... argN] */
274
275 idx_cons = duk_require_normalize_index(ctx, -nargs - 1);
276
277 DUK_DDD(DUK_DDDPRINT("top=%ld, nargs=%ld, idx_cons=%ld",
278 (long) duk_get_top(ctx), (long) nargs, (long) idx_cons));
279
280 /* XXX: code duplication */
281
282 /*
283 * Figure out the final, non-bound constructor, to get "prototype"
284 * property.
285 */
286
287 duk_dup(ctx, idx_cons);
288 for (;;) {
289 duk_tval *tv;
290 tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
291 DUK_ASSERT(tv != NULL);
292
293 if (DUK_TVAL_IS_OBJECT(tv)) {
294 cons = DUK_TVAL_GET_OBJECT(tv);
295 DUK_ASSERT(cons != NULL);
297 /* Checking callability of the immediate target
298 * is important, same for constructability.
299 * Checking it for functions down the bound
300 * function chain is not strictly necessary
301 * because .bind() should normally reject them.
302 * But it's good to check anyway because it's
303 * technically possible to edit the bound function
304 * chain via internal keys.
305 */
306 goto not_constructable;
307 }
308 if (!DUK_HOBJECT_HAS_BOUND(cons)) {
309 break;
310 }
311 } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
312 /* Lightfuncs cannot be bound. */
313 break;
314 } else {
315 /* Anything else is not constructable. */
316 goto not_constructable;
317 }
318 duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_TARGET); /* -> [... cons target] */
319 duk_remove(ctx, -2); /* -> [... target] */
320 }
321 DUK_ASSERT(duk_is_callable(ctx, -1));
322 DUK_ASSERT(duk_is_lightfunc(ctx, -1) ||
323 (duk_get_hobject(ctx, -1) != NULL && !DUK_HOBJECT_HAS_BOUND(duk_get_hobject(ctx, -1))));
324
325 /* [... constructor arg1 ... argN final_cons] */
326
327 /*
328 * Create "fallback" object to be used as the object instance,
329 * unless the constructor returns a replacement value.
330 * Its internal prototype needs to be set based on "prototype"
331 * property of the constructor.
332 */
333
334 duk_push_object(ctx); /* class Object, extensible */
335
336 /* [... constructor arg1 ... argN final_cons fallback] */
337
339 proto = duk_get_hobject(ctx, -1);
340 if (!proto) {
341 DUK_DDD(DUK_DDDPRINT("constructor has no 'prototype' property, or value not an object "
342 "-> leave standard Object prototype as fallback prototype"));
343 } else {
344 DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value "
345 "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto));
346 fallback = duk_get_hobject(ctx, -2);
347 DUK_ASSERT(fallback != NULL);
349 }
350 duk_pop(ctx);
351
352 /* [... constructor arg1 ... argN final_cons fallback] */
353
354 /*
355 * Manipulate callstack for the call.
356 */
357
358 duk_dup_top(ctx);
359 duk_insert(ctx, idx_cons + 1); /* use fallback as 'this' value */
360 duk_insert(ctx, idx_cons); /* also stash it before constructor,
361 * in case we need it (as the fallback value)
362 */
363 duk_pop(ctx); /* pop final_cons */
364
365
366 /* [... fallback constructor fallback(this) arg1 ... argN];
367 * Note: idx_cons points to first 'fallback', not 'constructor'.
368 */
369
370 DUK_DDD(DUK_DDDPRINT("before call, idx_cons+1 (constructor) -> %!T, idx_cons+2 (fallback/this) -> %!T, "
371 "nargs=%ld, top=%ld",
372 (duk_tval *) duk_get_tval(ctx, idx_cons + 1),
373 (duk_tval *) duk_get_tval(ctx, idx_cons + 2),
374 (long) nargs,
375 (long) duk_get_top(ctx)));
376
377 /*
378 * Call the constructor function (called in "constructor mode").
379 */
380
381 call_flags = DUK_CALL_FLAG_CONSTRUCTOR_CALL; /* not protected, respect reclimit, is a constructor call */
382
383 duk_handle_call_unprotected(thr, /* thread */
384 nargs, /* num_stack_args */
385 call_flags); /* call_flags */
386
387 /* [... fallback retval] */
388
389 DUK_DDD(DUK_DDDPRINT("constructor call finished, fallback=%!iT, retval=%!iT",
390 (duk_tval *) duk_get_tval(ctx, -2),
391 (duk_tval *) duk_get_tval(ctx, -1)));
392
393 /*
394 * Determine whether to use the constructor return value as the created
395 * object instance or not.
396 */
397
398 if (duk_is_object(ctx, -1)) {
399 duk_remove(ctx, -2);
400 } else {
401 duk_pop(ctx);
402 }
403
404 /*
405 * Augment created errors upon creation (not when they are thrown or
406 * rethrown). __FILE__ and __LINE__ are not desirable here; the call
407 * stack reflects the caller which is correct.
408 */
409
410#ifdef DUK_USE_AUGMENT_ERROR_CREATE
412 duk_err_augment_error_create(thr, thr, NULL, 0, 1 /*noblame_fileline*/);
413#endif
414
415 /* [... retval] */
416
417 return;
418
419 not_constructable:
421}
const char * proto
Definition civetweb.c:18378
#define DUK_HOBJECT_HAS_BOUND(h)
DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx)
#define DUK_CALL_FLAG_CONSTRUCTOR_CALL
#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h)
DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t index)
#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p)
#define DUK_HOBJECT_IS_CALLABLE(h)
DUK_EXTERNAL void duk_dup_top(duk_context *ctx)
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_STR_NOT_CONSTRUCTABLE
DUK_EXTERNAL duk_bool_t duk_is_object(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_idx_t duk_push_object(duk_context *ctx)
DUK_INTERNAL_DECL void duk_hthread_sync_currpc(duk_hthread *thr)
#define DUK_STRIDX_INT_TARGET
#define DUK_GET_TVAL_NEGIDX(ctx, idx)
DUK_INTERNAL_DECL duk_hobject * duk_get_hobject(duk_context *ctx, duk_idx_t index)
#define duk_is_callable(ctx, index)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_CALL_FLAG_CONSTRUCTOR_CALL, DUK_DDD, DUK_DDDPRINT, duk_dup(), duk_dup_top(), duk_err_augment_error_create(), DUK_ERROR_TYPE, duk_get_hobject(), duk_get_prop_stridx(), duk_get_top(), duk_get_tval(), DUK_GET_TVAL_NEGIDX, duk_handle_call_unprotected(), DUK_HOBJECT_HAS_BOUND, DUK_HOBJECT_HAS_CONSTRUCTABLE, DUK_HOBJECT_IS_CALLABLE, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, duk_hthread_sync_currpc(), duk_insert(), duk_is_callable, duk_is_lightfunc(), duk_is_object(), duk_pop(), duk_push_object(), duk_remove(), duk_require_normalize_index(), DUK_STR_NOT_CONSTRUCTABLE, DUK_STRIDX_INT_TARGET, DUK_STRIDX_PROTOTYPE, DUK_TVAL_GET_OBJECT, DUK_TVAL_IS_LIGHTFUNC, DUK_TVAL_IS_OBJECT, NULL, and proto.

Referenced by duk__pnew_helper().

◆ duk_pcall()

DUK_EXTERNAL duk_int_t duk_pcall ( duk_context * ctx,
duk_idx_t nargs )

Definition at line 103 of file duktape-1.5.2/src-separate/duk_api_call.c.

103 {
104 duk_hthread *thr = (duk_hthread *) ctx;
105 duk_small_uint_t call_flags;
106 duk_idx_t idx_func;
107 duk_int_t rc;
108
110 DUK_ASSERT(thr != NULL);
111
112 idx_func = duk_get_top(ctx) - nargs - 1; /* must work for nargs <= 0 */
113 if (idx_func < 0 || nargs < 0) {
114 /* We can't reliably pop anything here because the stack input
115 * shape is incorrect. So we throw an error; if the caller has
116 * no catch point for this, a fatal error will occur. Another
117 * alternative would be to just return an error. But then the
118 * stack would be in an unknown state which might cause some
119 * very hard to diagnose problems later on. Also note that even
120 * if we did not throw an error here, the underlying call handler
121 * might STILL throw an out-of-memory error or some other internal
122 * fatal error.
123 */
125 return DUK_EXEC_ERROR; /* unreachable */
126 }
127
128 /* awkward; we assume there is space for this */
130 duk_insert(ctx, idx_func + 1);
131
132 call_flags = 0; /* respect reclimit, not constructor */
133
134 rc = duk_handle_call_protected(thr, /* thread */
135 nargs, /* num_stack_args */
136 call_flags); /* call_flags */
137
138 return rc;
139}
DUK_INTERNAL_DECL duk_int_t duk_handle_call_protected(duk_hthread *thr, duk_idx_t num_stack_args, duk_small_uint_t call_flags)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_EXEC_ERROR, duk_get_top(), duk_handle_call_protected(), duk_insert(), duk_push_undefined(), DUK_STR_INVALID_CALL_ARGS, and NULL.

◆ duk_pcall_method()

DUK_EXTERNAL duk_int_t duk_pcall_method ( duk_context * ctx,
duk_idx_t nargs )

Definition at line 141 of file duktape-1.5.2/src-separate/duk_api_call.c.

141 {
142 duk_hthread *thr = (duk_hthread *) ctx;
143 duk_small_uint_t call_flags;
144 duk_idx_t idx_func;
145 duk_int_t rc;
146
148 DUK_ASSERT(thr != NULL);
149
150 idx_func = duk_get_top(ctx) - nargs - 2; /* must work for nargs <= 0 */
151 if (idx_func < 0 || nargs < 0) {
152 /* See comments in duk_pcall(). */
154 return DUK_EXEC_ERROR; /* unreachable */
155 }
156
157 call_flags = 0; /* respect reclimit, not constructor */
158
159 rc = duk_handle_call_protected(thr, /* thread */
160 nargs, /* num_stack_args */
161 call_flags); /* call_flags */
162
163 return rc;
164}

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_EXEC_ERROR, duk_get_top(), duk_handle_call_protected(), DUK_STR_INVALID_CALL_ARGS, and NULL.

◆ duk_pcall_prop()

DUK_EXTERNAL duk_int_t duk_pcall_prop ( duk_context * ctx,
duk_idx_t obj_index,
duk_idx_t nargs )

Definition at line 186 of file duktape-1.5.2/src-separate/duk_api_call.c.

186 {
187 /*
188 * Must be careful to catch errors related to value stack manipulation
189 * and property lookup, not just the call itself.
190 */
191
193
194 duk_push_idx(ctx, obj_index);
195 duk_push_idx(ctx, nargs);
196
197 /* Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
198 * If the value stack does not contain enough args, an error is thrown; this matches
199 * behavior of the other protected call API functions.
200 */
201 return duk_safe_call(ctx, duk__pcall_prop_raw, nargs + 1 + 2 /*nargs*/, 1 /*nrets*/);
202}
#define duk_push_idx(ctx, val)
DUK_LOCAL duk_ret_t duk__pcall_prop_raw(duk_context *ctx)
DUK_EXTERNAL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets)

References duk__pcall_prop_raw(), DUK_ASSERT_CTX_VALID, duk_push_idx, and duk_safe_call().

◆ duk_pnew()

DUK_EXTERNAL duk_int_t duk_pnew ( duk_context * ctx,
duk_idx_t nargs )

Definition at line 433 of file duktape-1.5.2/src-separate/duk_api_call.c.

433 {
434 duk_int_t rc;
435
437
438 /* For now, just use duk_safe_call() to wrap duk_new(). We can't
439 * simply use a protected duk_handle_call() because there's post
440 * processing which might throw. It should be possible to ensure
441 * the post processing never throws (except in internal errors and
442 * out of memory etc which are always allowed) and then remove this
443 * wrapper.
444 */
445
446 duk_push_uint(ctx, nargs);
447 rc = duk_safe_call(ctx, duk__pnew_helper, nargs + 2 /*nargs*/, 1 /*nrets*/);
448 return rc;
449}
DUK_EXTERNAL void duk_push_uint(duk_context *ctx, duk_uint_t val)
DUK_LOCAL duk_ret_t duk__pnew_helper(duk_context *ctx)

References duk__pnew_helper(), DUK_ASSERT_CTX_VALID, duk_push_uint(), and duk_safe_call().

◆ duk_safe_call()

DUK_EXTERNAL duk_int_t duk_safe_call ( duk_context * ctx,
duk_safe_call_function func,
duk_idx_t nargs,
duk_idx_t nrets )

Definition at line 204 of file duktape-1.5.2/src-separate/duk_api_call.c.

204 {
205 duk_hthread *thr = (duk_hthread *) ctx;
206 duk_int_t rc;
207
209 DUK_ASSERT(thr != NULL);
210
211 if (duk_get_top(ctx) < nargs || nrets < 0) {
212 /* See comments in duk_pcall(). */
214 return DUK_EXEC_ERROR; /* unreachable */
215 }
216
217 rc = duk_handle_safe_call(thr, /* thread */
218 func, /* func */
219 nargs, /* num_stack_args */
220 nrets); /* num_stack_res */
221
222 return rc;
223}
DUK_INTERNAL_DECL duk_int_t duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, duk_idx_t num_stack_args, duk_idx_t num_stack_res)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_ERROR_API, DUK_EXEC_ERROR, duk_get_top(), duk_handle_safe_call(), DUK_STR_INVALID_CALL_ARGS, and NULL.

Referenced by duk_pcall_prop(), and duk_pnew().

◆ duk_set_magic()

DUK_EXTERNAL void duk_set_magic ( duk_context * ctx,
duk_idx_t index,
duk_int_t magic )

Definition at line 547 of file duktape-1.5.2/src-separate/duk_api_call.c.

547 {
549
551
553 DUK_ASSERT(nf != NULL);
554 nf->magic = (duk_int16_t) magic;
555}
DUK_INTERNAL_DECL duk_hnativefunction * duk_require_hnativefunction(duk_context *ctx, duk_idx_t index)

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_require_hnativefunction(), index, duk_hnativefunction::magic, and NULL.