Skip to content

Commit bf6cb94

Browse files
committed
Add JS_SealObject and JS_FreezeObject methods
1 parent a236c4c commit bf6cb94

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
@@ -37208,6 +37208,22 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValue this_val,
3720837208
return JS_EXCEPTION;
3720937209
}
3721037210

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

quickjs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ JS_EXTERN int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val);
705705
JS_EXTERN JSValue JS_GetPrototype(JSContext *ctx, JSValue val);
706706
JS_EXTERN int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres);
707707
JS_EXTERN int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len);
708+
JS_EXTERN int JS_SealObject(JSContext *ctx, JSValue obj);
709+
JS_EXTERN int JS_FreezeObject(JSContext *ctx, JSValue obj);
708710

709711
#define JS_GPN_STRING_MASK (1 << 0)
710712
#define JS_GPN_SYMBOL_MASK (1 << 1)

0 commit comments

Comments
 (0)