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 | |
71 function AtomicsStoreJS(sta, index, value) { | 65 function AtomicsStoreJS(sta, index, value) { |
72 CheckSharedIntegerTypedArray(sta); | 66 CheckSharedIntegerTypedArray(sta); |
73 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); | 67 index = ValidateIndex(index, %_TypedArrayGetLength(sta)); |
74 value = TO_NUMBER(value); | 68 value = TO_NUMBER(value); |
75 return %_AtomicsStore(sta, index, value); | 69 return %_AtomicsStore(sta, index, value); |
76 } | 70 } |
77 | 71 |
78 function AtomicsAddJS(ia, index, value) { | 72 function AtomicsAddJS(ia, index, value) { |
79 CheckSharedIntegerTypedArray(ia); | 73 CheckSharedIntegerTypedArray(ia); |
80 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); | 74 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 index2 = ValidateIndex(index2, %_TypedArrayGetLength(ia)); | 148 index2 = ValidateIndex(index2, %_TypedArrayGetLength(ia)); |
155 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || | 149 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || |
156 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { | 150 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { |
157 return UNDEFINED; | 151 return UNDEFINED; |
158 } | 152 } |
159 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); | 153 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); |
160 } | 154 } |
161 | 155 |
162 // ------------------------------------------------------------------- | 156 // ------------------------------------------------------------------- |
163 | 157 |
164 function AtomicsConstructor() {} | 158 var Atomics = global.Atomics; |
165 | 159 |
166 var Atomics = new AtomicsConstructor(); | 160 // The Atomics global is defined by the bootstrapper. |
167 | |
168 %InternalSetPrototype(Atomics, GlobalObject.prototype); | |
169 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); | |
170 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); | |
171 | 161 |
172 %AddNamedProperty(Atomics, toStringTagSymbol, "Atomics", READ_ONLY | DONT_ENUM); | 162 %AddNamedProperty(Atomics, toStringTagSymbol, "Atomics", READ_ONLY | DONT_ENUM); |
173 | 163 |
174 // These must match the values in src/futex-emulation.h | 164 // These must match the values in src/futex-emulation.h |
175 utils.InstallConstants(Atomics, [ | 165 utils.InstallConstants(Atomics, [ |
176 "OK", 0, | 166 "OK", 0, |
177 "NOTEQUAL", -1, | 167 "NOTEQUAL", -1, |
178 "TIMEDOUT", -2, | 168 "TIMEDOUT", -2, |
179 ]); | 169 ]); |
180 | 170 |
181 utils.InstallFunctions(Atomics, DONT_ENUM, [ | 171 utils.InstallFunctions(Atomics, DONT_ENUM, [ |
| 172 // TODO(binji): remove the rest of the (non futex) Atomics functions as they |
| 173 // become builtins. |
182 "compareExchange", AtomicsCompareExchangeJS, | 174 "compareExchange", AtomicsCompareExchangeJS, |
183 "load", AtomicsLoadJS, | |
184 "store", AtomicsStoreJS, | 175 "store", AtomicsStoreJS, |
185 "add", AtomicsAddJS, | 176 "add", AtomicsAddJS, |
186 "sub", AtomicsSubJS, | 177 "sub", AtomicsSubJS, |
187 "and", AtomicsAndJS, | 178 "and", AtomicsAndJS, |
188 "or", AtomicsOrJS, | 179 "or", AtomicsOrJS, |
189 "xor", AtomicsXorJS, | 180 "xor", AtomicsXorJS, |
190 "exchange", AtomicsExchangeJS, | 181 "exchange", AtomicsExchangeJS, |
191 "isLockFree", AtomicsIsLockFreeJS, | 182 "isLockFree", AtomicsIsLockFreeJS, |
192 "futexWait", AtomicsFutexWaitJS, | 183 "futexWait", AtomicsFutexWaitJS, |
193 "futexWake", AtomicsFutexWakeJS, | 184 "futexWake", AtomicsFutexWakeJS, |
194 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, | 185 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, |
195 ]); | 186 ]); |
196 | 187 |
197 }) | 188 }) |
OLD | NEW |