Debian Codegraph @

js/src/jsapi-tests/testSameValue.cpp

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 #include "js/Equality.h" // JS::SameValue
9 #include "jsapi-tests/tests.h"
10
11 BEGIN_TEST(testSameValue) {
12 /*
13 * NB: passing a double that fits in an integer jsval is API misuse. As a
14 * matter of defense in depth, however, JS::SameValue should return the
15 * correct result comparing a positive-zero double to a negative-zero
16 * double, and this is believed to be the only way to make such a
17 * comparison possible.
18 */
19 JS::RootedValue v1(cx, JS::DoubleValue(0.0));
20 JS::RootedValue v2(cx, JS::DoubleValue(-0.0));
21 bool same;
22 CHECK(JS::SameValue(cx, v1, v2, &same));
23 CHECK(!same);
24 return true;
25 }
26 END_TEST(testSameValue)