| 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 | 
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- | 
| 12 // Imports | 12 // Imports | 
| 13 | 13 | 
| 14 var GlobalObject = global.Object; | 14 var GlobalObject = global.Object; | 
| 15 | 15 | 
|  | 16 var MathMax; | 
|  | 17 | 
|  | 18 utils.Import(function(from) { | 
|  | 19   MathMax = from.MathMax; | 
|  | 20 }); | 
|  | 21 | 
| 16 // ------------------------------------------------------------------- | 22 // ------------------------------------------------------------------- | 
| 17 | 23 | 
| 18 | 24 | 
| 19 function CheckSharedTypedArray(sta) { | 25 function CheckSharedTypedArray(sta) { | 
| 20   if (!%_IsSharedTypedArray(sta)) { | 26   if (!%IsSharedTypedArray(sta)) { | 
| 21     throw MakeTypeError(kNotSharedTypedArray, sta); | 27     throw MakeTypeError(kNotSharedTypedArray, sta); | 
| 22   } | 28   } | 
| 23 } | 29 } | 
| 24 | 30 | 
| 25 function CheckSharedIntegerTypedArray(ia) { | 31 function CheckSharedIntegerTypedArray(ia) { | 
| 26   if (!%_IsSharedIntegerTypedArray(ia)) { | 32   if (!%IsSharedIntegerTypedArray(ia)) { | 
| 27     throw MakeTypeError(kNotIntegerSharedTypedArray, ia); | 33     throw MakeTypeError(kNotIntegerSharedTypedArray, ia); | 
| 28   } | 34   } | 
| 29 } | 35 } | 
| 30 | 36 | 
|  | 37 function CheckSharedInteger32TypedArray(ia) { | 
|  | 38   CheckSharedIntegerTypedArray(ia); | 
|  | 39   if (%_ClassOf(ia) !== 'Int32Array') { | 
|  | 40     throw MakeTypeError(kNotInt32SharedTypedArray, ia); | 
|  | 41   } | 
|  | 42 } | 
|  | 43 | 
| 31 //------------------------------------------------------------------- | 44 //------------------------------------------------------------------- | 
| 32 | 45 | 
| 33 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { | 46 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { | 
| 34   CheckSharedTypedArray(sta); | 47   CheckSharedTypedArray(sta); | 
| 35   index = $toInteger(index); | 48   index = $toInteger(index); | 
| 36   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { | 49   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { | 
| 37     return UNDEFINED; | 50     return UNDEFINED; | 
| 38   } | 51   } | 
| 39   oldValue = $toNumber(oldValue); | 52   oldValue = $toNumber(oldValue); | 
| 40   newValue = $toNumber(newValue); | 53   newValue = $toNumber(newValue); | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 117     return UNDEFINED; | 130     return UNDEFINED; | 
| 118   } | 131   } | 
| 119   value = $toNumber(value); | 132   value = $toNumber(value); | 
| 120   return %_AtomicsExchange(ia, index, value); | 133   return %_AtomicsExchange(ia, index, value); | 
| 121 } | 134 } | 
| 122 | 135 | 
| 123 function AtomicsIsLockFreeJS(size) { | 136 function AtomicsIsLockFreeJS(size) { | 
| 124   return %_AtomicsIsLockFree(size); | 137   return %_AtomicsIsLockFree(size); | 
| 125 } | 138 } | 
| 126 | 139 | 
|  | 140 // Futexes | 
|  | 141 | 
|  | 142 function AtomicsFutexWaitJS(ia, index, value, timeout) { | 
|  | 143   CheckSharedInteger32TypedArray(ia); | 
|  | 144   index = $toInteger(index); | 
|  | 145   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|  | 146     return UNDEFINED; | 
|  | 147   } | 
|  | 148   if (IS_UNDEFINED(timeout)) { | 
|  | 149     timeout = INFINITY; | 
|  | 150   } else { | 
|  | 151     timeout = $toNumber(timeout); | 
|  | 152     if (NUMBER_IS_NAN(timeout)) { | 
|  | 153       timeout = INFINITY; | 
|  | 154     } else { | 
|  | 155       timeout = MathMax(0, timeout); | 
|  | 156     } | 
|  | 157   } | 
|  | 158   return %AtomicsFutexWait(ia, index, value, timeout); | 
|  | 159 } | 
|  | 160 | 
|  | 161 function AtomicsFutexWakeJS(ia, index, count) { | 
|  | 162   CheckSharedInteger32TypedArray(ia); | 
|  | 163   index = $toInteger(index); | 
|  | 164   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|  | 165     return UNDEFINED; | 
|  | 166   } | 
|  | 167   count = MathMax(0, $toInteger(count)); | 
|  | 168   return %AtomicsFutexWake(ia, index, count); | 
|  | 169 } | 
|  | 170 | 
|  | 171 function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) { | 
|  | 172   CheckSharedInteger32TypedArray(ia); | 
|  | 173   index1 = $toInteger(index1); | 
|  | 174   count = MathMax(0, $toInteger(count)); | 
|  | 175   value = $toInt32(value); | 
|  | 176   index2 = $toInteger(index2); | 
|  | 177   if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || | 
|  | 178       index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { | 
|  | 179     return UNDEFINED; | 
|  | 180   } | 
|  | 181   return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); | 
|  | 182 } | 
|  | 183 | 
| 127 // ------------------------------------------------------------------- | 184 // ------------------------------------------------------------------- | 
| 128 | 185 | 
| 129 function AtomicsConstructor() {} | 186 function AtomicsConstructor() {} | 
| 130 | 187 | 
| 131 var Atomics = new AtomicsConstructor(); | 188 var Atomics = new AtomicsConstructor(); | 
| 132 | 189 | 
| 133 %InternalSetPrototype(Atomics, GlobalObject.prototype); | 190 %InternalSetPrototype(Atomics, GlobalObject.prototype); | 
| 134 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); | 191 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); | 
| 135 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); | 192 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); | 
| 136 | 193 | 
| 137 %AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM); | 194 %AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM); | 
| 138 | 195 | 
|  | 196 // These must match the values in src/futex-emulation.h | 
|  | 197 utils.InstallConstants(Atomics, [ | 
|  | 198   "OK", 0, | 
|  | 199   "NOTEQUAL", -1, | 
|  | 200   "TIMEDOUT", -2, | 
|  | 201 ]); | 
|  | 202 | 
| 139 utils.InstallFunctions(Atomics, DONT_ENUM, [ | 203 utils.InstallFunctions(Atomics, DONT_ENUM, [ | 
| 140   "compareExchange", AtomicsCompareExchangeJS, | 204   "compareExchange", AtomicsCompareExchangeJS, | 
| 141   "load", AtomicsLoadJS, | 205   "load", AtomicsLoadJS, | 
| 142   "store", AtomicsStoreJS, | 206   "store", AtomicsStoreJS, | 
| 143   "add", AtomicsAddJS, | 207   "add", AtomicsAddJS, | 
| 144   "sub", AtomicsSubJS, | 208   "sub", AtomicsSubJS, | 
| 145   "and", AtomicsAndJS, | 209   "and", AtomicsAndJS, | 
| 146   "or", AtomicsOrJS, | 210   "or", AtomicsOrJS, | 
| 147   "xor", AtomicsXorJS, | 211   "xor", AtomicsXorJS, | 
| 148   "exchange", AtomicsExchangeJS, | 212   "exchange", AtomicsExchangeJS, | 
| 149   "isLockFree", AtomicsIsLockFreeJS, | 213   "isLockFree", AtomicsIsLockFreeJS, | 
|  | 214   "futexWait", AtomicsFutexWaitJS, | 
|  | 215   "futexWake", AtomicsFutexWakeJS, | 
|  | 216   "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, | 
| 150 ]); | 217 ]); | 
| 151 | 218 | 
| 152 }) | 219 }) | 
| OLD | NEW | 
|---|