• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
native_cb2(void)21 static void native_cb2 (void)
22 {
23   jerry_value_t array = jerry_create_array (100);
24   jerry_release_value (array);
25 } /* native_cb2 */
26 
27 static const jerry_object_native_info_t native_info2 =
28 {
29   .free_cb = (jerry_object_native_free_callback_t) native_cb2
30 };
31 
native_cb(void)32 static void native_cb (void)
33 {
34   jerry_value_t array = jerry_create_array (100);
35 
36   jerry_set_object_native_pointer (array, NULL, &native_info2);
37 
38   jerry_release_value (array);
39 } /* native_cb */
40 
41 static const jerry_object_native_info_t native_info =
42 {
43   .free_cb = (jerry_object_native_free_callback_t) native_cb
44 };
45 
46 static void *
context_alloc_fn(size_t size,void * cb_data)47 context_alloc_fn (size_t size, void *cb_data)
48 {
49   (void) cb_data;
50   return malloc (size);
51 } /* context_alloc_fn */
52 
53 int
main(void)54 main (void)
55 {
56   jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
57   jerry_port_default_set_current_context (ctx_p);
58   jerry_init (JERRY_INIT_EMPTY);
59 
60   jerry_value_t obj = jerry_create_object ();
61 
62   jerry_set_object_native_pointer (obj, NULL, &native_info);
63   jerry_release_value (obj);
64 
65   jerry_cleanup ();
66   free (ctx_p);
67   return 0;
68 } /* main */
69