OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 (function(global, utils) { |
| 6 |
| 7 "use strict"; |
| 8 |
| 9 %CheckIsBootstrapping(); |
| 10 |
| 11 // ------------------------------------------------------------------- |
| 12 // Imports |
| 13 |
| 14 var GlobalObject = global.Object; |
| 15 |
| 16 // ------------------------------------------------------------------- |
| 17 |
| 18 |
| 19 function CheckSharedTypedArray(sta) { |
| 20 if (!%_IsSharedTypedArray(sta)) { |
| 21 throw MakeTypeError(kNotSharedTypedArray, sta); |
| 22 } |
| 23 } |
| 24 |
| 25 function CheckSharedIntegerTypedArray(ia) { |
| 26 if (!%_IsSharedIntegerTypedArray(ia)) { |
| 27 throw MakeTypeError(kNotIntegerSharedTypedArray, ia); |
| 28 } |
| 29 } |
| 30 |
| 31 //------------------------------------------------------------------- |
| 32 |
| 33 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { |
| 34 CheckSharedTypedArray(sta); |
| 35 index = $toInteger(index); |
| 36 if (index < 0 || index >= sta.length) { |
| 37 return UNDEFINED; |
| 38 } |
| 39 return %_AtomicsCompareExchange(sta, index, oldValue, newValue); |
| 40 } |
| 41 |
| 42 function AtomicsLoadJS(sta, index) { |
| 43 CheckSharedTypedArray(sta); |
| 44 index = $toInteger(index); |
| 45 if (index < 0 || index >= sta.length) { |
| 46 return UNDEFINED; |
| 47 } |
| 48 return %_AtomicsLoad(sta, index); |
| 49 } |
| 50 |
| 51 function AtomicsStoreJS(sta, index, value) { |
| 52 CheckSharedTypedArray(sta); |
| 53 index = $toInteger(index); |
| 54 if (index < 0 || index >= sta.length) { |
| 55 return UNDEFINED; |
| 56 } |
| 57 return %_AtomicsStore(sta, index, value); |
| 58 } |
| 59 |
| 60 function AtomicsAddJS(ia, index, value) { |
| 61 CheckSharedIntegerTypedArray(ia); |
| 62 index = $toInteger(index); |
| 63 if (index < 0 || index >= ia.length) { |
| 64 return UNDEFINED; |
| 65 } |
| 66 return %_AtomicsAdd(ia, index, value); |
| 67 } |
| 68 |
| 69 function AtomicsSubJS(ia, index, value) { |
| 70 CheckSharedIntegerTypedArray(ia); |
| 71 index = $toInteger(index); |
| 72 if (index < 0 || index >= ia.length) { |
| 73 return UNDEFINED; |
| 74 } |
| 75 return %_AtomicsSub(ia, index, value); |
| 76 } |
| 77 |
| 78 function AtomicsAndJS(ia, index, value) { |
| 79 CheckSharedIntegerTypedArray(ia); |
| 80 index = $toInteger(index); |
| 81 if (index < 0 || index >= ia.length) { |
| 82 return UNDEFINED; |
| 83 } |
| 84 return %_AtomicsAnd(ia, index, value); |
| 85 } |
| 86 |
| 87 function AtomicsOrJS(ia, index, value) { |
| 88 CheckSharedIntegerTypedArray(ia); |
| 89 index = $toInteger(index); |
| 90 if (index < 0 || index >= ia.length) { |
| 91 return UNDEFINED; |
| 92 } |
| 93 return %_AtomicsOr(ia, index, value); |
| 94 } |
| 95 |
| 96 function AtomicsXorJS(ia, index, value) { |
| 97 CheckSharedIntegerTypedArray(ia); |
| 98 index = $toInteger(index); |
| 99 if (index < 0 || index >= ia.length) { |
| 100 return UNDEFINED; |
| 101 } |
| 102 return %_AtomicsXor(ia, index, value); |
| 103 } |
| 104 |
| 105 function AtomicsExchangeJS(ia, index, value) { |
| 106 CheckSharedIntegerTypedArray(ia); |
| 107 index = $toInteger(index); |
| 108 if (index < 0 || index >= ia.length) { |
| 109 return UNDEFINED; |
| 110 } |
| 111 return %_AtomicsExchange(ia, index, value); |
| 112 } |
| 113 |
| 114 function AtomicsIsLockFreeJS(size) { |
| 115 return %_AtomicsIsLockFree(size); |
| 116 } |
| 117 |
| 118 // ------------------------------------------------------------------- |
| 119 |
| 120 function AtomicsConstructor() {} |
| 121 |
| 122 var Atomics = new AtomicsConstructor(); |
| 123 |
| 124 %InternalSetPrototype(Atomics, GlobalObject.prototype); |
| 125 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM); |
| 126 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics'); |
| 127 |
| 128 %AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM); |
| 129 |
| 130 utils.InstallFunctions(Atomics, DONT_ENUM, [ |
| 131 "compareExchange", AtomicsCompareExchangeJS, |
| 132 "load", AtomicsLoadJS, |
| 133 "store", AtomicsStoreJS, |
| 134 "add", AtomicsAddJS, |
| 135 "sub", AtomicsSubJS, |
| 136 "and", AtomicsAndJS, |
| 137 "or", AtomicsOrJS, |
| 138 "xor", AtomicsXorJS, |
| 139 "exchange", AtomicsExchangeJS, |
| 140 "isLockFree", AtomicsIsLockFreeJS, |
| 141 ]); |
| 142 |
| 143 }) |
OLD | NEW |