Skip to content

Commit 813f0c1

Browse files
committed
webassembly/objjsproxy: Implement equality for JsProxy objects.
Signed-off-by: Damien George <[email protected]>
1 parent 241ee16 commit 813f0c1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ports/webassembly/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
5555
#define MICROPY_USE_INTERNAL_ERRNO (1)
5656
#define MICROPY_USE_INTERNAL_PRINTF (0)
57+
#define MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK (1)
5758

5859
#define MICROPY_EPOCH_IS_1970 (1)
5960
#define MICROPY_PY_ASYNCIO_TASK_QUEUE_PUSH_CALLBACK (1)

ports/webassembly/objjsproxy.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@ static mp_obj_t jsproxy_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
266266
}
267267
}
268268

269+
static mp_obj_t jsproxy_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
270+
if (!mp_obj_is_type(rhs_in, &mp_type_jsproxy)) {
271+
return MP_OBJ_NULL; // op not supported
272+
}
273+
274+
mp_obj_jsproxy_t *lhs = MP_OBJ_TO_PTR(lhs_in);
275+
mp_obj_jsproxy_t *rhs = MP_OBJ_TO_PTR(rhs_in);
276+
277+
switch (op) {
278+
case MP_BINARY_OP_EQUAL:
279+
return mp_obj_new_bool(lhs->ref == rhs->ref);
280+
281+
default:
282+
return MP_OBJ_NULL; // op not supported
283+
}
284+
}
285+
269286
EM_JS(void, proxy_js_free_obj, (int js_ref), {
270287
if (js_ref >= PROXY_JS_REF_NUM_STATIC) {
271288
proxy_js_ref[js_ref] = undefined;
@@ -566,6 +583,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
566583
MP_TYPE_FLAG_ITER_IS_GETITER,
567584
print, jsproxy_print,
568585
call, jsproxy_call,
586+
binary_op, jsproxy_binary_op,
569587
attr, mp_obj_jsproxy_attr,
570588
subscr, jsproxy_subscr,
571589
iter, jsproxy_getiter

0 commit comments

Comments
 (0)