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; | 15 var MakeTypeError; |
16 var MaxSimple; | 16 var MaxSimple; |
17 var MinSimple; | 17 var MinSimple; |
18 var SpeciesConstructor; | |
18 | 19 |
19 utils.Import(function(from) { | 20 utils.Import(function(from) { |
20 MakeTypeError = from.MakeTypeError; | 21 MakeTypeError = from.MakeTypeError; |
21 MaxSimple = from.MaxSimple; | 22 MaxSimple = from.MaxSimple; |
22 MinSimple = from.MinSimple; | 23 MinSimple = from.MinSimple; |
24 SpeciesConstructor = from.SpeciesConstructor; | |
23 }); | 25 }); |
24 | 26 |
25 // ------------------------------------------------------------------- | 27 // ------------------------------------------------------------------- |
26 | 28 |
27 function ArrayBufferGetByteLen() { | 29 function ArrayBufferGetByteLen() { |
28 if (!IS_ARRAYBUFFER(this)) { | 30 if (!IS_ARRAYBUFFER(this)) { |
29 throw MakeTypeError(kIncompatibleMethodReceiver, | 31 throw MakeTypeError(kIncompatibleMethodReceiver, |
30 'ArrayBuffer.prototype.byteLength', this); | 32 'ArrayBuffer.prototype.byteLength', this); |
31 } | 33 } |
32 return %_ArrayBufferGetByteLength(this); | 34 return %_ArrayBufferGetByteLength(this); |
(...skipping 22 matching lines...) Expand all Loading... | |
55 if (relativeEnd < 0) { | 57 if (relativeEnd < 0) { |
56 fin = MaxSimple(byte_length + relativeEnd, 0); | 58 fin = MaxSimple(byte_length + relativeEnd, 0); |
57 } else { | 59 } else { |
58 fin = MinSimple(relativeEnd, byte_length); | 60 fin = MinSimple(relativeEnd, byte_length); |
59 } | 61 } |
60 | 62 |
61 if (fin < first) { | 63 if (fin < first) { |
62 fin = first; | 64 fin = first; |
63 } | 65 } |
64 var newLen = fin - first; | 66 var newLen = fin - first; |
65 // TODO(dslomov): implement inheritance | 67 var constructor = SpeciesConstructor(this, GlobalArrayBuffer, true); |
66 var result = new GlobalArrayBuffer(newLen); | 68 var result = new constructor(newLen); |
69 if (!IS_ARRAYBUFFER(result)) { | |
adamk
2016/01/12 00:11:00
Is this exercised in some test?
Dan Ehrenberg
2016/01/12 01:38:33
Test262, but that's not active yet so I wrote anot
| |
70 throw MakeTypeError(kIncompatibleMethodReceiver, | |
71 'ArrayBuffer.prototype.slice', result); | |
72 } | |
73 if (%_ArrayBufferGetByteLength(result) < newLen) { | |
adamk
2016/01/12 00:11:00
And this? Same question about most of these error
Dan Ehrenberg
2016/01/12 01:38:33
Oops, I forgot to add the file test/mjsunit/harmon
| |
74 throw MakeTypeError(kArrayBufferTooShort); | |
75 } | |
76 if (result === this) { | |
adamk
2016/01/12 00:11:00
FWIW this check precedes the byte length check in
Dan Ehrenberg
2016/01/12 01:38:33
Was in test262, added an mjsunit test for it.
| |
77 throw MakeTypeError(kArrayBufferSpeciesThis); | |
78 } | |
67 | 79 |
68 %ArrayBufferSliceImpl(this, result, first); | 80 %ArrayBufferSliceImpl(this, result, first, newLen); |
69 return result; | 81 return result; |
70 } | 82 } |
71 | 83 |
72 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength", | 84 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength", |
73 ArrayBufferGetByteLen); | 85 ArrayBufferGetByteLen); |
74 | 86 |
75 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ | 87 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ |
76 "slice", ArrayBufferSlice | 88 "slice", ArrayBufferSlice |
77 ]); | 89 ]); |
78 | 90 |
79 }) | 91 }) |
OLD | NEW |