]> git.proxmox.com Git - ceph.git/blame - ceph/src/civetweb/src/third_party/duktape-1.5.2/src-separate/duk_hobject_misc.c
buildsys: switch source download to quincy
[ceph.git] / ceph / src / civetweb / src / third_party / duktape-1.5.2 / src-separate / duk_hobject_misc.c
CommitLineData
7c673cae
FG
1/*
2 * Misc support functions
3 */
4
5#include "duk_internal.h"
6
7DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop) {
8 duk_uint_t sanity;
9
10 DUK_ASSERT(thr != NULL);
11fdf7f2
TL
11
12 /* False if the object is NULL or the prototype 'p' is NULL.
13 * In particular, false if both are NULL (don't compare equal).
14 */
15 if (h == NULL || p == NULL) {
16 return 0;
17 }
7c673cae
FG
18
19 sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY;
20 do {
21 if (h == p) {
22 return 1;
23 }
24
25 if (sanity-- == 0) {
26 if (ignore_loop) {
27 break;
28 } else {
11fdf7f2 29 DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT);
7c673cae
FG
30 }
31 }
32 h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
33 } while (h);
34
35 return 0;
36}
37
11fdf7f2 38DUK_INTERNAL void duk_hobject_set_prototype_updref(duk_hthread *thr, duk_hobject *h, duk_hobject *p) {
7c673cae
FG
39#ifdef DUK_USE_REFERENCE_COUNTING
40 duk_hobject *tmp;
41
42 DUK_ASSERT(h);
43 tmp = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
44 DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p);
45 DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */
46 DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp);
47#else
48 DUK_ASSERT(h);
49 DUK_UNREF(thr);
50 DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p);
51#endif
52}