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

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

Issue 1124813005: WIP Atomics (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix AtomicsLoad type in typer.cc Created 5 years, 7 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/flag-definitions.h ('k') | src/messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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, shared, exports) {
6
7 "use strict";
8
9 %CheckIsBootstrapping();
10
11 var GlobalObject = global.Object;
12
13
14 // TODO(binji): something better here? We want this to match the behavior of
15 // integer indexed exotic object access, e.g.
16 // a = new Uint32Array(10);
17 // a[0] == 0
18 // a['0'] == 0
19 // a[new Number(0)] == 0
20 // a[{valueOf: function(){return 0;}}] == 0
21 // a[-1] == undefined
22 // a[11] == undefined
23 // a[0.4] == undefined
24 // a[null] == undefined
25 // a[undefined] == undefined
26 // a[false] == undefined
27 // a[{}] == undefined
28 // a['hello'] == undefined
29 // etc.
30 function ToIndex(x) {
31 if (%_IsSmi(x)) return x;
32 if (IS_NUMBER(x)) return %NumberToInteger(x);
33 if (IS_STRING(x)) {
34 if (%_HasCachedArrayIndex(x)) {
35 return %_GetCachedArrayIndex(x);
36 }
37
38 var n = %StringToNumber(x);
39 if (NUMBER_IS_NAN(n)) return UNDEFINED;
40
41 return %NumberToInteger(n);
42 }
43 return UNDEFINED;
44 }
45
46 function CheckSharedTypedArray(sta) {
47 if (!%_IsSharedTypedArray(sta)) {
48 throw MakeTypeError(kNotSharedTypedArray, sta);
49 }
50 }
51
52 function CheckSharedIntegerTypedArray(ia) {
53 if (!%_IsSharedIntegerTypedArray(ia)) {
54 throw MakeTypeError(kNotIntegerSharedTypedArray, ia);
55 }
56 }
57
58 //-------------------------------------------------------------------
59
60 function AtomicsCompareExchange(sta, index, oldValue, newValue) {
61 CheckSharedTypedArray(sta);
62 index = ToIndex(index);
63 if (IS_UNDEFINED(index) || index < 0 || index >= sta.length) {
64 return UNDEFINED;
65 }
66 return %_AtomicsCompareExchange(sta, index, oldValue, newValue);
67 }
68
69 function AtomicsLoad(sta, index) {
70 CheckSharedTypedArray(sta);
71 index = ToIndex(index);
72 if (IS_UNDEFINED(index) || index < 0 || index >= sta.length) {
73 return UNDEFINED;
74 }
75 return %_AtomicsLoad(sta, index);
76 }
77
78 function AtomicsStore(sta, index, value) {
79 CheckSharedTypedArray(sta);
80 index = ToIndex(index);
81 if (IS_UNDEFINED(index) || index < 0 || index >= sta.length) {
82 return UNDEFINED;
83 }
84 return %_AtomicsStore(sta, index, value);
85 }
86
87 function AtomicsAdd(ia, index, value) {
88 CheckSharedIntegerTypedArray(ia);
89 index = ToIndex(index);
90 if (IS_UNDEFINED(index) || index < 0 || index >= ia.length) {
91 return UNDEFINED;
92 }
93 return %_AtomicsAdd(ia, index, value);
94 }
95
96 function AtomicsSub(ia, index, value) {
97 CheckSharedIntegerTypedArray(ia);
98 index = ToIndex(index);
99 if (IS_UNDEFINED(index) || index < 0 || index >= ia.length) {
100 return UNDEFINED;
101 }
102 return %_AtomicsSub(ia, index, value);
103 }
104
105 function AtomicsAnd(ia, index, value) {
106 CheckSharedIntegerTypedArray(ia);
107 index = ToIndex(index);
108 if (IS_UNDEFINED(index) || index < 0 || index >= ia.length) {
109 return UNDEFINED;
110 }
111 return %_AtomicsAnd(ia, index, value);
112 }
113
114 function AtomicsOr(ia, index, value) {
115 CheckSharedIntegerTypedArray(ia);
116 index = ToIndex(index);
117 if (IS_UNDEFINED(index) || index < 0 || index >= ia.length) {
118 return UNDEFINED;
119 }
120 return %_AtomicsOr(ia, index, value);
121 }
122
123 function AtomicsXor(ia, index, value) {
124 CheckSharedIntegerTypedArray(ia);
125 index = ToIndex(index);
126 if (IS_UNDEFINED(index) || index < 0 || index >= ia.length) {
127 return UNDEFINED;
128 }
129 return %_AtomicsXor(ia, index, value);
130 }
131
132 function AtomicsExchange(ia, index, value) {
133 CheckSharedIntegerTypedArray(ia);
134 index = ToIndex(index);
135 if (IS_UNDEFINED(index) || index < 0 || index >= ia.length) {
136 return UNDEFINED;
137 }
138 return %_AtomicsExchange(ia, index, value);
139 }
140
141 function AtomicsIsLockFree(size) {
142 return %_AtomicsIsLockFree(size);
143 }
144
145 // -------------------------------------------------------------------
146
147 function AtomicsConstructor() {}
148
149 var Atomics = new AtomicsConstructor();
150
151 %InternalSetPrototype(Atomics, GlobalObject.prototype);
152 %AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM);
153 %FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics');
154
155 %AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM);
156
157 $installFunctions(Atomics, DONT_ENUM, [
158 "compareExchange", AtomicsCompareExchange,
159 "load", AtomicsLoad,
160 "store", AtomicsStore,
161 "add", AtomicsAdd,
162 "sub", AtomicsSub,
163 "and", AtomicsAnd,
164 "or", AtomicsOr,
165 "xor", AtomicsXor,
166 "exchange", AtomicsExchange,
167 "isLockFree", AtomicsIsLockFree,
168 ]);
169
170 })
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698