Skip to content

Commit d02a4ba

Browse files
ABBAPOHsaghul
authored andcommitted
Add JS_SealObject and JS_FreezeObject methods
1 parent 7021858 commit d02a4ba

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

quickjs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37205,6 +37205,22 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValue this_val,
3720537205
return JS_EXCEPTION;
3720637206
}
3720737207

37208+
int JS_SealObject(JSContext *ctx, JSValue obj)
37209+
{
37210+
JSValue value = js_object_seal(ctx, JS_UNDEFINED, 1, &obj, 0);
37211+
int result = JS_IsException(value) ? -1 : TRUE;
37212+
JS_FreeValue(ctx, value);
37213+
return result;
37214+
}
37215+
37216+
int JS_FreezeObject(JSContext *ctx, JSValue obj)
37217+
{
37218+
JSValue value = js_object_seal(ctx, JS_UNDEFINED, 1, &obj, 1);
37219+
int result = JS_IsException(value) ? -1 : TRUE;
37220+
JS_FreeValue(ctx, value);
37221+
return result;
37222+
}
37223+
3720837224
static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val,
3720937225
int argc, JSValue *argv)
3721037226
{

quickjs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ JS_EXTERN int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val);
712712
JS_EXTERN JSValue JS_GetPrototype(JSContext *ctx, JSValue val);
713713
JS_EXTERN int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres);
714714
JS_EXTERN int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len);
715+
JS_EXTERN int JS_SealObject(JSContext *ctx, JSValue obj);
716+
JS_EXTERN int JS_FreezeObject(JSContext *ctx, JSValue obj);
715717

716718
#define JS_GPN_STRING_MASK (1 << 0)
717719
#define JS_GPN_SYMBOL_MASK (1 << 1)

0 commit comments

Comments
 (0)