Skip to content

Add JS_SealObject and JS_FreezeObject methods #819

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

Merged
merged 1 commit into from
Jan 14, 2025
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
16 changes: 16 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37208,6 +37208,22 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}

int JS_SealObject(JSContext *ctx, JSValue obj)
{
JSValue value = js_object_seal(ctx, JS_UNDEFINED, 1, &obj, 0);
int result = JS_IsException(value) ? -1 : TRUE;
JS_FreeValue(ctx, value);
return result;
}

int JS_FreezeObject(JSContext *ctx, JSValue obj)
{
JSValue value = js_object_seal(ctx, JS_UNDEFINED, 1, &obj, 1);
int result = JS_IsException(value) ? -1 : TRUE;
JS_FreeValue(ctx, value);
return result;
}

static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv)
{
Expand Down
2 changes: 2 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ JS_EXTERN int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val);
JS_EXTERN JSValue JS_GetPrototype(JSContext *ctx, JSValue val);
JS_EXTERN int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres);
JS_EXTERN int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len);
JS_EXTERN int JS_SealObject(JSContext *ctx, JSValue obj);
JS_EXTERN int JS_FreezeObject(JSContext *ctx, JSValue obj);

#define JS_GPN_STRING_MASK (1 << 0)
#define JS_GPN_SYMBOL_MASK (1 << 1)
Expand Down
Loading