Chromium Code Reviews| 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 >= sta.length) { | 49 if (index < 0 || index >= sta.length) { |
| 37 return UNDEFINED; | 50 return UNDEFINED; |
| 38 } | 51 } |
| 39 return %_AtomicsCompareExchange(sta, index, oldValue, newValue); | 52 return %_AtomicsCompareExchange(sta, index, oldValue, newValue); |
| 40 } | 53 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 if (index < 0 || index >= ia.length) { | 121 if (index < 0 || index >= ia.length) { |
| 109 return UNDEFINED; | 122 return UNDEFINED; |
| 110 } | 123 } |
| 111 return %_AtomicsExchange(ia, index, value); | 124 return %_AtomicsExchange(ia, index, value); |
| 112 } | 125 } |
| 113 | 126 |
| 114 function AtomicsIsLockFreeJS(size) { | 127 function AtomicsIsLockFreeJS(size) { |
| 115 return %_AtomicsIsLockFree(size); | 128 return %_AtomicsIsLockFree(size); |
| 116 } | 129 } |
| 117 | 130 |
| 131 // Futexes | |
| 132 | |
| 133 function AtomicsFutexWaitJS(ia, index, value, timeout) { | |
| 134 CheckSharedInteger32TypedArray(ia); | |
| 135 index = $toInteger(index); | |
| 136 if (index < 0 || index >= ia.length) { | |
| 137 return UNDEFINED; | |
| 138 } | |
| 139 if (IS_UNDEFINED(timeout)) { | |
| 140 timeout = INFINITY; | |
| 141 } else { | |
| 142 timeout = $toNumber(timeout); | |
| 143 if (NUMBER_IS_NAN(timeout)) { | |
| 144 timeout = INFINITY; | |
| 145 } else { | |
| 146 timeout = MathMax(0, timeout); | |
| 147 } | |
| 148 } | |
| 149 return %_AtomicsFutexWait(ia, index, value, timeout); | |
|
Michael Starzinger
2015/07/08 17:54:20
The %_FooBar syntax is used to indicate that at le
binji
2015/07/08 18:05:29
Done.
| |
| 150 } | |
| 151 | |
| 152 function AtomicsFutexWakeJS(ia, index, count) { | |
| 153 CheckSharedInteger32TypedArray(ia); | |
| 154 index = $toInteger(index); | |
| 155 if (index < 0 || index >= ia.length) { | |
| 156 return UNDEFINED; | |
| 157 } | |
| 158 count = MathMax(0, $toInteger(count)); | |
| 159 return %_AtomicsFutexWake(ia, index, count); | |
| 160 } | |
| 161 | |
| 162 function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) { | |
| 163 CheckSharedInteger32TypedArray(ia); | |
| 164 index1 = $toInteger(index1); | |
| 165 count = MathMax(0, $toInteger(count)); | |
| 166 value = $toInt32(value); | |
| 167 index2 = $toInteger(index2); | |
| 168 if (index1 < 0 || index1 >= ia.length || index2 < 0 || index2 >= ia.length) { | |
| 169 return UNDEFINED; | |
| 170 } | |
| 171 return %_AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); | |
| 172 } | |
| 173 | |
| 118 // ------------------------------------------------------------------- | 174 // ------------------------------------------------------------------- |
| 119 | 175 |
| 120 function AtomicsConstructor() {} | 176 function AtomicsConstructor() {} |
| 121 | 177 |
| 122 var Atomics = new AtomicsConstructor(); | 178 var Atomics = new AtomicsConstructor(); |
| 123 | 179 |
| 124 %InternalSetPrototype(Atomics, GlobalObject.prototype); | 180 %InternalSetPrototype(Atomics, GlobalObject.prototype); |
| 125 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); | 181 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); |
| 126 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); | 182 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); |
| 127 | 183 |
| 128 %AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM); | 184 %AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM); |
| 129 | 185 |
| 186 // These must match the values in src/futex-emulation.h | |
| 187 utils.InstallConstants(Atomics, [ | |
| 188 "OK", 0, | |
| 189 "NOTEQUAL", -1, | |
| 190 "TIMEDOUT", -2, | |
| 191 ]); | |
| 192 | |
| 130 utils.InstallFunctions(Atomics, DONT_ENUM, [ | 193 utils.InstallFunctions(Atomics, DONT_ENUM, [ |
| 131 "compareExchange", AtomicsCompareExchangeJS, | 194 "compareExchange", AtomicsCompareExchangeJS, |
| 132 "load", AtomicsLoadJS, | 195 "load", AtomicsLoadJS, |
| 133 "store", AtomicsStoreJS, | 196 "store", AtomicsStoreJS, |
| 134 "add", AtomicsAddJS, | 197 "add", AtomicsAddJS, |
| 135 "sub", AtomicsSubJS, | 198 "sub", AtomicsSubJS, |
| 136 "and", AtomicsAndJS, | 199 "and", AtomicsAndJS, |
| 137 "or", AtomicsOrJS, | 200 "or", AtomicsOrJS, |
| 138 "xor", AtomicsXorJS, | 201 "xor", AtomicsXorJS, |
| 139 "exchange", AtomicsExchangeJS, | 202 "exchange", AtomicsExchangeJS, |
| 140 "isLockFree", AtomicsIsLockFreeJS, | 203 "isLockFree", AtomicsIsLockFreeJS, |
| 204 "futexWait", AtomicsFutexWaitJS, | |
| 205 "futexWake", AtomicsFutexWakeJS, | |
| 206 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, | |
| 141 ]); | 207 ]); |
| 142 | 208 |
| 143 }) | 209 }) |
| OLD | NEW |