Browse Source

add duk_equals() and duk_strict_equals() API calls

pull/1/head
Sami Vaarala 12 years ago
parent
commit
e147f64f45
  1. 37
      src/duk_api.c
  2. 5
      src/duk_api.h

37
src/duk_api.c

@ -2331,3 +2331,40 @@ void duk_error(duk_context *ctx, int err_code, const char *fmt, ...) {
duk_throw(ctx);
}
int duk_equals(duk_context *ctx, int index1, int index2) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_tval *tv1, *tv2;
tv1 = duk_get_tval(ctx, index1);
if (!tv1) {
return 0;
}
tv2 = duk_get_tval(ctx, index2);
if (!tv2) {
return 0;
}
/* Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
*/
return duk_js_equals(thr, tv1, tv2);
}
int duk_strict_equals(duk_context *ctx, int index1, int index2) {
duk_tval *tv1, *tv2;
tv1 = duk_get_tval(ctx, index1);
if (!tv1) {
return 0;
}
tv2 = duk_get_tval(ctx, index2);
if (!tv2) {
return 0;
}
/* No coercions or other side effects, so safe */
return duk_js_strict_equals(tv1, tv2);
}

5
src/duk_api.h

@ -456,9 +456,10 @@ void duk_trim(duk_context *ctx, int index); /* trim usin
/* FIXME: what to include; there are plenty of operators, arithmetic, comparison, bit ops, etc */
#if 0 /* FIXME: to be decided */
int duk_equals(duk_context *ctx, int index1, int index2); /* true if equals with Ecmascript '==' semantics; false if either index invalid */
int duk_strictly_equals(duk_context *ctx, int index1, int index2); /* true if equals with Ecmascript '===' semantics; false if either index invalid */
int duk_strict_equals(duk_context *ctx, int index1, int index2); /* true if equals with Ecmascript '===' semantics; false if either index invalid */
#if 0 /* FIXME: to be decided */
int duk_less_than(duk_context *ctx, int index1, int index2); /* 'x < y' comparison, E5 Section 11.8.5 */
int duk_same_value(duk_context *ctx, int index1, int index2); /* true with Ecmascript SameValue, E5 Section 9.12 (stricter than '===') */
#endif

Loading…
Cancel
Save