Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: src/harmony-atomics.js

Issue 1378533002: [es6] Introduce %ToInteger and %ToLength. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/harmony-array-includes.js ('k') | src/hydrogen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 CheckSharedIntegerTypedArray(ia); 34 CheckSharedIntegerTypedArray(ia);
35 if (%_ClassOf(ia) !== 'Int32Array') { 35 if (%_ClassOf(ia) !== 'Int32Array') {
36 throw MakeTypeError(kNotInt32SharedTypedArray, ia); 36 throw MakeTypeError(kNotInt32SharedTypedArray, ia);
37 } 37 }
38 } 38 }
39 39
40 //------------------------------------------------------------------- 40 //-------------------------------------------------------------------
41 41
42 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { 42 function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
43 CheckSharedIntegerTypedArray(sta); 43 CheckSharedIntegerTypedArray(sta);
44 index = $toInteger(index); 44 index = TO_INTEGER(index);
45 if (index < 0 || index >= %_TypedArrayGetLength(sta)) { 45 if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
46 return UNDEFINED; 46 return UNDEFINED;
47 } 47 }
48 oldValue = ToNumber(oldValue); 48 oldValue = ToNumber(oldValue);
49 newValue = ToNumber(newValue); 49 newValue = ToNumber(newValue);
50 return %_AtomicsCompareExchange(sta, index, oldValue, newValue); 50 return %_AtomicsCompareExchange(sta, index, oldValue, newValue);
51 } 51 }
52 52
53 function AtomicsLoadJS(sta, index) { 53 function AtomicsLoadJS(sta, index) {
54 CheckSharedIntegerTypedArray(sta); 54 CheckSharedIntegerTypedArray(sta);
55 index = $toInteger(index); 55 index = TO_INTEGER(index);
56 if (index < 0 || index >= %_TypedArrayGetLength(sta)) { 56 if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
57 return UNDEFINED; 57 return UNDEFINED;
58 } 58 }
59 return %_AtomicsLoad(sta, index); 59 return %_AtomicsLoad(sta, index);
60 } 60 }
61 61
62 function AtomicsStoreJS(sta, index, value) { 62 function AtomicsStoreJS(sta, index, value) {
63 CheckSharedIntegerTypedArray(sta); 63 CheckSharedIntegerTypedArray(sta);
64 index = $toInteger(index); 64 index = TO_INTEGER(index);
65 if (index < 0 || index >= %_TypedArrayGetLength(sta)) { 65 if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
66 return UNDEFINED; 66 return UNDEFINED;
67 } 67 }
68 value = ToNumber(value); 68 value = ToNumber(value);
69 return %_AtomicsStore(sta, index, value); 69 return %_AtomicsStore(sta, index, value);
70 } 70 }
71 71
72 function AtomicsAddJS(ia, index, value) { 72 function AtomicsAddJS(ia, index, value) {
73 CheckSharedIntegerTypedArray(ia); 73 CheckSharedIntegerTypedArray(ia);
74 index = $toInteger(index); 74 index = TO_INTEGER(index);
75 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 75 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
76 return UNDEFINED; 76 return UNDEFINED;
77 } 77 }
78 value = ToNumber(value); 78 value = ToNumber(value);
79 return %_AtomicsAdd(ia, index, value); 79 return %_AtomicsAdd(ia, index, value);
80 } 80 }
81 81
82 function AtomicsSubJS(ia, index, value) { 82 function AtomicsSubJS(ia, index, value) {
83 CheckSharedIntegerTypedArray(ia); 83 CheckSharedIntegerTypedArray(ia);
84 index = $toInteger(index); 84 index = TO_INTEGER(index);
85 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 85 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
86 return UNDEFINED; 86 return UNDEFINED;
87 } 87 }
88 value = ToNumber(value); 88 value = ToNumber(value);
89 return %_AtomicsSub(ia, index, value); 89 return %_AtomicsSub(ia, index, value);
90 } 90 }
91 91
92 function AtomicsAndJS(ia, index, value) { 92 function AtomicsAndJS(ia, index, value) {
93 CheckSharedIntegerTypedArray(ia); 93 CheckSharedIntegerTypedArray(ia);
94 index = $toInteger(index); 94 index = TO_INTEGER(index);
95 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 95 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
96 return UNDEFINED; 96 return UNDEFINED;
97 } 97 }
98 value = ToNumber(value); 98 value = ToNumber(value);
99 return %_AtomicsAnd(ia, index, value); 99 return %_AtomicsAnd(ia, index, value);
100 } 100 }
101 101
102 function AtomicsOrJS(ia, index, value) { 102 function AtomicsOrJS(ia, index, value) {
103 CheckSharedIntegerTypedArray(ia); 103 CheckSharedIntegerTypedArray(ia);
104 index = $toInteger(index); 104 index = TO_INTEGER(index);
105 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 105 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
106 return UNDEFINED; 106 return UNDEFINED;
107 } 107 }
108 value = ToNumber(value); 108 value = ToNumber(value);
109 return %_AtomicsOr(ia, index, value); 109 return %_AtomicsOr(ia, index, value);
110 } 110 }
111 111
112 function AtomicsXorJS(ia, index, value) { 112 function AtomicsXorJS(ia, index, value) {
113 CheckSharedIntegerTypedArray(ia); 113 CheckSharedIntegerTypedArray(ia);
114 index = $toInteger(index); 114 index = TO_INTEGER(index);
115 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 115 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
116 return UNDEFINED; 116 return UNDEFINED;
117 } 117 }
118 value = ToNumber(value); 118 value = ToNumber(value);
119 return %_AtomicsXor(ia, index, value); 119 return %_AtomicsXor(ia, index, value);
120 } 120 }
121 121
122 function AtomicsExchangeJS(ia, index, value) { 122 function AtomicsExchangeJS(ia, index, value) {
123 CheckSharedIntegerTypedArray(ia); 123 CheckSharedIntegerTypedArray(ia);
124 index = $toInteger(index); 124 index = TO_INTEGER(index);
125 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 125 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
126 return UNDEFINED; 126 return UNDEFINED;
127 } 127 }
128 value = ToNumber(value); 128 value = ToNumber(value);
129 return %_AtomicsExchange(ia, index, value); 129 return %_AtomicsExchange(ia, index, value);
130 } 130 }
131 131
132 function AtomicsIsLockFreeJS(size) { 132 function AtomicsIsLockFreeJS(size) {
133 return %_AtomicsIsLockFree(size); 133 return %_AtomicsIsLockFree(size);
134 } 134 }
135 135
136 // Futexes 136 // Futexes
137 137
138 function AtomicsFutexWaitJS(ia, index, value, timeout) { 138 function AtomicsFutexWaitJS(ia, index, value, timeout) {
139 CheckSharedInteger32TypedArray(ia); 139 CheckSharedInteger32TypedArray(ia);
140 index = $toInteger(index); 140 index = TO_INTEGER(index);
141 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 141 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
142 return UNDEFINED; 142 return UNDEFINED;
143 } 143 }
144 if (IS_UNDEFINED(timeout)) { 144 if (IS_UNDEFINED(timeout)) {
145 timeout = INFINITY; 145 timeout = INFINITY;
146 } else { 146 } else {
147 timeout = ToNumber(timeout); 147 timeout = ToNumber(timeout);
148 if (NUMBER_IS_NAN(timeout)) { 148 if (NUMBER_IS_NAN(timeout)) {
149 timeout = INFINITY; 149 timeout = INFINITY;
150 } else { 150 } else {
151 timeout = MathMax(0, timeout); 151 timeout = MathMax(0, timeout);
152 } 152 }
153 } 153 }
154 return %AtomicsFutexWait(ia, index, value, timeout); 154 return %AtomicsFutexWait(ia, index, value, timeout);
155 } 155 }
156 156
157 function AtomicsFutexWakeJS(ia, index, count) { 157 function AtomicsFutexWakeJS(ia, index, count) {
158 CheckSharedInteger32TypedArray(ia); 158 CheckSharedInteger32TypedArray(ia);
159 index = $toInteger(index); 159 index = TO_INTEGER(index);
160 if (index < 0 || index >= %_TypedArrayGetLength(ia)) { 160 if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
161 return UNDEFINED; 161 return UNDEFINED;
162 } 162 }
163 count = MathMax(0, $toInteger(count)); 163 count = MathMax(0, TO_INTEGER(count));
164 return %AtomicsFutexWake(ia, index, count); 164 return %AtomicsFutexWake(ia, index, count);
165 } 165 }
166 166
167 function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) { 167 function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) {
168 CheckSharedInteger32TypedArray(ia); 168 CheckSharedInteger32TypedArray(ia);
169 index1 = $toInteger(index1); 169 index1 = TO_INTEGER(index1);
170 count = MathMax(0, $toInteger(count)); 170 count = MathMax(0, TO_INTEGER(count));
171 value = TO_INT32(value); 171 value = TO_INT32(value);
172 index2 = $toInteger(index2); 172 index2 = TO_INTEGER(index2);
173 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || 173 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) ||
174 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { 174 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) {
175 return UNDEFINED; 175 return UNDEFINED;
176 } 176 }
177 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); 177 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2);
178 } 178 }
179 179
180 // ------------------------------------------------------------------- 180 // -------------------------------------------------------------------
181 181
182 function AtomicsConstructor() {} 182 function AtomicsConstructor() {}
(...skipping 23 matching lines...) Expand all
206 "or", AtomicsOrJS, 206 "or", AtomicsOrJS,
207 "xor", AtomicsXorJS, 207 "xor", AtomicsXorJS,
208 "exchange", AtomicsExchangeJS, 208 "exchange", AtomicsExchangeJS,
209 "isLockFree", AtomicsIsLockFreeJS, 209 "isLockFree", AtomicsIsLockFreeJS,
210 "futexWait", AtomicsFutexWaitJS, 210 "futexWait", AtomicsFutexWaitJS,
211 "futexWake", AtomicsFutexWakeJS, 211 "futexWake", AtomicsFutexWakeJS,
212 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, 212 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS,
213 ]); 213 ]);
214 214
215 }) 215 })
OLDNEW
« no previous file with comments | « src/harmony-array-includes.js ('k') | src/hydrogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698