tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testValueABI.cpp (1516B)


      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 "js/GlobalObject.h"
      6 #include "jsapi-tests/tests.h"
      7 
      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.
     13 *
     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.
     16 */
     17 
     18 extern "C" {
     19 
     20 extern bool C_ValueToObject(JSContext* cx, jsval v, JSObject** obj);
     21 
     22 extern jsval C_GetEmptyStringValue(JSContext* cx);
     23 
     24 extern size_t C_jsvalAlignmentTest();
     25 }
     26 
     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);
     36 
     37  v = C_GetEmptyStringValue(cx);
     38  CHECK(v.isString());
     39 
     40  return true;
     41 }
     42 END_TEST(testValueABI_retparam)
     43 
     44 BEGIN_TEST(testValueABI_alignment) {
     45  typedef struct {
     46    char c;
     47    jsval v;
     48  } AlignTest;
     49  CHECK(C_jsvalAlignmentTest() == sizeof(AlignTest));
     50 
     51  return true;
     52 }
     53 END_TEST(testValueABI_alignment)