Backed out changeset 8f976ed899d7 (bug 1847231) for causing bc failures on browser_se...
[gecko.git] / js / src / jsapi-tests / testValueABI.cpp
blob298bd7dd9960433e4eda3c022a10ac01e177d76a
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "js/GlobalObject.h"
6 #include "jsapi-tests/tests.h"
8 /*
9 * Bug 689101 - jsval is technically a non-POD type because it has a private
10 * data member. On gcc, this doesn't seem to matter. On MSVC, this prevents
11 * returning a jsval from a function between C and C++ because it will use a
12 * retparam in C++ and a direct return value in C.
14 * Bug 712289 - jsval alignment was different on 32-bit platforms between C and
15 * C++ because the default alignments of js::Value and jsval_layout differ.
18 extern "C" {
20 extern bool C_ValueToObject(JSContext* cx, jsval v, JSObject** obj);
22 extern jsval C_GetEmptyStringValue(JSContext* cx);
24 extern size_t C_jsvalAlignmentTest();
27 BEGIN_TEST(testValueABI_retparam) {
28 JS::RootedObject obj(cx, JS::CurrentGlobalOrNull(cx));
29 RootedValue v(cx, ObjectValue(*obj));
30 obj = nullptr;
31 CHECK(C_ValueToObject(cx, v, obj.address()));
32 bool equal;
33 RootedValue v2(cx, ObjectValue(*obj));
34 CHECK(JS_StrictlyEqual(cx, v, v2, &equal));
35 CHECK(equal);
37 v = C_GetEmptyStringValue(cx);
38 CHECK(v.isString());
40 return true;
42 END_TEST(testValueABI_retparam)
44 BEGIN_TEST(testValueABI_alignment) {
45 typedef struct {
46 char c;
47 jsval v;
48 } AlignTest;
49 CHECK(C_jsvalAlignmentTest() == sizeof(AlignTest));
51 return true;
53 END_TEST(testValueABI_alignment)