Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down