| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 //------------------------------------------------------------------- | 55 //------------------------------------------------------------------- |
| 56 | 56 |
| 57 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { | 57 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { |
| 58 CheckSharedIntegerTypedArray(sta); | 58 CheckSharedIntegerTypedArray(sta); |
| 59 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); | 59 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); |
| 60 oldValue = TO_NUMBER(oldValue); | 60 oldValue = TO_NUMBER(oldValue); |
| 61 newValue = TO_NUMBER(newValue); | 61 newValue = TO_NUMBER(newValue); |
| 62 return %_AtomicsCompareExchange(sta, index, oldValue, newValue); | 62 return %_AtomicsCompareExchange(sta, index, oldValue, newValue); |
| 63 } | 63 } |
| 64 | 64 |
| 65 function AtomicsLoadJS(sta, index) { |
| 66 CheckSharedIntegerTypedArray(sta); |
| 67 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); |
| 68 return %_AtomicsLoad(sta, index); |
| 69 } |
| 70 |
| 65 function AtomicsStoreJS(sta, index, value) { | 71 function AtomicsStoreJS(sta, index, value) { |
| 66 CheckSharedIntegerTypedArray(sta); | 72 CheckSharedIntegerTypedArray(sta); |
| 67 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); | 73 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); |
| 68 value = TO_NUMBER(value); | 74 value = TO_NUMBER(value); |
| 69 return %_AtomicsStore(sta, index, value); | 75 return %_AtomicsStore(sta, index, value); |
| 70 } | 76 } |
| 71 | 77 |
| 72 function AtomicsAddJS(ia, index, value) { | 78 function AtomicsAddJS(ia, index, value) { |
| 73 CheckSharedIntegerTypedArray(ia); | 79 CheckSharedIntegerTypedArray(ia); |
| 74 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); | 80 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 index2 = ValidateIndex(index2, %_TypedArrayGetLength(ia)); | 154 index2 = ValidateIndex(index2, %_TypedArrayGetLength(ia)); |
| 149 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || | 155 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || |
| 150 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { | 156 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { |
| 151 return UNDEFINED; | 157 return UNDEFINED; |
| 152 } | 158 } |
| 153 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); | 159 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); |
| 154 } | 160 } |
| 155 | 161 |
| 156 // ------------------------------------------------------------------- | 162 // ------------------------------------------------------------------- |
| 157 | 163 |
| 158 var Atomics = global.Atomics; | 164 function AtomicsConstructor() {} |
| 159 | 165 |
| 160 // The Atomics global is defined by the bootstrapper. | 166 var Atomics = new AtomicsConstructor(); |
| 167 |
| 168 %InternalSetPrototype(Atomics, GlobalObject.prototype); |
| 169 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); |
| 170 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); |
| 161 | 171 |
| 162 %AddNamedProperty(Atomics, toStringTagSymbol, "Atomics", READ_ONLY | DONT_ENUM); | 172 %AddNamedProperty(Atomics, toStringTagSymbol, "Atomics", READ_ONLY | DONT_ENUM); |
| 163 | 173 |
| 164 // These must match the values in src/futex-emulation.h | 174 // These must match the values in src/futex-emulation.h |
| 165 utils.InstallConstants(Atomics, [ | 175 utils.InstallConstants(Atomics, [ |
| 166 "OK", 0, | 176 "OK", 0, |
| 167 "NOTEQUAL", -1, | 177 "NOTEQUAL", -1, |
| 168 "TIMEDOUT", -2, | 178 "TIMEDOUT", -2, |
| 169 ]); | 179 ]); |
| 170 | 180 |
| 171 utils.InstallFunctions(Atomics, DONT_ENUM, [ | 181 utils.InstallFunctions(Atomics, DONT_ENUM, [ |
| 172 // TODO(binji): remove the rest of the (non futex) Atomics functions as they | |
| 173 // become builtins. | |
| 174 "compareExchange", AtomicsCompareExchangeJS, | 182 "compareExchange", AtomicsCompareExchangeJS, |
| 183 "load", AtomicsLoadJS, |
| 175 "store", AtomicsStoreJS, | 184 "store", AtomicsStoreJS, |
| 176 "add", AtomicsAddJS, | 185 "add", AtomicsAddJS, |
| 177 "sub", AtomicsSubJS, | 186 "sub", AtomicsSubJS, |
| 178 "and", AtomicsAndJS, | 187 "and", AtomicsAndJS, |
| 179 "or", AtomicsOrJS, | 188 "or", AtomicsOrJS, |
| 180 "xor", AtomicsXorJS, | 189 "xor", AtomicsXorJS, |
| 181 "exchange", AtomicsExchangeJS, | 190 "exchange", AtomicsExchangeJS, |
| 182 "isLockFree", AtomicsIsLockFreeJS, | 191 "isLockFree", AtomicsIsLockFreeJS, |
| 183 "futexWait", AtomicsFutexWaitJS, | 192 "futexWait", AtomicsFutexWaitJS, |
| 184 "futexWake", AtomicsFutexWakeJS, | 193 "futexWake", AtomicsFutexWakeJS, |
| 185 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, | 194 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, |
| 186 ]); | 195 ]); |
| 187 | 196 |
| 188 }) | 197 }) |
| OLD | NEW |