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 "jcontext.h" 17 18 /** \addtogroup context Context 19 * @{ 20 */ 21 22 /** 23 * Check the existence of the ECMA_STATUS_EXCEPTION flag. 24 * 25 * @return true - if the flag is set 26 * false - otherwise 27 */ 28 extern inline bool JERRY_ATTR_ALWAYS_INLINE jcontext_has_pending_exception(void)29jcontext_has_pending_exception (void) 30 { 31 return JERRY_CONTEXT (status_flags) & ECMA_STATUS_EXCEPTION; 32 } /* jcontext_has_pending_exception */ 33 34 /** 35 * Check the existence of the ECMA_STATUS_ABORT flag. 36 * 37 * @return true - if the flag is set 38 * false - otherwise 39 */ 40 extern inline bool JERRY_ATTR_ALWAYS_INLINE jcontext_has_pending_abort(void)41jcontext_has_pending_abort (void) 42 { 43 return JERRY_CONTEXT (status_flags) & ECMA_STATUS_ABORT; 44 } /* jcontext_has_pending_abort */ 45 46 /** 47 * Set the abort flag for the context. 48 */ 49 extern inline void JERRY_ATTR_ALWAYS_INLINE jcontext_set_abort_flag(bool is_abort)50jcontext_set_abort_flag (bool is_abort) /**< true - if the abort flag should be set 51 * false - if the abort flag should be removed */ 52 { 53 JERRY_ASSERT (jcontext_has_pending_exception ()); 54 55 if (is_abort) 56 { 57 JERRY_CONTEXT (status_flags) |= ECMA_STATUS_ABORT; 58 } 59 else 60 { 61 JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_ABORT; 62 } 63 } /* jcontext_set_abort_flag */ 64 65 /** 66 * Set the exception flag for the context. 67 */ 68 extern inline void JERRY_ATTR_ALWAYS_INLINE jcontext_set_exception_flag(bool is_exception)69jcontext_set_exception_flag (bool is_exception) /**< true - if the exception flag should be set 70 * false - if the exception flag should be removed */ 71 { 72 if (is_exception) 73 { 74 JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION; 75 } 76 else 77 { 78 JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_EXCEPTION; 79 } 80 } /* jcontext_set_exception_flag */ 81 82 /** 83 * Raise exception from the given error value. 84 */ 85 extern inline void JERRY_ATTR_ALWAYS_INLINE jcontext_raise_exception(ecma_value_t error)86jcontext_raise_exception (ecma_value_t error) /**< error to raise */ 87 { 88 JERRY_ASSERT (!jcontext_has_pending_exception ()); 89 JERRY_ASSERT (!jcontext_has_pending_abort ()); 90 91 JERRY_CONTEXT (error_value) = error; 92 jcontext_set_exception_flag (true); 93 } /* jcontext_raise_exception */ 94 95 /** 96 * Release the current exception/abort of the context. 97 */ 98 void jcontext_release_exception(void)99jcontext_release_exception (void) 100 { 101 JERRY_ASSERT (jcontext_has_pending_exception ()); 102 103 ecma_free_value (jcontext_take_exception ()); 104 } /* jcontext_release_exception */ 105 106 /** 107 * Take the current exception/abort of context. 108 * 109 * @return current exception as an ecma-value 110 */ 111 ecma_value_t jcontext_take_exception(void)112jcontext_take_exception (void) 113 { 114 JERRY_ASSERT (jcontext_has_pending_exception ()); 115 116 jcontext_set_abort_flag (false); 117 jcontext_set_exception_flag (false); 118 return JERRY_CONTEXT (error_value); 119 } /* jcontext_take_exception */ 120 121 #if !ENABLED (JERRY_EXTERNAL_CONTEXT) 122 123 /** 124 * Global context. 125 */ 126 jerry_context_t jerry_global_context; 127 128 #if !ENABLED (JERRY_SYSTEM_ALLOCATOR) 129 130 /** 131 * Check size of heap is corresponding to configuration 132 */ 133 JERRY_STATIC_ASSERT (sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE, 134 size_of_mem_heap_must_be_less_than_or_equal_to_JMEM_HEAP_SIZE); 135 136 /** 137 * Global heap. 138 */ 139 #ifdef JERRY_FOR_IAR_CONFIG // ACELite changes, align heap by 8bytes for IAR 140 #pragma data_alignment = JMEM_ALIGNMENT 141 jmem_heap_t jerry_global_heap JERRY_ATTR_GLOBAL_HEAP; 142 #else 143 jmem_heap_t jerry_global_heap JERRY_ATTR_ALIGNED (JMEM_ALIGNMENT) JERRY_ATTR_GLOBAL_HEAP; 144 #endif 145 146 #endif /* !ENABLED (JERRY_SYSTEM_ALLOCATOR) */ 147 148 #else /* ENABLED (JERRY_EXTERNAL_CONTEXT) */ 149 jerry_context_t *jerry_dynamic_global_context_p = NULL; 150 #endif /* !ENABLED (JERRY_EXTERNAL_CONTEXT) */ 151 152 /** 153 * @} 154 */ 155