Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 %TypedArrayInitialize(obj, arrayId, buffer, offset, newByteLength); | 116 %TypedArrayInitialize(obj, arrayId, buffer, offset, newByteLength); |
| 117 } | 117 } |
| 118 | 118 |
| 119 function ConstructByLength(obj, length) { | 119 function ConstructByLength(obj, length) { |
| 120 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); | 120 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); |
| 121 var byteLength = l * elementSize; | 121 var byteLength = l * elementSize; |
| 122 var buffer = new $ArrayBuffer(byteLength); | 122 var buffer = new $ArrayBuffer(byteLength); |
| 123 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); | 123 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); |
| 124 } | 124 } |
| 125 | 125 |
| 126 function TryConstructByArrayLike(obj, arrayLike) { | |
|
rossberg
2013/05/02 11:52:20
Nit: why is this called TryConstruct?
| |
| 127 var length = arrayLike.length; | |
| 128 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); | |
| 129 var byteLength = l * elementSize; | |
| 130 var buffer = new $ArrayBuffer(byteLength); | |
| 131 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); | |
| 132 for (var i = 0; i < l; i++) { | |
| 133 obj[i] = arrayLike[i]; | |
| 134 } | |
| 135 } | |
| 136 | |
| 126 return function (arg1, arg2, arg3) { | 137 return function (arg1, arg2, arg3) { |
| 127 if (%_IsConstructCall()) { | 138 if (%_IsConstructCall()) { |
| 128 if (IS_ARRAYBUFFER(arg1)) { | 139 if (IS_ARRAYBUFFER(arg1)) { |
| 129 ConstructByArrayBuffer(this, arg1, arg2, arg3); | 140 ConstructByArrayBuffer(this, arg1, arg2, arg3); |
| 141 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || IS_BOOLEAN(arg1)) { | |
| 142 ConstructByLength(this, arg1); | |
| 143 } else if (!IS_UNDEFINED(arg1)){ | |
| 144 TryConstructByArrayLike(this, arg1); | |
| 130 } else { | 145 } else { |
| 131 ConstructByLength(this, arg1); | 146 throw MakeTypeError("parameterless_typed_array_constr", name); |
| 132 } | 147 } |
| 133 } else { | 148 } else { |
| 134 return new constructor(arg1, arg2, arg3); | 149 return new constructor(arg1, arg2, arg3); |
| 135 } | 150 } |
| 136 } | 151 } |
| 137 } | 152 } |
| 138 | 153 |
| 139 function TypedArrayGetBuffer() { | 154 function TypedArrayGetBuffer() { |
| 140 return %TypedArrayGetBuffer(this); | 155 return %TypedArrayGetBuffer(this); |
| 141 } | 156 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 210 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 196 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); | 211 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); |
| 197 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); | 212 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); |
| 198 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); | 213 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); |
| 199 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); | 214 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); |
| 200 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); | 215 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); |
| 201 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); | 216 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); |
| 202 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); | 217 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); |
| 203 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); | 218 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); |
| 204 | 219 |
| OLD | NEW |