| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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, shared, exports) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 |
| 12 // ------------------------------------------------------------------- |
| 13 // Imports |
| 14 |
| 11 var GlobalArrayBuffer = global.ArrayBuffer; | 15 var GlobalArrayBuffer = global.ArrayBuffer; |
| 12 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
| 13 | 17 |
| 18 var MathMax; |
| 19 var MathMin; |
| 20 |
| 21 utils.Import(function(from) { |
| 22 MathMax = from.MathMax; |
| 23 MathMin = from.MathMin; |
| 24 }); |
| 25 |
| 14 // ------------------------------------------------------------------- | 26 // ------------------------------------------------------------------- |
| 15 | 27 |
| 16 function ArrayBufferConstructor(length) { // length = 1 | 28 function ArrayBufferConstructor(length) { // length = 1 |
| 17 if (%_IsConstructCall()) { | 29 if (%_IsConstructCall()) { |
| 18 var byteLength = $toPositiveInteger(length, kInvalidArrayBufferLength); | 30 var byteLength = $toPositiveInteger(length, kInvalidArrayBufferLength); |
| 19 %ArrayBufferInitialize(this, byteLength); | 31 %ArrayBufferInitialize(this, byteLength); |
| 20 } else { | 32 } else { |
| 21 throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer"); | 33 throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer"); |
| 22 } | 34 } |
| 23 } | 35 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 37 'ArrayBuffer.prototype.slice', this); | 49 'ArrayBuffer.prototype.slice', this); |
| 38 } | 50 } |
| 39 | 51 |
| 40 var relativeStart = TO_INTEGER(start); | 52 var relativeStart = TO_INTEGER(start); |
| 41 if (!IS_UNDEFINED(end)) { | 53 if (!IS_UNDEFINED(end)) { |
| 42 end = TO_INTEGER(end); | 54 end = TO_INTEGER(end); |
| 43 } | 55 } |
| 44 var first; | 56 var first; |
| 45 var byte_length = %_ArrayBufferGetByteLength(this); | 57 var byte_length = %_ArrayBufferGetByteLength(this); |
| 46 if (relativeStart < 0) { | 58 if (relativeStart < 0) { |
| 47 first = $max(byte_length + relativeStart, 0); | 59 first = MathMax(byte_length + relativeStart, 0); |
| 48 } else { | 60 } else { |
| 49 first = $min(relativeStart, byte_length); | 61 first = MathMin(relativeStart, byte_length); |
| 50 } | 62 } |
| 51 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end; | 63 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end; |
| 52 var fin; | 64 var fin; |
| 53 if (relativeEnd < 0) { | 65 if (relativeEnd < 0) { |
| 54 fin = $max(byte_length + relativeEnd, 0); | 66 fin = MathMax(byte_length + relativeEnd, 0); |
| 55 } else { | 67 } else { |
| 56 fin = $min(relativeEnd, byte_length); | 68 fin = MathMin(relativeEnd, byte_length); |
| 57 } | 69 } |
| 58 | 70 |
| 59 if (fin < first) { | 71 if (fin < first) { |
| 60 fin = first; | 72 fin = first; |
| 61 } | 73 } |
| 62 var newLen = fin - first; | 74 var newLen = fin - first; |
| 63 // TODO(dslomov): implement inheritance | 75 // TODO(dslomov): implement inheritance |
| 64 var result = new GlobalArrayBuffer(newLen); | 76 var result = new GlobalArrayBuffer(newLen); |
| 65 | 77 |
| 66 %ArrayBufferSliceImpl(this, result, first); | 78 %ArrayBufferSliceImpl(this, result, first); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 87 | 99 |
| 88 $installFunctions(GlobalArrayBuffer, DONT_ENUM, [ | 100 $installFunctions(GlobalArrayBuffer, DONT_ENUM, [ |
| 89 "isView", ArrayBufferIsViewJS | 101 "isView", ArrayBufferIsViewJS |
| 90 ]); | 102 ]); |
| 91 | 103 |
| 92 $installFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ | 104 $installFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ |
| 93 "slice", ArrayBufferSlice | 105 "slice", ArrayBufferSlice |
| 94 ]); | 106 ]); |
| 95 | 107 |
| 96 }) | 108 }) |
| OLD | NEW |