diff --git a/quickjs.c b/quickjs.c index bcb962a..e1ec8c3 100644 --- a/quickjs.c +++ b/quickjs.c @@ -6859,6 +6859,13 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValue obj, sh = p->shape; if (sh->proto == proto) return TRUE; + if (p == JS_VALUE_GET_OBJ(ctx->class_proto[JS_CLASS_OBJECT])) { + if (throw_flag) { + JS_ThrowTypeError(ctx, "'Immutable prototype object \'Object.prototype\' cannot have their prototype set'"); + return -1; + } + return FALSE; + } if (!p->extensible) { if (throw_flag) { JS_ThrowTypeError(ctx, "object is not extensible"); diff --git a/tests/test_builtin.js b/tests/test_builtin.js index 98faa74..5420951 100644 --- a/tests/test_builtin.js +++ b/tests/test_builtin.js @@ -220,6 +220,8 @@ function test() assert(Object.isExtensible(a), false, "extensible"); assert(typeof a.y, "undefined", "extensible"); assert(err, true, "extensible"); + + assert_throws(TypeError, () => Object.setPrototypeOf(Object.prototype, {})); } function test_enum()