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

Unified Diff: src/harmony-atomics.js

Issue 1162503002: Implement Atomics API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add more symbols to anonymous namespace 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | src/messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-atomics.js
diff --git a/src/harmony-atomics.js b/src/harmony-atomics.js
new file mode 100644
index 0000000000000000000000000000000000000000..aa81822d1e2f877f4de933f02d269b81775eea11
--- /dev/null
+++ b/src/harmony-atomics.js
@@ -0,0 +1,143 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function(global, utils) {
+
+"use strict";
+
+%CheckIsBootstrapping();
+
+// -------------------------------------------------------------------
+// Imports
+
+var GlobalObject = global.Object;
+
+// -------------------------------------------------------------------
+
+
+function CheckSharedTypedArray(sta) {
+ if (!%_IsSharedTypedArray(sta)) {
+ throw MakeTypeError(kNotSharedTypedArray, sta);
+ }
+}
+
+function CheckSharedIntegerTypedArray(ia) {
+ if (!%_IsSharedIntegerTypedArray(ia)) {
+ throw MakeTypeError(kNotIntegerSharedTypedArray, ia);
+ }
+}
+
+//-------------------------------------------------------------------
+
+function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
+ CheckSharedTypedArray(sta);
+ index = $toInteger(index);
+ if (index < 0 || index >= sta.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsCompareExchange(sta, index, oldValue, newValue);
+}
+
+function AtomicsLoadJS(sta, index) {
+ CheckSharedTypedArray(sta);
+ index = $toInteger(index);
+ if (index < 0 || index >= sta.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsLoad(sta, index);
+}
+
+function AtomicsStoreJS(sta, index, value) {
+ CheckSharedTypedArray(sta);
+ index = $toInteger(index);
+ if (index < 0 || index >= sta.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsStore(sta, index, value);
+}
+
+function AtomicsAddJS(ia, index, value) {
+ CheckSharedIntegerTypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsAdd(ia, index, value);
+}
+
+function AtomicsSubJS(ia, index, value) {
+ CheckSharedIntegerTypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsSub(ia, index, value);
+}
+
+function AtomicsAndJS(ia, index, value) {
+ CheckSharedIntegerTypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsAnd(ia, index, value);
+}
+
+function AtomicsOrJS(ia, index, value) {
+ CheckSharedIntegerTypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsOr(ia, index, value);
+}
+
+function AtomicsXorJS(ia, index, value) {
+ CheckSharedIntegerTypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsXor(ia, index, value);
+}
+
+function AtomicsExchangeJS(ia, index, value) {
+ CheckSharedIntegerTypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsExchange(ia, index, value);
+}
+
+function AtomicsIsLockFreeJS(size) {
+ return %_AtomicsIsLockFree(size);
+}
+
+// -------------------------------------------------------------------
+
+function AtomicsConstructor() {}
+
+var Atomics = new AtomicsConstructor();
+
+%InternalSetPrototype(Atomics, GlobalObject.prototype);
+%AddNamedProperty(global, "Atomics", Atomics, DONT_ENUM);
+%FunctionSetInstanceClassName(AtomicsConstructor, 'Atomics');
+
+%AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM);
+
+utils.InstallFunctions(Atomics, DONT_ENUM, [
+ "compareExchange", AtomicsCompareExchangeJS,
+ "load", AtomicsLoadJS,
+ "store", AtomicsStoreJS,
+ "add", AtomicsAddJS,
+ "sub", AtomicsSubJS,
+ "and", AtomicsAndJS,
+ "or", AtomicsOrJS,
+ "xor", AtomicsXorJS,
+ "exchange", AtomicsExchangeJS,
+ "isLockFree", AtomicsIsLockFreeJS,
+]);
+
+})
« 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