<commit_before>/*
 *  Proxy built-in (ES6 draft)
 */

#include "duk_internal.h"

#if defined(DUK_USE_ES6_PROXY)
duk_ret_t duk_bi_proxy_constructor(duk_context *ctx) {

	if (!duk_is_constructor_call(ctx)) {
		return DUK_RET_TYPE_ERROR;
	}
	(void) duk_require_hobject(ctx, 0);
	(void) duk_require_hobject(ctx, 1);

	/* XXX: the returned value is exotic in ES6 (draft), but we use a
	 * simple object here with no prototype.
	 */
	(void) duk_push_object_helper_proto(ctx,
	                                    DUK_HOBJECT_FLAG_SPECIAL_PROXYOBJ |
	                                    DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),  /* FIXME: class? */
	                                    NULL);

	/* XXX: no callable check/handling now */
	/* XXX: with no prototype, [[DefaultValue]] coercion will fail, which is confusing */

	DUK_ASSERT_TOP(ctx, 3);

	/* Proxy target */
	duk_dup(ctx, 0);
	duk_def_prop_stridx(ctx, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_WC);

	/* Proxy handler */
	duk_dup(ctx, 1);
	duk_def_prop_stridx(ctx, -2, DUK_STRIDX_INT_HANDLER, DUK_PROPDESC_FLAGS_WC);

	return 1;
}
#else  /* DUK_UES_ES6_PROXY */
duk_ret_t duk_bi_proxy_constructor(duk_context *ctx) {
	DUK_UNREF(ctx);
	return DUK_RET_UNSUPPORTED_ERROR;
}
#endif  /* DUK_USE_ES6_PROXY */

#if defined(DUK_USE_ES6_PROXY)
duk_ret_t duk_bi_proxy_constructor_revocable(duk_context *ctx) {
	DUK_UNREF(ctx);
	return DUK_RET_UNIMPLEMENTED_ERROR;  /*FIXME*/
}
#else  /* DUK_UES_ES6_PROXY */
duk_ret_t duk_bi_proxy_constructor_revocable(duk_context *ctx) {
	DUK_UNREF(ctx);
	return DUK_RET_UNSUPPORTED_ERROR;
}
#endif  /* DUK_USE_ES6_PROXY */
<commit_msg>reject proxy objects as a proxy's handler/target object for sanity<commit_after>/*
 *  Proxy built-in (ES6 draft)
 */

#include "duk_internal.h"

#if defined(DUK_USE_ES6_PROXY)
duk_ret_t duk_bi_proxy_constructor(duk_context *ctx) {
	duk_hobject *h_target;
	duk_hobject *h_handler;

	if (!duk_is_constructor_call(ctx)) {
		return DUK_RET_TYPE_ERROR;
	}

	/* Reject a proxy object as the target because it would need
	 * special handler in property lookups.  (ES6 has no such restriction)
	 */
	h_target = duk_require_hobject(ctx, 0);
	DUK_ASSERT(h_target != NULL);
	if (DUK_HOBJECT_HAS_SPECIAL_PROXYOBJ(h_target)) {
		return DUK_RET_TYPE_ERROR;
	}

	/* Reject a proxy object as the handler because it would cause
	 * potentially unbounded recursion.  (ES6 has no such restriction)
	 */
	h_handler = duk_require_hobject(ctx, 1);
	DUK_ASSERT(h_handler != NULL);
	if (DUK_HOBJECT_HAS_SPECIAL_PROXYOBJ(h_handler)) {
		return DUK_RET_TYPE_ERROR;
	}

	/* XXX: the returned value is exotic in ES6 (draft), but we use a
	 * simple object here with no prototype.
	 */
	(void) duk_push_object_helper_proto(ctx,
	                                    DUK_HOBJECT_FLAG_SPECIAL_PROXYOBJ |
	                                    DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),  /* FIXME: class? */
	                                    NULL);

	/* XXX: no callable check/handling now */
	/* XXX: with no prototype, [[DefaultValue]] coercion will fail, which is confusing */

	DUK_ASSERT_TOP(ctx, 3);

	/* Proxy target */
	duk_dup(ctx, 0);
	duk_def_prop_stridx(ctx, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_WC);

	/* Proxy handler */
	duk_dup(ctx, 1);
	duk_def_prop_stridx(ctx, -2, DUK_STRIDX_INT_HANDLER, DUK_PROPDESC_FLAGS_WC);

	return 1;
}
#else  /* DUK_UES_ES6_PROXY */
duk_ret_t duk_bi_proxy_constructor(duk_context *ctx) {
	DUK_UNREF(ctx);
	return DUK_RET_UNSUPPORTED_ERROR;
}
#endif  /* DUK_USE_ES6_PROXY */

#if defined(DUK_USE_ES6_PROXY)
duk_ret_t duk_bi_proxy_constructor_revocable(duk_context *ctx) {
	DUK_UNREF(ctx);
	return DUK_RET_UNIMPLEMENTED_ERROR;  /*FIXME*/
}
#else  /* DUK_UES_ES6_PROXY */
duk_ret_t duk_bi_proxy_constructor_revocable(duk_context *ctx) {
	DUK_UNREF(ctx);
	return DUK_RET_UNSUPPORTED_ERROR;
}
#endif  /* DUK_USE_ES6_PROXY */

{'fraction_non_alphanumeric': 0.10141570141570141, 'fraction_numerical': 0.008751608751608752, 'mean_word_length': 3.962962962962963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5130442', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1547, 'n_words': 291}