diff --git a/quickjs.c b/quickjs.c index 6ca030b9f..fb1ed674e 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: @@ -10570,6 +10576,8 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst obj, JSAtom prop default: 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; 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