Skip to content

Expose public equality comparison and sameness public API. #373

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 3 commits into from
Apr 16, 2024
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
24 changes: 24 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -51816,6 +51816,30 @@ void JS_AddPerformance(JSContext *ctx)
JS_FreeValue(ctx, performance);
}

/* Equality comparisons and sameness */
int JS_IsEqual(JSContext *ctx, JSValue op1, JSValue op2)
{
JSValue sp[2] = { js_dup(op1), js_dup(op2) };
if (js_eq_slow(ctx, endof(sp), 0))
return -1;
return JS_VALUE_GET_BOOL(sp[0]);
}

JS_BOOL JS_IsStrictEqual(JSContext *ctx, JSValue op1, JSValue op2)
{
return js_strict_eq2(ctx, js_dup(op1), js_dup(op2), JS_EQ_STRICT);
}

JS_BOOL JS_IsSameValue(JSContext *ctx, JSValue op1, JSValue op2)
{
return js_same_value(ctx, op1, op2);
}

JS_BOOL JS_IsSameValueZero(JSContext *ctx, JSValue op1, JSValue op2)
{
return js_same_value_zero(ctx, op1, op2);
}

/* WeakRef */

typedef struct JSWeakRefData {
Expand Down
7 changes: 7 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ JS_EXTERN void JS_AddIntrinsicBigInt(JSContext *ctx);
JS_EXTERN void JS_AddIntrinsicWeakRef(JSContext *ctx);
JS_EXTERN void JS_AddPerformance(JSContext *ctx);

/* for equality comparisons and sameness */
JS_EXTERN int JS_IsEqual(JSContext *ctx, JSValue op1, JSValue op2);
JS_EXTERN JS_BOOL JS_IsStrictEqual(JSContext *ctx, JSValue op1, JSValue op2);
JS_EXTERN JS_BOOL JS_IsSameValue(JSContext *ctx, JSValue op1, JSValue op2);
/* Similar to same-value equality, but +0 and -0 are considered equal. */
JS_EXTERN JS_BOOL JS_IsSameValueZero(JSContext *ctx, JSValue op1, JSValue op2);

/* Only used for running 262 tests. TODO(saghul) add build time flag. */
JS_EXTERN JSValue js_string_codePointRange(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv);
Expand Down