Skip to content

Accept 'null' for duk_set_prototype() #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src-input/duk_api_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,11 @@ DUK_EXTERNAL void duk_get_prototype(duk_context *ctx, duk_idx_t idx) {
obj = duk_require_hobject(ctx, idx);
DUK_ASSERT(obj != NULL);

/* XXX: shared helper for duk_push_hobject_or_undefined()? */
proto = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, obj);
if (proto) {
duk_push_hobject(ctx, proto);
} else {
duk_push_undefined(ctx);
duk_push_null(ctx);
}
}

Expand All @@ -643,7 +642,8 @@ DUK_EXTERNAL void duk_set_prototype(duk_context *ctx, duk_idx_t idx) {

obj = duk_require_hobject(ctx, idx);
DUK_ASSERT(obj != NULL);
duk_require_type_mask(ctx, -1, DUK_TYPE_MASK_UNDEFINED |
duk_require_type_mask(ctx, -1, DUK_TYPE_MASK_UNDEFINED | /* FIXME: don't accept undefined anymore? */
DUK_TYPE_MASK_NULL |
DUK_TYPE_MASK_OBJECT);
proto = duk_get_hobject(ctx, -1);
/* proto can also be NULL here (allowed explicitly) */
Expand Down
6 changes: 3 additions & 3 deletions website/api/duk_set_prototype.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ stack: |

summary: |
<p>Set the internal prototype of the value at <code>idx</code> to the value
at stack top (which must be an object or <code>undefined</code>). If the
target value is not an object or the prototype value is not an object or
<code>undefined</code>, an error is thrown.</p>
at stack top If the target value is not an object or the prototype value is
not an object, <code>undefined</code>, or <code>null</code>, an error is
thrown.</p>

<div class="note">
Unlike Ecmascript prototype manipulation primitives, this API call allows
Expand Down