Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duktape-1.5.2/src-separate/duk_api_var.c
Go to the documentation of this file.
1/*
2 * Variable access
3 */
4
5#include "duk_internal.h"
6
8 duk_hthread *thr = (duk_hthread *) ctx;
10 duk_hstring *h_varname;
11 duk_small_int_t throw_flag = 1; /* always throw ReferenceError for unresolvable */
12
14
15 h_varname = duk_require_hstring(ctx, -1); /* XXX: tostring? */
16 DUK_ASSERT(h_varname != NULL);
17
19 if (act) {
20 (void) duk_js_getvar_activation(thr, act, h_varname, throw_flag); /* -> [ ... varname val this ] */
21 } else {
22 /* Outside any activation -> look up from global. */
24 (void) duk_js_getvar_envrec(thr, thr->builtins[DUK_BIDX_GLOBAL_ENV], h_varname, throw_flag);
25 }
26
27 /* [ ... varname val this ] (because throw_flag == 1, always resolved) */
28
29 duk_pop(ctx);
30 duk_remove(ctx, -2);
31
32 /* [ ... val ] */
33
34 /* Return value would be pointless: because throw_flag==1, we always
35 * throw if the identifier doesn't resolve.
36 */
37 return;
38}
39
41 duk_hthread *thr = (duk_hthread *) ctx;
42 duk_activation *act;
43 duk_hstring *h_varname;
44 duk_tval *tv_val;
45 duk_small_int_t throw_flag;
46
48
49 h_varname = duk_require_hstring(ctx, -2); /* XXX: tostring? */
50 DUK_ASSERT(h_varname != NULL);
51
52 tv_val = duk_require_tval(ctx, -1);
53
54 throw_flag = duk_is_strict_call(ctx);
55
57 if (act) {
58 duk_js_putvar_activation(thr, act, h_varname, tv_val, throw_flag); /* -> [ ... varname val this ] */
59 } else {
60 /* Outside any activation -> put to global. */
62 duk_js_putvar_envrec(thr, thr->builtins[DUK_BIDX_GLOBAL_ENV], h_varname, tv_val, throw_flag);
63 }
64
65 /* [ ... varname val ] */
66
67 duk_pop_2(ctx);
68
69 /* [ ... ] */
70
71 return;
72}
73
80
duk_small_int_t duk_bool_t
DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag)
#define DUK_ASSERT_CTX_VALID(ctx)
DUK_EXTERNAL void duk_pop_2(duk_context *ctx)
DUK_EXTERNAL duk_bool_t duk_is_strict_call(duk_context *ctx)
DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict)
DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict)
DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t index)
#define DUK_ERROR_UNIMPLEMENTED_DEFMSG(thr)
DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag)
DUK_INTERNAL_DECL duk_tval * duk_require_tval(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL void duk_pop(duk_context *ctx)
DUK_INTERNAL_DECL duk_hstring * duk_require_hstring(duk_context *ctx, duk_idx_t index)
DUK_INTERNAL_DECL duk_activation * duk_hthread_get_current_activation(duk_hthread *thr)
DUK_EXTERNAL duk_bool_t duk_del_var(duk_context *ctx)
DUK_EXTERNAL void duk_get_var(duk_context *ctx)
DUK_EXTERNAL void duk_put_var(duk_context *ctx)
DUK_EXTERNAL duk_bool_t duk_has_var(duk_context *ctx)
#define NULL
Definition gmacros.h:924
duk_hobject * builtins[DUK_NUM_BUILTINS]