|
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/. */ |
|
4 |
|
5 #include "jsapi-tests/tests.h" |
|
6 |
|
7 /* |
|
8 * Bug 689101 - jsval is technically a non-POD type because it has a private |
|
9 * data member. On gcc, this doesn't seem to matter. On MSVC, this prevents |
|
10 * returning a jsval from a function between C and C++ because it will use a |
|
11 * retparam in C++ and a direct return value in C. |
|
12 * |
|
13 * Bug 712289 - jsval alignment was different on 32-bit platforms between C and |
|
14 * C++ because the default alignments of js::Value and jsval_layout differ. |
|
15 */ |
|
16 |
|
17 extern "C" { |
|
18 |
|
19 extern bool |
|
20 C_ValueToObject(JSContext *cx, jsval v, JSObject **obj); |
|
21 |
|
22 extern jsval |
|
23 C_GetEmptyStringValue(JSContext *cx); |
|
24 |
|
25 extern size_t |
|
26 C_jsvalAlignmentTest(); |
|
27 |
|
28 } |
|
29 |
|
30 BEGIN_TEST(testValueABI_retparam) |
|
31 { |
|
32 JS::RootedObject obj(cx, JS::CurrentGlobalOrNull(cx)); |
|
33 jsval v = OBJECT_TO_JSVAL(obj); |
|
34 obj = nullptr; |
|
35 CHECK(C_ValueToObject(cx, v, obj.address())); |
|
36 bool equal; |
|
37 CHECK(JS_StrictlyEqual(cx, v, OBJECT_TO_JSVAL(obj), &equal)); |
|
38 CHECK(equal); |
|
39 |
|
40 v = C_GetEmptyStringValue(cx); |
|
41 CHECK(JSVAL_IS_STRING(v)); |
|
42 |
|
43 return true; |
|
44 } |
|
45 END_TEST(testValueABI_retparam) |
|
46 |
|
47 BEGIN_TEST(testValueABI_alignment) |
|
48 { |
|
49 typedef struct { char c; jsval v; } AlignTest; |
|
50 CHECK(C_jsvalAlignmentTest() == sizeof(AlignTest)); |
|
51 |
|
52 return true; |
|
53 } |
|
54 END_TEST(testValueABI_alignment) |