From 738e6a9d276426034a4f1055eb3759aa0ec8a4f8 Mon Sep 17 00:00:00 2001 From: Samir Date: Sun, 20 Sep 2026 17:18:51 -0400 Subject: [PATCH 1/2] Return false instead of error with undefined receiver in Reflect.set --- quickjs.c | 7 +++++++ tests/bug1730.js | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 tests/bug1730.js diff --git a/quickjs.c b/quickjs.c index 6ca030b9f..cc9ec6e30 100644 --- a/quickjs.c +++ b/quickjs.c @@ -10556,9 +10556,15 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst obj, JSAtom prop switch(JS_VALUE_GET_TAG(this_obj)) { case JS_TAG_NULL: + if (JS_IsObject(obj)) { + goto primitive_receiver; + } JS_ThrowTypeErrorAtom(ctx, "cannot set property '%s' of null", prop); goto fail; case JS_TAG_UNDEFINED: + if (JS_IsObject(obj)) { + goto primitive_receiver; + } JS_ThrowTypeErrorAtom(ctx, "cannot set property '%s' of undefined", prop); goto fail; case JS_TAG_OBJECT: @@ -10568,6 +10574,7 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst obj, JSAtom prop break; goto retry2; default: + primitive_receiver: if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) obj = JS_GetPrototypePrimitive(ctx, obj); p = NULL; diff --git a/tests/bug1730.js b/tests/bug1730.js new file mode 100644 index 000000000..a81e3c485 --- /dev/null +++ b/tests/bug1730.js @@ -0,0 +1,5 @@ +import { assert } from "./assert.js"; + +assert(Reflect.set({ set x(v) {} }, "x", 1, null), true); +assert(Reflect.set({}, "x", 1, undefined), false); +assert(Reflect.set({}, "x", 1, null), false); \ No newline at end of file From 7ad9bba8904f85be3bb56dec36bea4e6ac85f986 Mon Sep 17 00:00:00 2001 From: Samir Rangwalla Date: Fri, 2 Oct 2026 16:12:19 -0400 Subject: [PATCH 2/2] Move primitive_receiver label down to avoid redundant if statement --- quickjs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index cc9ec6e30..fb1ed674e 100644 --- a/quickjs.c +++ b/quickjs.c @@ -10574,9 +10574,10 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst obj, JSAtom prop break; goto retry2; default: - primitive_receiver: if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) obj = JS_GetPrototypePrimitive(ctx, obj); + + primitive_receiver: p = NULL; p1 = JS_VALUE_GET_OBJ(obj); goto prototype_lookup;