|
| 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 "ecma-atomics-object.h" |
| 17 | +#include "ecma-builtins.h" |
| 18 | +#include "ecma-globals.h" |
| 19 | +#include "ecma-helpers.h" |
| 20 | +#include "jrt.h" |
| 21 | + |
| 22 | +#if JERRY_BUILTIN_ATOMICS |
| 23 | + |
| 24 | +#define ECMA_BUILTINS_INTERNAL |
| 25 | + |
| 26 | +#include "ecma-builtins-internal.h" |
| 27 | + |
| 28 | +/** |
| 29 | + * This object has a custom dispatch function. |
| 30 | + */ |
| 31 | +#define BUILTIN_CUSTOM_DISPATCH |
| 32 | + |
| 33 | +/** |
| 34 | + * List of built-in routine identifiers. |
| 35 | + */ |
| 36 | +enum |
| 37 | +{ |
| 38 | + ECMA_ATOMICS_ROUTINE_START = 0, /**< Special value, should be ignored */ |
| 39 | + ECMA_ATOMICS_ROUTINE_ADD, /**< Atomics add routine */ |
| 40 | + ECMA_ATOMICS_ROUTINE_AND, /**< Atomics and routine */ |
| 41 | + ECMA_ATOMICS_ROUTINE_COMPAREEXCHANGE, /**< Atomics compare exchange routine */ |
| 42 | + ECMA_ATOMICS_ROUTINE_EXCHANGE, /**< Atomics exchange routine */ |
| 43 | + ECMA_ATOMICS_ROUTINE_ISLOCKFREE, /**< Atomics is lock free routine */ |
| 44 | + ECMA_ATOMICS_ROUTINE_LOAD, /**< Atomics load routine */ |
| 45 | + ECMA_ATOMICS_ROUTINE_OR, /**< Atomics or routine */ |
| 46 | + ECMA_ATOMICS_ROUTINE_STORE, /**< Atomics store routine */ |
| 47 | + ECMA_ATOMICS_ROUTINE_SUB, /**< Atomics sub routine */ |
| 48 | + ECMA_ATOMICS_ROUTINE_WAIT, /**< Atomics wait routine */ |
| 49 | + ECMA_ATOMICS_ROUTINE_NOTIFY, /**< Atomics notify routine */ |
| 50 | + ECMA_ATOMICS_ROUTINE_XOR, /**< Atomics xor routine */ |
| 51 | +}; |
| 52 | + |
| 53 | +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-atomics.inc.h" |
| 54 | +#define BUILTIN_UNDERSCORED_ID atomics |
| 55 | + |
| 56 | +#include "ecma-builtin-internal-routines-template.inc.h" |
| 57 | + |
| 58 | +/** \addtogroup ecma ECMA |
| 59 | + * @{ |
| 60 | + * |
| 61 | + * \addtogroup ecmabuiltins |
| 62 | + * @{ |
| 63 | + * |
| 64 | + * \addtogroup atomics ECMA Atomics object built-in |
| 65 | + * @{ |
| 66 | + */ |
| 67 | + |
| 68 | +/** |
| 69 | + * The Atomics object's 'compareExchange' routine |
| 70 | + * |
| 71 | + * See also: ES11 24.4.4 |
| 72 | + * |
| 73 | + * @return ecma value |
| 74 | + * Returned value must be freed with ecma_free_value. |
| 75 | + */ |
| 76 | +static ecma_value_t |
| 77 | +ecma_builtin_atomics_compare_exchange (ecma_value_t typedarray, /**< typedArray argument */ |
| 78 | + ecma_value_t index, /**< index argument */ |
| 79 | + ecma_value_t expected_value, /**< expectedValue argument */ |
| 80 | + ecma_value_t replacement_value) /**< replacementValue argument*/ |
| 81 | +{ |
| 82 | + JERRY_UNUSED (typedarray); |
| 83 | + JERRY_UNUSED (index); |
| 84 | + JERRY_UNUSED (expected_value); |
| 85 | + JERRY_UNUSED (replacement_value); |
| 86 | + |
| 87 | + return ecma_make_uint32_value (0); |
| 88 | +} /* ecma_builtin_atomics_compare_exchange */ |
| 89 | + |
| 90 | +/** |
| 91 | + * The Atomics object's 'isLockFree' routine |
| 92 | + * |
| 93 | + * See also: ES11 24.4.6 |
| 94 | + * |
| 95 | + * @return ecma value |
| 96 | + * Returned value must be freed with ecma_free_value. |
| 97 | + */ |
| 98 | +static ecma_value_t |
| 99 | +ecma_builtin_atomics_is_lock_free (ecma_value_t size) /**< size argument */ |
| 100 | +{ |
| 101 | + JERRY_UNUSED (size); |
| 102 | + |
| 103 | + return ECMA_VALUE_FALSE; |
| 104 | +} /* ecma_builtin_atomics_is_lock_free */ |
| 105 | + |
| 106 | +/** |
| 107 | + * The Atomics object's 'store' routine |
| 108 | + * |
| 109 | + * See also: ES11 24.4.9 |
| 110 | + * |
| 111 | + * @return ecma value |
| 112 | + * Returned value must be freed with ecma_free_value. |
| 113 | + */ |
| 114 | +static ecma_value_t |
| 115 | +ecma_builtin_atomics_store (ecma_value_t typedarray, /**< typedArray argument */ |
| 116 | + ecma_value_t index, /**< index argument */ |
| 117 | + ecma_value_t value) /**< value argument */ |
| 118 | +{ |
| 119 | + JERRY_UNUSED (typedarray); |
| 120 | + JERRY_UNUSED (index); |
| 121 | + JERRY_UNUSED (value); |
| 122 | + |
| 123 | + return ecma_make_uint32_value (0); |
| 124 | +} /* ecma_builtin_atomics_store */ |
| 125 | + |
| 126 | +/** |
| 127 | + * The Atomics object's 'wait' routine |
| 128 | + * |
| 129 | + * See also: ES11 24.4.11 |
| 130 | + * |
| 131 | + * @return ecma value |
| 132 | + * Returned value must be freed with ecma_free_value. |
| 133 | + */ |
| 134 | +static ecma_value_t |
| 135 | +ecma_builtin_atomics_wait (ecma_value_t typedarray, /**< typedArray argument */ |
| 136 | + ecma_value_t index, /**< index argument */ |
| 137 | + ecma_value_t value, /**< value argument */ |
| 138 | + ecma_value_t timeout) /**< timeout argument */ |
| 139 | +{ |
| 140 | + JERRY_UNUSED (typedarray); |
| 141 | + JERRY_UNUSED (index); |
| 142 | + JERRY_UNUSED (value); |
| 143 | + JERRY_UNUSED (timeout); |
| 144 | + |
| 145 | + return ecma_make_uint32_value (0); |
| 146 | +} /* ecma_builtin_atomics_wait */ |
| 147 | + |
| 148 | +/** |
| 149 | + * The Atomics object's 'notify' routine |
| 150 | + * |
| 151 | + * See also: ES11 24.4.12 |
| 152 | + * |
| 153 | + * @return ecma value |
| 154 | + * Returned value must be freed with ecma_free_value. |
| 155 | + */ |
| 156 | +static ecma_value_t |
| 157 | +ecma_builtin_atomics_notify (ecma_value_t typedarray, /**< typedArray argument */ |
| 158 | + ecma_value_t index, /**< index argument */ |
| 159 | + ecma_value_t count) /**< count argument */ |
| 160 | +{ |
| 161 | + JERRY_UNUSED (typedarray); |
| 162 | + JERRY_UNUSED (index); |
| 163 | + JERRY_UNUSED (count); |
| 164 | + |
| 165 | + return ecma_make_uint32_value (0); |
| 166 | +} /* ecma_builtin_atomics_notify */ |
| 167 | + |
| 168 | +/** |
| 169 | + * Dispatcher of the built-in's routines |
| 170 | + * |
| 171 | + * @return ecma value |
| 172 | + * Returned value must be freed with ecma_free_value. |
| 173 | + */ |
| 174 | +ecma_value_t |
| 175 | +ecma_builtin_atomics_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ |
| 176 | + ecma_value_t this_arg, /**< 'this' argument value */ |
| 177 | + const ecma_value_t arguments_list_p[], /**< list of arguments |
| 178 | + * passed to routine */ |
| 179 | + uint32_t arguments_number) /**< length of arguments' list */ |
| 180 | +{ |
| 181 | + JERRY_UNUSED (this_arg); |
| 182 | + ecma_value_t arg1 = arguments_list_p[0]; |
| 183 | + ecma_value_t arg2 = arguments_list_p[1]; |
| 184 | + ecma_value_t arg3 = arguments_list_p[2]; |
| 185 | + ecma_value_t arg4 = (arguments_number > 3) ? arguments_list_p[3] : ECMA_VALUE_UNDEFINED; |
| 186 | + |
| 187 | + ecma_atomics_op_t type; |
| 188 | + |
| 189 | + switch (builtin_routine_id) |
| 190 | + { |
| 191 | + case ECMA_ATOMICS_ROUTINE_ADD: |
| 192 | + { |
| 193 | + type = ECMA_ATOMICS_ADD; |
| 194 | + break; |
| 195 | + } |
| 196 | + case ECMA_ATOMICS_ROUTINE_AND: |
| 197 | + { |
| 198 | + type = ECMA_ATOMICS_AND; |
| 199 | + break; |
| 200 | + } |
| 201 | + case ECMA_ATOMICS_ROUTINE_COMPAREEXCHANGE: |
| 202 | + { |
| 203 | + return ecma_builtin_atomics_compare_exchange (arg1, arg2, arg3, arg4); |
| 204 | + } |
| 205 | + case ECMA_ATOMICS_ROUTINE_EXCHANGE: |
| 206 | + { |
| 207 | + type = ECMA_ATOMICS_EXCHANGE; |
| 208 | + break; |
| 209 | + } |
| 210 | + case ECMA_ATOMICS_ROUTINE_ISLOCKFREE: |
| 211 | + { |
| 212 | + return ecma_builtin_atomics_is_lock_free (arg1); |
| 213 | + } |
| 214 | + case ECMA_ATOMICS_ROUTINE_LOAD: |
| 215 | + { |
| 216 | + return ecma_atomic_load (arg1, arg2); |
| 217 | + } |
| 218 | + case ECMA_ATOMICS_ROUTINE_OR: |
| 219 | + { |
| 220 | + type = ECMA_ATOMICS_OR; |
| 221 | + break; |
| 222 | + } |
| 223 | + case ECMA_ATOMICS_ROUTINE_STORE: |
| 224 | + { |
| 225 | + return ecma_builtin_atomics_store (arg1, arg2, arg3); |
| 226 | + } |
| 227 | + case ECMA_ATOMICS_ROUTINE_SUB: |
| 228 | + { |
| 229 | + type = ECMA_ATOMICS_SUBTRACT; |
| 230 | + break; |
| 231 | + } |
| 232 | + case ECMA_ATOMICS_ROUTINE_WAIT: |
| 233 | + { |
| 234 | + return ecma_builtin_atomics_wait (arg1, arg2, arg3, arg4); |
| 235 | + } |
| 236 | + case ECMA_ATOMICS_ROUTINE_NOTIFY: |
| 237 | + { |
| 238 | + return ecma_builtin_atomics_notify (arg1, arg2, arg3); |
| 239 | + } |
| 240 | + case ECMA_ATOMICS_ROUTINE_XOR: |
| 241 | + { |
| 242 | + type = ECMA_ATOMICS_XOR; |
| 243 | + break; |
| 244 | + } |
| 245 | + default: |
| 246 | + { |
| 247 | + JERRY_UNREACHABLE (); |
| 248 | + } |
| 249 | + } |
| 250 | + return ecma_atomic_read_modify_write (arg1, arg2, arg3, type); |
| 251 | +} /* ecma_builtin_atomics_dispatch_routine */ |
| 252 | + |
| 253 | +/** |
| 254 | + * @} |
| 255 | + * @} |
| 256 | + * @} |
| 257 | + */ |
| 258 | + |
| 259 | +#endif /* JERRY_BUILTIN_ATOMICS */ |
0 commit comments