| 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 var MathMax; |   15 var MathMax; | 
|   16 var ToNumber; |  | 
|   17 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |   16 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 
|   18  |   17  | 
|   19 utils.Import(function(from) { |   18 utils.Import(function(from) { | 
|   20   MathMax = from.MathMax; |   19   MathMax = from.MathMax; | 
|   21   ToNumber = from.ToNumber; |  | 
|   22 }); |   20 }); | 
|   23  |   21  | 
|   24 // ------------------------------------------------------------------- |   22 // ------------------------------------------------------------------- | 
|   25  |   23  | 
|   26  |   24  | 
|   27 function CheckSharedIntegerTypedArray(ia) { |   25 function CheckSharedIntegerTypedArray(ia) { | 
|   28   if (!%IsSharedIntegerTypedArray(ia)) { |   26   if (!%IsSharedIntegerTypedArray(ia)) { | 
|   29     throw MakeTypeError(kNotIntegerSharedTypedArray, ia); |   27     throw MakeTypeError(kNotIntegerSharedTypedArray, ia); | 
|   30   } |   28   } | 
|   31 } |   29 } | 
|   32  |   30  | 
|   33 function CheckSharedInteger32TypedArray(ia) { |   31 function CheckSharedInteger32TypedArray(ia) { | 
|   34   CheckSharedIntegerTypedArray(ia); |   32   CheckSharedIntegerTypedArray(ia); | 
|   35   if (%_ClassOf(ia) !== 'Int32Array') { |   33   if (%_ClassOf(ia) !== 'Int32Array') { | 
|   36     throw MakeTypeError(kNotInt32SharedTypedArray, ia); |   34     throw MakeTypeError(kNotInt32SharedTypedArray, ia); | 
|   37   } |   35   } | 
|   38 } |   36 } | 
|   39  |   37  | 
|   40 //------------------------------------------------------------------- |   38 //------------------------------------------------------------------- | 
|   41  |   39  | 
|   42 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { |   40 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { | 
|   43   CheckSharedIntegerTypedArray(sta); |   41   CheckSharedIntegerTypedArray(sta); | 
|   44   index = TO_INTEGER(index); |   42   index = TO_INTEGER(index); | 
|   45   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { |   43   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { | 
|   46     return UNDEFINED; |   44     return UNDEFINED; | 
|   47   } |   45   } | 
|   48   oldValue = ToNumber(oldValue); |   46   oldValue = TO_NUMBER(oldValue); | 
|   49   newValue = ToNumber(newValue); |   47   newValue = TO_NUMBER(newValue); | 
|   50   return %_AtomicsCompareExchange(sta, index, oldValue, newValue); |   48   return %_AtomicsCompareExchange(sta, index, oldValue, newValue); | 
|   51 } |   49 } | 
|   52  |   50  | 
|   53 function AtomicsLoadJS(sta, index) { |   51 function AtomicsLoadJS(sta, index) { | 
|   54   CheckSharedIntegerTypedArray(sta); |   52   CheckSharedIntegerTypedArray(sta); | 
|   55   index = TO_INTEGER(index); |   53   index = TO_INTEGER(index); | 
|   56   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { |   54   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { | 
|   57     return UNDEFINED; |   55     return UNDEFINED; | 
|   58   } |   56   } | 
|   59   return %_AtomicsLoad(sta, index); |   57   return %_AtomicsLoad(sta, index); | 
|   60 } |   58 } | 
|   61  |   59  | 
|   62 function AtomicsStoreJS(sta, index, value) { |   60 function AtomicsStoreJS(sta, index, value) { | 
|   63   CheckSharedIntegerTypedArray(sta); |   61   CheckSharedIntegerTypedArray(sta); | 
|   64   index = TO_INTEGER(index); |   62   index = TO_INTEGER(index); | 
|   65   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { |   63   if (index < 0 || index >= %_TypedArrayGetLength(sta)) { | 
|   66     return UNDEFINED; |   64     return UNDEFINED; | 
|   67   } |   65   } | 
|   68   value = ToNumber(value); |   66   value = TO_NUMBER(value); | 
|   69   return %_AtomicsStore(sta, index, value); |   67   return %_AtomicsStore(sta, index, value); | 
|   70 } |   68 } | 
|   71  |   69  | 
|   72 function AtomicsAddJS(ia, index, value) { |   70 function AtomicsAddJS(ia, index, value) { | 
|   73   CheckSharedIntegerTypedArray(ia); |   71   CheckSharedIntegerTypedArray(ia); | 
|   74   index = TO_INTEGER(index); |   72   index = TO_INTEGER(index); | 
|   75   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |   73   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|   76     return UNDEFINED; |   74     return UNDEFINED; | 
|   77   } |   75   } | 
|   78   value = ToNumber(value); |   76   value = TO_NUMBER(value); | 
|   79   return %_AtomicsAdd(ia, index, value); |   77   return %_AtomicsAdd(ia, index, value); | 
|   80 } |   78 } | 
|   81  |   79  | 
|   82 function AtomicsSubJS(ia, index, value) { |   80 function AtomicsSubJS(ia, index, value) { | 
|   83   CheckSharedIntegerTypedArray(ia); |   81   CheckSharedIntegerTypedArray(ia); | 
|   84   index = TO_INTEGER(index); |   82   index = TO_INTEGER(index); | 
|   85   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |   83   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|   86     return UNDEFINED; |   84     return UNDEFINED; | 
|   87   } |   85   } | 
|   88   value = ToNumber(value); |   86   value = TO_NUMBER(value); | 
|   89   return %_AtomicsSub(ia, index, value); |   87   return %_AtomicsSub(ia, index, value); | 
|   90 } |   88 } | 
|   91  |   89  | 
|   92 function AtomicsAndJS(ia, index, value) { |   90 function AtomicsAndJS(ia, index, value) { | 
|   93   CheckSharedIntegerTypedArray(ia); |   91   CheckSharedIntegerTypedArray(ia); | 
|   94   index = TO_INTEGER(index); |   92   index = TO_INTEGER(index); | 
|   95   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |   93   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|   96     return UNDEFINED; |   94     return UNDEFINED; | 
|   97   } |   95   } | 
|   98   value = ToNumber(value); |   96   value = TO_NUMBER(value); | 
|   99   return %_AtomicsAnd(ia, index, value); |   97   return %_AtomicsAnd(ia, index, value); | 
|  100 } |   98 } | 
|  101  |   99  | 
|  102 function AtomicsOrJS(ia, index, value) { |  100 function AtomicsOrJS(ia, index, value) { | 
|  103   CheckSharedIntegerTypedArray(ia); |  101   CheckSharedIntegerTypedArray(ia); | 
|  104   index = TO_INTEGER(index); |  102   index = TO_INTEGER(index); | 
|  105   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |  103   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|  106     return UNDEFINED; |  104     return UNDEFINED; | 
|  107   } |  105   } | 
|  108   value = ToNumber(value); |  106   value = TO_NUMBER(value); | 
|  109   return %_AtomicsOr(ia, index, value); |  107   return %_AtomicsOr(ia, index, value); | 
|  110 } |  108 } | 
|  111  |  109  | 
|  112 function AtomicsXorJS(ia, index, value) { |  110 function AtomicsXorJS(ia, index, value) { | 
|  113   CheckSharedIntegerTypedArray(ia); |  111   CheckSharedIntegerTypedArray(ia); | 
|  114   index = TO_INTEGER(index); |  112   index = TO_INTEGER(index); | 
|  115   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |  113   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|  116     return UNDEFINED; |  114     return UNDEFINED; | 
|  117   } |  115   } | 
|  118   value = ToNumber(value); |  116   value = TO_NUMBER(value); | 
|  119   return %_AtomicsXor(ia, index, value); |  117   return %_AtomicsXor(ia, index, value); | 
|  120 } |  118 } | 
|  121  |  119  | 
|  122 function AtomicsExchangeJS(ia, index, value) { |  120 function AtomicsExchangeJS(ia, index, value) { | 
|  123   CheckSharedIntegerTypedArray(ia); |  121   CheckSharedIntegerTypedArray(ia); | 
|  124   index = TO_INTEGER(index); |  122   index = TO_INTEGER(index); | 
|  125   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |  123   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|  126     return UNDEFINED; |  124     return UNDEFINED; | 
|  127   } |  125   } | 
|  128   value = ToNumber(value); |  126   value = TO_NUMBER(value); | 
|  129   return %_AtomicsExchange(ia, index, value); |  127   return %_AtomicsExchange(ia, index, value); | 
|  130 } |  128 } | 
|  131  |  129  | 
|  132 function AtomicsIsLockFreeJS(size) { |  130 function AtomicsIsLockFreeJS(size) { | 
|  133   return %_AtomicsIsLockFree(size); |  131   return %_AtomicsIsLockFree(size); | 
|  134 } |  132 } | 
|  135  |  133  | 
|  136 // Futexes |  134 // Futexes | 
|  137  |  135  | 
|  138 function AtomicsFutexWaitJS(ia, index, value, timeout) { |  136 function AtomicsFutexWaitJS(ia, index, value, timeout) { | 
|  139   CheckSharedInteger32TypedArray(ia); |  137   CheckSharedInteger32TypedArray(ia); | 
|  140   index = TO_INTEGER(index); |  138   index = TO_INTEGER(index); | 
|  141   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { |  139   if (index < 0 || index >= %_TypedArrayGetLength(ia)) { | 
|  142     return UNDEFINED; |  140     return UNDEFINED; | 
|  143   } |  141   } | 
|  144   if (IS_UNDEFINED(timeout)) { |  142   if (IS_UNDEFINED(timeout)) { | 
|  145     timeout = INFINITY; |  143     timeout = INFINITY; | 
|  146   } else { |  144   } else { | 
|  147     timeout = ToNumber(timeout); |  145     timeout = TO_NUMBER(timeout); | 
|  148     if (NUMBER_IS_NAN(timeout)) { |  146     if (NUMBER_IS_NAN(timeout)) { | 
|  149       timeout = INFINITY; |  147       timeout = INFINITY; | 
|  150     } else { |  148     } else { | 
|  151       timeout = MathMax(0, timeout); |  149       timeout = MathMax(0, timeout); | 
|  152     } |  150     } | 
|  153   } |  151   } | 
|  154   return %AtomicsFutexWait(ia, index, value, timeout); |  152   return %AtomicsFutexWait(ia, index, value, timeout); | 
|  155 } |  153 } | 
|  156  |  154  | 
|  157 function AtomicsFutexWakeJS(ia, index, count) { |  155 function AtomicsFutexWakeJS(ia, index, count) { | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  206   "or", AtomicsOrJS, |  204   "or", AtomicsOrJS, | 
|  207   "xor", AtomicsXorJS, |  205   "xor", AtomicsXorJS, | 
|  208   "exchange", AtomicsExchangeJS, |  206   "exchange", AtomicsExchangeJS, | 
|  209   "isLockFree", AtomicsIsLockFreeJS, |  207   "isLockFree", AtomicsIsLockFreeJS, | 
|  210   "futexWait", AtomicsFutexWaitJS, |  208   "futexWait", AtomicsFutexWaitJS, | 
|  211   "futexWake", AtomicsFutexWakeJS, |  209   "futexWake", AtomicsFutexWakeJS, | 
|  212   "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, |  210   "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, | 
|  213 ]); |  211 ]); | 
|  214  |  212  | 
|  215 }) |  213 }) | 
| OLD | NEW |