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() { | |
6 | |
7 "use strict"; | 5 "use strict"; |
8 | 6 |
9 %CheckIsBootstrapping(); | 7 var $ArrayBuffer = global.ArrayBuffer; |
10 | |
11 var GlobalArrayBuffer = global.ArrayBuffer; | |
12 var GlobalObject = global.Object; | |
13 | 8 |
14 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
15 | 10 |
16 function ArrayBufferConstructor(length) { // length = 1 | 11 function ArrayBufferConstructor(length) { // length = 1 |
17 if (%_IsConstructCall()) { | 12 if (%_IsConstructCall()) { |
18 var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length'); | 13 var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length'); |
19 %ArrayBufferInitialize(this, byteLength); | 14 %ArrayBufferInitialize(this, byteLength); |
20 } else { | 15 } else { |
21 throw MakeTypeError('constructor_not_function', ["ArrayBuffer"]); | 16 throw MakeTypeError('constructor_not_function', ["ArrayBuffer"]); |
22 } | 17 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 fin = $max(byte_length + relativeEnd, 0); | 49 fin = $max(byte_length + relativeEnd, 0); |
55 } else { | 50 } else { |
56 fin = $min(relativeEnd, byte_length); | 51 fin = $min(relativeEnd, byte_length); |
57 } | 52 } |
58 | 53 |
59 if (fin < first) { | 54 if (fin < first) { |
60 fin = first; | 55 fin = first; |
61 } | 56 } |
62 var newLen = fin - first; | 57 var newLen = fin - first; |
63 // TODO(dslomov): implement inheritance | 58 // TODO(dslomov): implement inheritance |
64 var result = new GlobalArrayBuffer(newLen); | 59 var result = new $ArrayBuffer(newLen); |
65 | 60 |
66 %ArrayBufferSliceImpl(this, result, first); | 61 %ArrayBufferSliceImpl(this, result, first); |
67 return result; | 62 return result; |
68 } | 63 } |
69 | 64 |
70 function ArrayBufferIsViewJS(obj) { | 65 function ArrayBufferIsViewJS(obj) { |
71 return %ArrayBufferIsView(obj); | 66 return %ArrayBufferIsView(obj); |
72 } | 67 } |
73 | 68 |
| 69 function SetUpArrayBuffer() { |
| 70 %CheckIsBootstrapping(); |
74 | 71 |
75 // Set up the ArrayBuffer constructor function. | 72 // Set up the ArrayBuffer constructor function. |
76 %SetCode(GlobalArrayBuffer, ArrayBufferConstructor); | 73 %SetCode($ArrayBuffer, ArrayBufferConstructor); |
77 %FunctionSetPrototype(GlobalArrayBuffer, new GlobalObject()); | 74 %FunctionSetPrototype($ArrayBuffer, new $Object()); |
78 | 75 |
79 // Set up the constructor property on the ArrayBuffer prototype object. | 76 // Set up the constructor property on the ArrayBuffer prototype object. |
80 %AddNamedProperty( | 77 %AddNamedProperty( |
81 GlobalArrayBuffer.prototype, "constructor", GlobalArrayBuffer, DONT_ENUM); | 78 $ArrayBuffer.prototype, "constructor", $ArrayBuffer, DONT_ENUM); |
82 | 79 |
83 %AddNamedProperty(GlobalArrayBuffer.prototype, | 80 %AddNamedProperty($ArrayBuffer.prototype, |
84 symbolToStringTag, "ArrayBuffer", DONT_ENUM | READ_ONLY); | 81 symbolToStringTag, "ArrayBuffer", DONT_ENUM | READ_ONLY); |
85 | 82 |
86 InstallGetter(GlobalArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLen); | 83 InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLen); |
87 | 84 |
88 InstallFunctions(GlobalArrayBuffer, DONT_ENUM, [ | 85 InstallFunctions($ArrayBuffer, DONT_ENUM, [ |
89 "isView", ArrayBufferIsViewJS | 86 "isView", ArrayBufferIsViewJS |
90 ]); | 87 ]); |
91 | 88 |
92 InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ | 89 InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, [ |
93 "slice", ArrayBufferSlice | 90 "slice", ArrayBufferSlice |
94 ]); | 91 ]); |
| 92 } |
95 | 93 |
96 })(); | 94 SetUpArrayBuffer(); |
OLD | NEW |