Skip to content

Commit f3f2f42

Browse files
authored
Add JS_StrictEq(), JS_SameValue(), and JS_SameValueZero() (bellard#264)
* add `JS_StrictEq()`, `JS_SameValue()`, and `JS_SameValueZero()` all accepting `JSValueConst` * make `js_strict_eq` accept `JSValueConst`, remove uses of this function internally and replace them with `js_strict_eq2` instead.
1 parent 6f9d05f commit f3f2f42

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

quickjs.c

+22-5
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ typedef enum JSStrictEqModeEnum {
11321132

11331133
static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
11341134
JSStrictEqModeEnum eq_mode);
1135-
static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2);
1135+
static BOOL js_strict_eq(JSContext *ctx, JSValueConst op1, JSValueConst op2);
11361136
static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2);
11371137
static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
11381138
static JSValue JS_ToObject(JSContext *ctx, JSValueConst val);
@@ -14239,7 +14239,7 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,
1423914239
goto exception;
1424014240
}
1424114241
}
14242-
res = js_strict_eq(ctx, op1, op2);
14242+
res = js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT);
1424314243
} else if (tag1 == JS_TAG_BOOL) {
1424414244
op1 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op1));
1424514245
goto redo;
@@ -14557,9 +14557,16 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
1455714557
return res;
1455814558
}
1455914559

14560-
static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2)
14560+
static BOOL js_strict_eq(JSContext *ctx, JSValueConst op1, JSValueConst op2)
14561+
{
14562+
return js_strict_eq2(ctx,
14563+
JS_DupValue(ctx, op1), JS_DupValue(ctx, op2),
14564+
JS_EQ_STRICT);
14565+
}
14566+
14567+
BOOL JS_StrictEq(JSContext *ctx, JSValueConst op1, JSValueConst op2)
1456114568
{
14562-
return js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT);
14569+
return js_strict_eq(ctx, op1, op2);
1456314570
}
1456414571

1456514572
static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2)
@@ -14569,18 +14576,28 @@ static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2)
1456914576
JS_EQ_SAME_VALUE);
1457014577
}
1457114578

14579+
BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2)
14580+
{
14581+
return js_same_value(ctx, op1, op2);
14582+
}
14583+
1457214584
static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2)
1457314585
{
1457414586
return js_strict_eq2(ctx,
1457514587
JS_DupValue(ctx, op1), JS_DupValue(ctx, op2),
1457614588
JS_EQ_SAME_VALUE_ZERO);
1457714589
}
1457814590

14591+
BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2)
14592+
{
14593+
return js_same_value_zero(ctx, op1, op2);
14594+
}
14595+
1457914596
static no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp,
1458014597
BOOL is_neq)
1458114598
{
1458214599
BOOL res;
14583-
res = js_strict_eq(ctx, sp[-2], sp[-1]);
14600+
res = js_strict_eq2(ctx, sp[-2], sp[-1], JS_EQ_STRICT);
1458414601
sp[-2] = JS_NewBool(ctx, res ^ is_neq);
1458514602
return 0;
1458614603
}

quickjs.h

+4
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
684684
return (JSValue)v;
685685
}
686686

687+
JS_BOOL JS_StrictEq(JSContext *ctx, JSValueConst op1, JSValueConst op2);
688+
JS_BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2);
689+
JS_BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
690+
687691
int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
688692
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
689693
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)

0 commit comments

Comments
 (0)