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, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 var GlobalArrayBuffer = global.ArrayBuffer; | 14 var GlobalArrayBuffer = global.ArrayBuffer; |
15 var GlobalObject = global.Object; | 15 var GlobalObject = global.Object; |
16 var MathMax; | 16 var MaxSimple; |
17 var MathMin; | 17 var MinSimple; |
18 var ToPositiveInteger; | 18 var ToPositiveInteger; |
19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
20 | 20 |
21 utils.Import(function(from) { | 21 utils.Import(function(from) { |
22 MathMax = from.MathMax; | 22 MaxSimple = from.MaxSimple; |
23 MathMin = from.MathMin; | 23 MinSimple = from.MinSimple; |
24 ToPositiveInteger = from.ToPositiveInteger; | 24 ToPositiveInteger = from.ToPositiveInteger; |
25 }); | 25 }); |
26 | 26 |
27 // ------------------------------------------------------------------- | 27 // ------------------------------------------------------------------- |
28 | 28 |
29 function ArrayBufferConstructor(length) { // length = 1 | 29 function ArrayBufferConstructor(length) { // length = 1 |
30 if (%_IsConstructCall()) { | 30 if (%_IsConstructCall()) { |
31 var byteLength = ToPositiveInteger(length, kInvalidArrayBufferLength); | 31 var byteLength = ToPositiveInteger(length, kInvalidArrayBufferLength); |
32 %ArrayBufferInitialize(this, byteLength, kNotShared); | 32 %ArrayBufferInitialize(this, byteLength, kNotShared); |
33 } else { | 33 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
50 'ArrayBuffer.prototype.slice', this); | 50 'ArrayBuffer.prototype.slice', this); |
51 } | 51 } |
52 | 52 |
53 var relativeStart = TO_INTEGER(start); | 53 var relativeStart = TO_INTEGER(start); |
54 if (!IS_UNDEFINED(end)) { | 54 if (!IS_UNDEFINED(end)) { |
55 end = TO_INTEGER(end); | 55 end = TO_INTEGER(end); |
56 } | 56 } |
57 var first; | 57 var first; |
58 var byte_length = %_ArrayBufferGetByteLength(this); | 58 var byte_length = %_ArrayBufferGetByteLength(this); |
59 if (relativeStart < 0) { | 59 if (relativeStart < 0) { |
60 first = MathMax(byte_length + relativeStart, 0); | 60 first = MaxSimple(byte_length + relativeStart, 0); |
61 } else { | 61 } else { |
62 first = MathMin(relativeStart, byte_length); | 62 first = MinSimple(relativeStart, byte_length); |
63 } | 63 } |
64 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end; | 64 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end; |
65 var fin; | 65 var fin; |
66 if (relativeEnd < 0) { | 66 if (relativeEnd < 0) { |
67 fin = MathMax(byte_length + relativeEnd, 0); | 67 fin = MaxSimple(byte_length + relativeEnd, 0); |
68 } else { | 68 } else { |
69 fin = MathMin(relativeEnd, byte_length); | 69 fin = MinSimple(relativeEnd, byte_length); |
70 } | 70 } |
71 | 71 |
72 if (fin < first) { | 72 if (fin < first) { |
73 fin = first; | 73 fin = first; |
74 } | 74 } |
75 var newLen = fin - first; | 75 var newLen = fin - first; |
76 // TODO(dslomov): implement inheritance | 76 // TODO(dslomov): implement inheritance |
77 var result = new GlobalArrayBuffer(newLen); | 77 var result = new GlobalArrayBuffer(newLen); |
78 | 78 |
79 %ArrayBufferSliceImpl(this, result, first); | 79 %ArrayBufferSliceImpl(this, result, first); |
(...skipping 21 matching lines...) Expand all Loading... |
101 | 101 |
102 utils.InstallFunctions(GlobalArrayBuffer, DONT_ENUM, [ | 102 utils.InstallFunctions(GlobalArrayBuffer, DONT_ENUM, [ |
103 "isView", ArrayBufferIsViewJS | 103 "isView", ArrayBufferIsViewJS |
104 ]); | 104 ]); |
105 | 105 |
106 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ | 106 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ |
107 "slice", ArrayBufferSlice | 107 "slice", ArrayBufferSlice |
108 ]); | 108 ]); |
109 | 109 |
110 }) | 110 }) |
OLD | NEW |