1/* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * Unit test for jerry-ext/handle-scope. 18 */ 19 20#include "jerryscript.h" 21#include "jerryscript-ext/handle-scope.h" 22#include "test-common.h" 23 24static int native_free_cb_call_count; 25 26static void 27native_free_cb (void *native_p) 28{ 29 ++native_free_cb_call_count; 30 (void) native_p; 31} /* native_free_cb */ 32 33static const jerry_object_native_info_t native_info = 34{ 35 .free_cb = native_free_cb, 36}; 37 38static jerry_value_t 39create_object (void) 40{ 41 jerry_value_t obj = jerry_create_object (); 42 jerry_set_object_native_pointer (obj, NULL, &native_info); 43 return obj; 44} /* create_object */ 45 46static void 47test_handle_scope_val (void) 48{ 49 jerryx_handle_scope scope; 50 jerryx_open_handle_scope (&scope); 51 jerry_value_t obj = jerryx_create_handle (create_object ()); 52 (void) obj; 53 jerryx_close_handle_scope (scope); 54} /* test_handle_scope_val */ 55 56int 57main (void) 58{ 59 jerry_init (JERRY_INIT_EMPTY); 60 61 native_free_cb_call_count = 0; 62 test_handle_scope_val (); 63 jerry_gc (JERRY_GC_PRESSURE_LOW); 64 TEST_ASSERT (native_free_cb_call_count == 1); 65 66 jerry_cleanup (); 67} /* main */ 68