Skip to content

Commit

Permalink
Merge pull request #1680 from svaarala/add-push-proxy-flags
Browse files Browse the repository at this point in the history
Add an unused flags field to duk_push_proxy()
  • Loading branch information
svaarala authored Aug 15, 2017
2 parents 9b1ef4d + a14d99e commit b09722c
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion RELEASES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ Planned
* Add duk_is_constructable() API call (GH-1523)

* Add duk_push_proxy() API call which allows a Proxy to be created from C
code (GH-1500, GH-837)
code (GH-1500, GH-837, GH-1680)

* Add DUK_HIDDEN_SYMBOL(), DUK_GLOBAL_SYMBOL(), DUK_LOCAL_SYMBOL(), and
DUK_WELLKNOWN_SYMBOL() macros for creating symbol literals (GH-1673)
Expand Down
6 changes: 4 additions & 2 deletions src-input/duk_api_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -5224,14 +5224,15 @@ DUK_INTERNAL void *duk_push_fixed_buffer_zero(duk_hthread *thr, duk_size_t len)
}

#if defined(DUK_USE_ES6_PROXY)
DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr) {
DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) {
duk_hobject *h_target;
duk_hobject *h_handler;
duk_hproxy *h_proxy;
duk_tval *tv_slot;
duk_uint_t flags;

DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(proxy_flags);

/* DUK__CHECK_SPACE() unnecessary because the Proxy is written to
* value stack in-place.
Expand Down Expand Up @@ -5316,8 +5317,9 @@ DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr) {
DUK_ERROR_TYPE_INVALID_ARGS(thr);
}
#else /* DUK_USE_ES6_PROXY */
DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr) {
DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) {
DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(proxy_flags);
DUK_ERROR_UNSUPPORTED(thr);
}
#endif /* DUK_USE_ES6_PROXY */
Expand Down
2 changes: 1 addition & 1 deletion src-input/duk_bi_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_hthread *thr) {
DUK_ASSERT_TOP(thr, 2); /* [ target handler ] */

duk_require_constructor_call(thr);
duk_push_proxy(thr); /* [ target handler ] -> [ proxy ] */
duk_push_proxy(thr, 0 /*flags*/); /* [ target handler ] -> [ proxy ] */
return 1; /* replacement */
}
#endif /* DUK_USE_ES6_PROXY */
2 changes: 1 addition & 1 deletion src-input/duktape.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ DUK_EXTERNAL_DECL duk_idx_t duk_push_array(duk_context *ctx);
DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
DUK_EXTERNAL_DECL 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_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags);
DUK_EXTERNAL_DECL duk_idx_t duk_push_proxy(duk_context *ctx);
DUK_EXTERNAL_DECL duk_idx_t duk_push_proxy(duk_context *ctx, duk_uint_t proxy_flags);

#define duk_push_thread(ctx) \
duk_push_thread_raw((ctx), 0 /*flags*/)
Expand Down
1 change: 1 addition & 0 deletions tests/api/test-all-public-symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ static duk_ret_t test_func(duk_context *ctx, void *udata) {
(void) duk_push_number(ctx, 0.0);
(void) duk_push_object(ctx);
(void) duk_push_pointer(ctx, NULL);
(void) duk_push_proxy(ctx, 0);
(void) duk_push_sprintf(ctx, "dummy");
(void) duk_push_string(ctx, "dummy");
(void) duk_push_this(ctx);
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test-proxy-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static duk_ret_t test_passthrough(duk_context *ctx, void *udata) {
duk_push_c_function(ctx, my_function, 1 /*nargs*/); /* target */
duk_push_object(ctx); /* handler */

duk_push_proxy(ctx);
duk_push_proxy(ctx, 0);

duk_push_uint(ctx, 123);
duk_call(ctx, 1);
Expand All @@ -53,7 +53,7 @@ static duk_ret_t test_trap(duk_context *ctx, void *udata) {
duk_push_c_function(ctx, my_apply_trap, 3 /*nargs*/);
duk_put_prop_string(ctx, -2, "apply");

duk_push_proxy(ctx);
duk_push_proxy(ctx, 0);

duk_push_uint(ctx, 123);
duk_call(ctx, 1);
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test-proxy-construct.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static duk_ret_t test_passthrough(duk_context *ctx, void *udata) {
duk_push_c_function(ctx, my_constructor, 1 /*nargs*/); /* target */
duk_push_object(ctx); /* handler */

duk_push_proxy(ctx);
duk_push_proxy(ctx, 0);

duk_push_uint(ctx, 123);
duk_new(ctx, 1 /*nargs*/);
Expand All @@ -54,7 +54,7 @@ static duk_ret_t test_trap(duk_context *ctx, void *udata) {
duk_push_c_function(ctx, my_construct_trap, 3 /*nargs*/);
duk_put_prop_string(ctx, -2, "construct");

duk_push_proxy(ctx);
duk_push_proxy(ctx, 0);

duk_push_uint(ctx, 123);
duk_new(ctx, 1 /*nargs*/);
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test-push-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static duk_ret_t test_basic(duk_context *ctx, void *udata) {
duk_eval_string(ctx, "({ foo: 123 })");
duk_eval_string(ctx, "({ get: function myget() { return 321; } })");
printf("top before: %ld\n", (long) duk_get_top(ctx));
ret = duk_push_proxy(ctx);
ret = duk_push_proxy(ctx, 0);
printf("top after: %ld\n", (long) duk_get_top(ctx));
printf("duk_push_proxy() returned %ld\n", (long) ret);

Expand Down
8 changes: 5 additions & 3 deletions website/api/duk_push_proxy.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: duk_push_proxy

proto: |
duk_idx_t duk_push_proxy(duk_context *ctx);
duk_idx_t duk_push_proxy(duk_context *ctx, duk_uint_t proxy_flags);
stack: |
[ ... target! handler! ] -> [ ... proxy! ]
summary: |
<p>Push a new Proxy object for target and handler table given on the value
stack, equivalent to <code>new Proxy(target, handler)</code>.</p>
stack, equivalent to <code>new Proxy(target, handler)</code>. The
<code>proxy_flags</code> argument is currently (Duktape 2.2) unused, calling
code must pass in a zero.</p>
example: |
duk_idx_t proxy_idx;
Expand All @@ -17,7 +19,7 @@ example: |
duk_push_object(ctx); /* handler */
duk_push_c_function(ctx, my_get, 3); /* 'get' trap */
duk_put_prop_string(ctx, -2, "get");
proxy_idx = duk_push_proxy(ctx); /* [ target handler ] -> [ proxy ] */
proxy_idx = duk_push_proxy(ctx, 0); /* [ target handler ] -> [ proxy ] */
tags:
- stack
Expand Down

0 comments on commit b09722c

Please sign in to comment.