Skip to content

Commit fe5be3c

Browse files
andrjohnssaghul
authored andcommitted
Add JS_SetLength API function
1 parent 6ce2dcc commit fe5be3c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

quickjs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ static __exception int js_get_length32(JSContext *ctx, uint32_t *pres,
12441244
JSValue obj);
12451245
static __exception int js_get_length64(JSContext *ctx, int64_t *pres,
12461246
JSValue obj);
1247+
static __exception int js_set_length64(JSContext *ctx, JSValue obj,
1248+
int64_t len);
12471249
static void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len);
12481250
static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,
12491251
JSValue array_arg);
@@ -7092,6 +7094,10 @@ int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres) {
70927094
return js_get_length64(ctx, pres, obj);
70937095
}
70947096

7097+
int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len) {
7098+
return js_set_length64(ctx, obj, len);
7099+
}
7100+
70957101
/* return TRUE, FALSE or (-1) in case of exception */
70967102
static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValue val,
70977103
JSValue obj)
@@ -37118,6 +37124,15 @@ static __exception int js_get_length64(JSContext *ctx, int64_t *pres,
3711837124
return JS_ToLengthFree(ctx, pres, len_val);
3711937125
}
3712037126

37127+
static __exception int js_set_length64(JSContext *ctx, JSValue obj, int64_t len)
37128+
{
37129+
JSValue len_val;
37130+
len_val = JS_NewInt64(ctx, len);
37131+
if (JS_IsException(len_val))
37132+
return -1;
37133+
return JS_SetProperty(ctx, obj, JS_ATOM_length, len_val);
37134+
}
37135+
3712137136
static void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len)
3712237137
{
3712337138
uint32_t i;

quickjs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ JS_EXTERN int JS_DeleteProperty(JSContext *ctx, JSValue obj, JSAtom prop, int fl
699699
JS_EXTERN int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val);
700700
JS_EXTERN JSValue JS_GetPrototype(JSContext *ctx, JSValue val);
701701
JS_EXTERN int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres);
702+
JS_EXTERN int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len);
702703

703704
#define JS_GPN_STRING_MASK (1 << 0)
704705
#define JS_GPN_SYMBOL_MASK (1 << 1)

0 commit comments

Comments
 (0)