OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 "use strict"; | 28 "use strict"; |
29 | 29 |
30 var $ArrayBuffer = global.ArrayBuffer; | 30 var $ArrayBuffer = global.ArrayBuffer; |
31 | 31 |
32 // ------------------------------------------------------------------- | 32 // ------------------------------------------------------------------- |
33 | 33 |
34 function ArrayBufferConstructor(length) { // length = 1 | 34 function ArrayBufferConstructor(length, shared) { // length = 1 |
35 if (%_IsConstructCall()) { | 35 if (%_IsConstructCall()) { |
36 var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length'); | 36 var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length'); |
37 %ArrayBufferInitialize(this, byteLength); | 37 var is_shared = !!shared; |
| 38 %ArrayBufferInitialize(this, byteLength, is_shared); |
38 } else { | 39 } else { |
39 throw MakeTypeError('constructor_not_function', ["ArrayBuffer"]); | 40 throw MakeTypeError('constructor_not_function', ["ArrayBuffer"]); |
40 } | 41 } |
41 } | 42 } |
42 | 43 |
43 function ArrayBufferGetByteLength() { | 44 function ArrayBufferGetByteLength() { |
44 if (!IS_ARRAYBUFFER(this)) { | 45 if (!IS_ARRAYBUFFER(this)) { |
45 throw MakeTypeError('incompatible_method_receiver', | 46 throw MakeTypeError('incompatible_method_receiver', |
46 ['ArrayBuffer.prototype.byteLength', this]); | 47 ['ArrayBuffer.prototype.byteLength', this]); |
47 } | 48 } |
48 return %ArrayBufferGetByteLength(this); | 49 return %ArrayBufferGetByteLength(this); |
49 } | 50 } |
50 | 51 |
| 52 function ArrayBufferGetShared() { |
| 53 if (!IS_ARRAYBUFFER(this)) { |
| 54 throw MakeTypeError('incompatible_method_receiver', |
| 55 ['ArrayBuffer.prototype.shared', this]); |
| 56 } |
| 57 return %ArrayBufferGetShared(this); |
| 58 } |
| 59 |
51 // ES6 Draft 15.13.5.5.3 | 60 // ES6 Draft 15.13.5.5.3 |
52 function ArrayBufferSlice(start, end) { | 61 function ArrayBufferSlice(start, end) { |
53 if (!IS_ARRAYBUFFER(this)) { | 62 if (!IS_ARRAYBUFFER(this)) { |
54 throw MakeTypeError('incompatible_method_receiver', | 63 throw MakeTypeError('incompatible_method_receiver', |
55 ['ArrayBuffer.prototype.slice', this]); | 64 ['ArrayBuffer.prototype.slice', this]); |
56 } | 65 } |
57 | 66 |
58 var relativeStart = TO_INTEGER(start); | 67 var relativeStart = TO_INTEGER(start); |
59 var first; | 68 var first; |
60 if (relativeStart < 0) { | 69 if (relativeStart < 0) { |
(...skipping 17 matching lines...) Expand all Loading... |
78 var result = new $ArrayBuffer(newLen); | 87 var result = new $ArrayBuffer(newLen); |
79 | 88 |
80 %ArrayBufferSliceImpl(this, result, first); | 89 %ArrayBufferSliceImpl(this, result, first); |
81 return result; | 90 return result; |
82 } | 91 } |
83 | 92 |
84 function ArrayBufferIsView(obj) { | 93 function ArrayBufferIsView(obj) { |
85 return %ArrayBufferIsView(obj); | 94 return %ArrayBufferIsView(obj); |
86 } | 95 } |
87 | 96 |
| 97 function ArrayBufferMutexInit(addr) { |
| 98 var a = TO_INTEGER(addr); |
| 99 return %ArrayBufferMutexInit(this, a); |
| 100 } |
| 101 |
| 102 function ArrayBufferMutexDestroy(addr) { |
| 103 var a = TO_INTEGER(addr); |
| 104 return %ArrayBufferMutexDestroy(this, a); |
| 105 } |
| 106 |
| 107 function ArrayBufferMutexLock(addr) { |
| 108 var a = TO_INTEGER(addr); |
| 109 return %ArrayBufferMutexLock(this, a); |
| 110 } |
| 111 |
| 112 function ArrayBufferMutexUnlock(addr) { |
| 113 var a = TO_INTEGER(addr); |
| 114 return %ArrayBufferMutexUnlock(this, a); |
| 115 } |
| 116 |
| 117 function ArrayBufferMutexSize(obj) { |
| 118 return %ArrayBufferMutexSize(obj); |
| 119 } |
| 120 |
| 121 function ArrayBufferCondInit(addr) { |
| 122 var a = TO_INTEGER(addr); |
| 123 return %ArrayBufferCondInit(this, a); |
| 124 } |
| 125 |
| 126 function ArrayBufferCondDestroy(addr) { |
| 127 var a = TO_INTEGER(addr); |
| 128 return %ArrayBufferCondDestroy(this, a); |
| 129 } |
| 130 |
| 131 function ArrayBufferCondWait(caddr, maddr) { |
| 132 var ca = TO_INTEGER(caddr); |
| 133 var ma = TO_INTEGER(maddr); |
| 134 return %ArrayBufferCondWait(this, ca, ma); |
| 135 } |
| 136 |
| 137 function ArrayBufferCondSignal(addr) { |
| 138 var a = TO_INTEGER(addr); |
| 139 return %ArrayBufferCondSignal(this, a); |
| 140 } |
| 141 |
| 142 function ArrayBufferCondBroadcast(addr) { |
| 143 var a = TO_INTEGER(addr); |
| 144 return %ArrayBufferCondBroadcast(this, a); |
| 145 } |
| 146 |
| 147 function ArrayBufferCondSize(obj) { |
| 148 return %ArrayBufferCondSize(obj); |
| 149 } |
| 150 |
88 function SetUpArrayBuffer() { | 151 function SetUpArrayBuffer() { |
89 %CheckIsBootstrapping(); | 152 %CheckIsBootstrapping(); |
90 | 153 |
91 // Set up the ArrayBuffer constructor function. | 154 // Set up the ArrayBuffer constructor function. |
92 %SetCode($ArrayBuffer, ArrayBufferConstructor); | 155 %SetCode($ArrayBuffer, ArrayBufferConstructor); |
93 %FunctionSetPrototype($ArrayBuffer, new $Object()); | 156 %FunctionSetPrototype($ArrayBuffer, new $Object()); |
94 | 157 |
95 // Set up the constructor property on the ArrayBuffer prototype object. | 158 // Set up the constructor property on the ArrayBuffer prototype object. |
96 %SetProperty($ArrayBuffer.prototype, "constructor", $ArrayBuffer, DONT_ENUM); | 159 %SetProperty($ArrayBuffer.prototype, "constructor", $ArrayBuffer, DONT_ENUM); |
97 | 160 |
98 InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLength); | 161 InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLength); |
99 | 162 |
| 163 InstallGetter($ArrayBuffer.prototype, "shared", ArrayBufferGetShared); |
| 164 |
100 InstallFunctions($ArrayBuffer, DONT_ENUM, $Array( | 165 InstallFunctions($ArrayBuffer, DONT_ENUM, $Array( |
101 "isView", ArrayBufferIsView | 166 "isView", ArrayBufferIsView |
102 )); | 167 )); |
103 | 168 |
104 InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array( | 169 InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array( |
| 170 "mutexInit", ArrayBufferMutexInit, |
| 171 "mutexDestroy", ArrayBufferMutexDestroy, |
| 172 "mutexLock", ArrayBufferMutexLock, |
| 173 "mutexUnlock", ArrayBufferMutexUnlock, |
| 174 "mutexSize", ArrayBufferMutexSize, |
| 175 "condInit", ArrayBufferCondInit, |
| 176 "condDestroy", ArrayBufferCondDestroy, |
| 177 "condWait", ArrayBufferCondWait, |
| 178 "condSignal", ArrayBufferCondSignal, |
| 179 "condBroadcast", ArrayBufferCondBroadcast, |
| 180 "condSize", ArrayBufferCondSize, |
105 "slice", ArrayBufferSlice | 181 "slice", ArrayBufferSlice |
106 )); | 182 )); |
107 } | 183 } |
108 | 184 |
109 SetUpArrayBuffer(); | 185 SetUpArrayBuffer(); |
OLD | NEW |