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
24extern "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 */
44typedef 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 */
49struct 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
56jerryx_handle_scope_t *
57jerryx_handle_scope_get_parent (jerryx_handle_scope_t *scope);
58
59jerryx_handle_scope_t *
60jerryx_handle_scope_get_child (jerryx_handle_scope_t *scope);
61
62jerryx_handle_scope_t *
63jerryx_handle_scope_alloc (void);
64
65void
66jerryx_handle_scope_free (jerryx_handle_scope_t *scope);
67/** MARK: - END handle-scope-allocator.c */
68
69/** MARK: - handle-scope.c */
70void
71jerryx_handle_scope_release_handles (jerryx_handle_scope scope);
72
73jerry_value_t
74jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t idx);
75
76jerry_value_t
77jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope scope);
78
79jerryx_handle_scope_status
80jerryx_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