testObjectWithStashedPointer.cpp (1224B)
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/ObjectWithStashedPointer.h" 6 #include "jsapi-tests/tests.h" 7 8 static void alter_value(int* valuePtr) { *valuePtr = 33; } 9 10 BEGIN_TEST(testObjectWithStashedPointer_basic) { 11 int value = 55; 12 13 JSObject* obj = JS::NewObjectWithStashedPointer(cx, &value, alter_value); 14 CHECK(obj); 15 16 { 17 JS::RootedObject rooted{cx, obj}; 18 JS_GC(cx); 19 CHECK_EQUAL(value, 55); 20 } 21 22 JS_GC(cx); 23 CHECK_EQUAL(value, 33); 24 return true; 25 } 26 END_TEST(testObjectWithStashedPointer_basic) 27 28 BEGIN_TEST(testObjectWithStashedPointer_noFreeFunc) { 29 int value = 55; 30 31 JSObject* obj = JS::NewObjectWithStashedPointer(cx, &value); 32 CHECK(obj); 33 34 CHECK_EQUAL(*JS::ObjectGetStashedPointer<int>(cx, obj), 55); 35 return true; 36 } 37 END_TEST(testObjectWithStashedPointer_noFreeFunc) 38 39 BEGIN_TEST(testObjectWithStashedPointer_null) { 40 JSObject* obj = JS::NewObjectWithStashedPointer<void>(cx, nullptr); 41 CHECK(obj); 42 43 CHECK_NULL(JS::ObjectGetStashedPointer<void>(cx, obj)); 44 return true; 45 } 46 END_TEST(testObjectWithStashedPointer_null)