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 #include "jerryscript.h"
17 #include "jerryscript-port.h"
18 #include "jerryscript-port-default.h"
19 #include "test-common.h"
20 #include <gtest/gtest.h>
21
native_cb2(void)22 static void native_cb2 (void)
23 {
24 jerry_value_t array = jerry_create_array (100);
25 jerry_release_value (array);
26 } /* native_cb2 */
27
28 static const jerry_object_native_info_t native_info2 =
29 {
30 .free_cb = (jerry_object_native_free_callback_t) native_cb2
31 };
32
native_cb(void)33 static void native_cb (void)
34 {
35 jerry_value_t array = jerry_create_array (100);
36
37 jerry_set_object_native_pointer (array, NULL, &native_info2);
38
39 jerry_release_value (array);
40 } /* native_cb */
41
42 static const jerry_object_native_info_t native_info =
43 {
44 .free_cb = (jerry_object_native_free_callback_t) native_cb
45 };
46
47 static void *
context_alloc_fn(size_t size,void * cb_data)48 context_alloc_fn (size_t size, void *cb_data)
49 {
50 (void) cb_data;
51 return malloc (size);
52 } /* context_alloc_fn */
53
54 class NativeCallbackNestedTest : public testing::Test{
55 public:
SetUpTestCase()56 static void SetUpTestCase()
57 {
58 GTEST_LOG_(INFO) << "NativeCallbackNestedTest SetUpTestCase";
59 }
60
TearDownTestCase()61 static void TearDownTestCase()
62 {
63 GTEST_LOG_(INFO) << "NativeCallbackNestedTest TearDownTestCase";
64 }
65
SetUp()66 void SetUp() override {}
TearDown()67 void TearDown() override {}
68
69 };
70 HWTEST_F(NativeCallbackNestedTest, Test001, testing::ext::TestSize.Level1)
71 {
72 jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
73 jerry_port_default_set_current_context (ctx_p);
74 jerry_init (JERRY_INIT_EMPTY);
75
76 jerry_value_t obj = jerry_create_object ();
77
78 jerry_set_object_native_pointer (obj, NULL, &native_info);
79 jerry_release_value (obj);
80
81 jerry_cleanup ();
82 free (ctx_p);
83 }
84