• 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 #ifndef JERRYX_HANDLE_SCOPE_INTERNAL_H
17 #define JERRYX_HANDLE_SCOPE_INTERNAL_H
18 
19 #include "jerryscript.h"
20 #include "jerryscript-port.h"
21 #include "jerryscript-ext/handle-scope.h"
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif /* __cplusplus */
27 
28 #define JERRYX_HANDLE_SCOPE_ASSERT(x) \
29   do \
30   { \
31     if (!(x)) \
32     { \
33       jerry_port_log (JERRY_LOG_LEVEL_ERROR, \
34                       "JerryXHandleScope: Assertion '%s' failed at %s(%s):%lu.\n", \
35                       #x, \
36                       __FILE__, \
37                       __func__, \
38                       (unsigned long) __LINE__); \
39       jerry_port_fatal (ERR_FAILED_INTERNAL_ASSERTION); \
40     } \
41   } while (0)
42 
43 /** MARK: - handle-scope-allocator.c */
44 typedef struct jerryx_handle_scope_pool_s jerryx_handle_scope_pool_t;
45 /**
46  * A linear allocating memory pool for type jerryx_handle_scope_t,
47  * in which allocated item shall be released in reversed order of allocation
48  */
49 struct jerryx_handle_scope_pool_s
50 {
51   jerryx_handle_scope_t prelist[JERRYX_SCOPE_PRELIST_SIZE]; /**< inlined handle scopes in the pool */
52   size_t count; /**< number of handle scopes in the pool */
53   jerryx_handle_scope_dynamic_t *start; /**< start address of dynamically allocated handle scope list */
54 };
55 
56 jerryx_handle_scope_t *
57 jerryx_handle_scope_get_parent (jerryx_handle_scope_t *scope);
58 
59 jerryx_handle_scope_t *
60 jerryx_handle_scope_get_child (jerryx_handle_scope_t *scope);
61 
62 jerryx_handle_scope_t *
63 jerryx_handle_scope_alloc (void);
64 
65 void
66 jerryx_handle_scope_free (jerryx_handle_scope_t *scope);
67 /** MARK: - END handle-scope-allocator.c */
68 
69 /** MARK: - handle-scope.c */
70 void
71 jerryx_handle_scope_release_handles (jerryx_handle_scope scope);
72 
73 jerry_value_t
74 jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t idx);
75 
76 jerry_value_t
77 jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope scope);
78 
79 jerryx_handle_scope_status
80 jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
81                                jerry_value_t escapee,
82                                jerry_value_t *result,
83                                bool should_promote);
84 /** MARK: - END handle-scope.c */
85 
86 #ifdef __cplusplus
87 }
88 #endif /* __cplusplus */
89 #endif /* !JERRYX_HANDLE_SCOPE_INTERNAL_H */
90