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; | |
16 var MakeTypeError; | 15 var MakeTypeError; |
17 var MaxSimple; | 16 var MaxSimple; |
18 var MinSimple; | 17 var MinSimple; |
19 var ToPositiveInteger; | |
20 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | |
21 | 18 |
22 utils.Import(function(from) { | 19 utils.Import(function(from) { |
23 MakeTypeError = from.MakeTypeError; | 20 MakeTypeError = from.MakeTypeError; |
24 MaxSimple = from.MaxSimple; | 21 MaxSimple = from.MaxSimple; |
25 MinSimple = from.MinSimple; | 22 MinSimple = from.MinSimple; |
26 ToPositiveInteger = from.ToPositiveInteger; | |
27 }); | 23 }); |
28 | 24 |
29 // ------------------------------------------------------------------- | 25 // ------------------------------------------------------------------- |
30 | 26 |
31 function ArrayBufferConstructor(length) { // length = 1 | |
32 if (!IS_UNDEFINED(new.target)) { | |
33 var byteLength = ToPositiveInteger(length, kInvalidArrayBufferLength); | |
34 %ArrayBufferInitialize(this, byteLength, kNotShared); | |
35 } else { | |
36 throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer"); | |
37 } | |
38 } | |
39 | |
40 function ArrayBufferGetByteLen() { | 27 function ArrayBufferGetByteLen() { |
41 if (!IS_ARRAYBUFFER(this)) { | 28 if (!IS_ARRAYBUFFER(this)) { |
42 throw MakeTypeError(kIncompatibleMethodReceiver, | 29 throw MakeTypeError(kIncompatibleMethodReceiver, |
43 'ArrayBuffer.prototype.byteLength', this); | 30 'ArrayBuffer.prototype.byteLength', this); |
44 } | 31 } |
45 return %_ArrayBufferGetByteLength(this); | 32 return %_ArrayBufferGetByteLength(this); |
46 } | 33 } |
47 | 34 |
48 // ES6 Draft 15.13.5.5.3 | 35 // ES6 Draft 15.13.5.5.3 |
49 function ArrayBufferSlice(start, end) { | 36 function ArrayBufferSlice(start, end) { |
(...skipping 25 matching lines...) Expand all Loading... |
75 fin = first; | 62 fin = first; |
76 } | 63 } |
77 var newLen = fin - first; | 64 var newLen = fin - first; |
78 // TODO(dslomov): implement inheritance | 65 // TODO(dslomov): implement inheritance |
79 var result = new GlobalArrayBuffer(newLen); | 66 var result = new GlobalArrayBuffer(newLen); |
80 | 67 |
81 %ArrayBufferSliceImpl(this, result, first); | 68 %ArrayBufferSliceImpl(this, result, first); |
82 return result; | 69 return result; |
83 } | 70 } |
84 | 71 |
85 function ArrayBufferIsViewJS(obj) { | |
86 return %ArrayBufferIsView(obj); | |
87 } | |
88 | |
89 | |
90 // Set up the ArrayBuffer constructor function. | |
91 %SetCode(GlobalArrayBuffer, ArrayBufferConstructor); | |
92 %FunctionSetPrototype(GlobalArrayBuffer, new GlobalObject()); | |
93 | |
94 // Set up the constructor property on the ArrayBuffer prototype object. | |
95 %AddNamedProperty( | |
96 GlobalArrayBuffer.prototype, "constructor", GlobalArrayBuffer, DONT_ENUM); | |
97 | |
98 %AddNamedProperty(GlobalArrayBuffer.prototype, | |
99 toStringTagSymbol, "ArrayBuffer", DONT_ENUM | READ_ONLY); | |
100 | |
101 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength", | 72 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength", |
102 ArrayBufferGetByteLen); | 73 ArrayBufferGetByteLen); |
103 | 74 |
104 utils.InstallFunctions(GlobalArrayBuffer, DONT_ENUM, [ | |
105 "isView", ArrayBufferIsViewJS | |
106 ]); | |
107 | |
108 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ | 75 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ |
109 "slice", ArrayBufferSlice | 76 "slice", ArrayBufferSlice |
110 ]); | 77 ]); |
111 | 78 |
112 }) | 79 }) |
OLD | NEW |