|
| 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 | +#include "jerryscript.h" |
| 18 | +#include "jerryscript-port.h" |
| 19 | +#include "jerryscript-port-default.h" |
| 20 | +#include "test-common.h" |
| 21 | + |
| 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 | + |
| 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 * |
| 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 | +int |
| 55 | +main (void) |
| 56 | +{ |
| 57 | + jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL); |
| 58 | + jerry_port_default_set_current_context (ctx_p); |
| 59 | + jerry_init (JERRY_INIT_EMPTY); |
| 60 | + |
| 61 | + jerry_value_t obj = jerry_create_object (); |
| 62 | + |
| 63 | + jerry_set_object_native_pointer (obj, NULL, &native_info); |
| 64 | + jerry_release_value (obj); |
| 65 | + |
| 66 | + jerry_cleanup (); |
| 67 | + free (ctx_p); |
| 68 | + return 0; |
| 69 | +} /* main */ |
0 commit comments