js/src/jsapi-tests/testValueABI.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 "jsapi-tests/tests.h"
     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  */
    17 extern "C" {
    19 extern bool
    20 C_ValueToObject(JSContext *cx, jsval v, JSObject **obj);
    22 extern jsval
    23 C_GetEmptyStringValue(JSContext *cx);
    25 extern size_t
    26 C_jsvalAlignmentTest();
    28 }
    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);
    40     v = C_GetEmptyStringValue(cx);
    41     CHECK(JSVAL_IS_STRING(v));
    43     return true;
    44 }
    45 END_TEST(testValueABI_retparam)
    47 BEGIN_TEST(testValueABI_alignment)
    48 {
    49     typedef struct { char c; jsval v; } AlignTest;
    50     CHECK(C_jsvalAlignmentTest() == sizeof(AlignTest));
    52     return true;
    53 }
    54 END_TEST(testValueABI_alignment)

mercurial