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 MakeTypeError; | |
16 var MaxSimple; | 15 var MaxSimple; |
17 var MinSimple; | 16 var MinSimple; |
18 var SpeciesConstructor; | 17 var SpeciesConstructor; |
19 var speciesSymbol = utils.ImportNow("species_symbol"); | 18 var speciesSymbol = utils.ImportNow("species_symbol"); |
20 | 19 |
21 utils.Import(function(from) { | 20 utils.Import(function(from) { |
22 MakeTypeError = from.MakeTypeError; | |
23 MaxSimple = from.MaxSimple; | 21 MaxSimple = from.MaxSimple; |
24 MinSimple = from.MinSimple; | 22 MinSimple = from.MinSimple; |
25 SpeciesConstructor = from.SpeciesConstructor; | 23 SpeciesConstructor = from.SpeciesConstructor; |
26 }); | 24 }); |
27 | 25 |
28 // ------------------------------------------------------------------- | 26 // ------------------------------------------------------------------- |
29 | 27 |
30 // ES6 Draft 15.13.5.5.3 | 28 // ES6 Draft 15.13.5.5.3 |
31 function ArrayBufferSlice(start, end) { | 29 function ArrayBufferSlice(start, end) { |
32 if (!IS_ARRAYBUFFER(this)) { | 30 if (!IS_ARRAYBUFFER(this)) { |
33 throw MakeTypeError(kIncompatibleMethodReceiver, | 31 throw %make_type_error(kIncompatibleMethodReceiver, |
34 'ArrayBuffer.prototype.slice', this); | 32 'ArrayBuffer.prototype.slice', this); |
35 } | 33 } |
36 | 34 |
37 var relativeStart = TO_INTEGER(start); | 35 var relativeStart = TO_INTEGER(start); |
38 if (!IS_UNDEFINED(end)) { | 36 if (!IS_UNDEFINED(end)) { |
39 end = TO_INTEGER(end); | 37 end = TO_INTEGER(end); |
40 } | 38 } |
41 var first; | 39 var first; |
42 var byte_length = %_ArrayBufferGetByteLength(this); | 40 var byte_length = %_ArrayBufferGetByteLength(this); |
43 if (relativeStart < 0) { | 41 if (relativeStart < 0) { |
44 first = MaxSimple(byte_length + relativeStart, 0); | 42 first = MaxSimple(byte_length + relativeStart, 0); |
45 } else { | 43 } else { |
46 first = MinSimple(relativeStart, byte_length); | 44 first = MinSimple(relativeStart, byte_length); |
47 } | 45 } |
48 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end; | 46 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end; |
49 var fin; | 47 var fin; |
50 if (relativeEnd < 0) { | 48 if (relativeEnd < 0) { |
51 fin = MaxSimple(byte_length + relativeEnd, 0); | 49 fin = MaxSimple(byte_length + relativeEnd, 0); |
52 } else { | 50 } else { |
53 fin = MinSimple(relativeEnd, byte_length); | 51 fin = MinSimple(relativeEnd, byte_length); |
54 } | 52 } |
55 | 53 |
56 if (fin < first) { | 54 if (fin < first) { |
57 fin = first; | 55 fin = first; |
58 } | 56 } |
59 var newLen = fin - first; | 57 var newLen = fin - first; |
60 var constructor = SpeciesConstructor(this, GlobalArrayBuffer, true); | 58 var constructor = SpeciesConstructor(this, GlobalArrayBuffer, true); |
61 var result = new constructor(newLen); | 59 var result = new constructor(newLen); |
62 if (!IS_ARRAYBUFFER(result)) { | 60 if (!IS_ARRAYBUFFER(result)) { |
63 throw MakeTypeError(kIncompatibleMethodReceiver, | 61 throw %make_type_error(kIncompatibleMethodReceiver, |
64 'ArrayBuffer.prototype.slice', result); | 62 'ArrayBuffer.prototype.slice', result); |
65 } | 63 } |
66 // Checks for detached source/target ArrayBuffers are done inside of | 64 // Checks for detached source/target ArrayBuffers are done inside of |
67 // %ArrayBufferSliceImpl; the reordering of checks does not violate | 65 // %ArrayBufferSliceImpl; the reordering of checks does not violate |
68 // the spec because all exceptions thrown are TypeErrors. | 66 // the spec because all exceptions thrown are TypeErrors. |
69 if (result === this) { | 67 if (result === this) { |
70 throw MakeTypeError(kArrayBufferSpeciesThis); | 68 throw %make_type_error(kArrayBufferSpeciesThis); |
71 } | 69 } |
72 if (%_ArrayBufferGetByteLength(result) < newLen) { | 70 if (%_ArrayBufferGetByteLength(result) < newLen) { |
73 throw MakeTypeError(kArrayBufferTooShort); | 71 throw %make_type_error(kArrayBufferTooShort); |
74 } | 72 } |
75 | 73 |
76 %ArrayBufferSliceImpl(this, result, first, newLen); | 74 %ArrayBufferSliceImpl(this, result, first, newLen); |
77 return result; | 75 return result; |
78 } | 76 } |
79 | 77 |
80 | 78 |
81 function ArrayBufferSpecies() { | 79 function ArrayBufferSpecies() { |
82 return this; | 80 return this; |
83 } | 81 } |
84 | 82 |
85 utils.InstallGetter(GlobalArrayBuffer, speciesSymbol, ArrayBufferSpecies); | 83 utils.InstallGetter(GlobalArrayBuffer, speciesSymbol, ArrayBufferSpecies); |
86 | 84 |
87 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ | 85 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ |
88 "slice", ArrayBufferSlice | 86 "slice", ArrayBufferSlice |
89 ]); | 87 ]); |
90 | 88 |
91 }) | 89 }) |
OLD | NEW |