Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: src/typedarray.js

Issue 1186733002: Add %TypedArray% to proto chain (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 27 matching lines...) Expand all
38 var MathMax; 38 var MathMax;
39 var MathMin; 39 var MathMin;
40 40
41 utils.Import(function(from) { 41 utils.Import(function(from) {
42 MathMax = from.MathMax; 42 MathMax = from.MathMax;
43 MathMin = from.MathMin; 43 MathMin = from.MathMin;
44 }); 44 });
45 45
46 // --------------- Typed Arrays --------------------- 46 // --------------- Typed Arrays ---------------------
47 47
48 function TypedArray() { }
49
50 function TypedArray_GetBuffer() {
51 if (!%IsTypedArray(this)) {
52 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
53 }
54 return %TypedArrayGetBuffer(this);
55 }
56
57 function TypedArray_GetByteLength() {
58 if (!%IsTypedArray(this)) {
59 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
adamk 2015/06/13 00:49:38 s/buffer/byteLength/
Dan Ehrenberg 2015/06/13 05:54:09 Done.
60 }
61 return %_ArrayBufferViewGetByteLength(this);
62 }
63
64 function TypedArray_GetByteOffset() {
65 if (!%IsTypedArray(this)) {
66 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
adamk 2015/06/13 00:49:38 byteOffset
Dan Ehrenberg 2015/06/13 05:54:09 Done.
67 }
68 return %_ArrayBufferViewGetByteOffset(this);
69 }
70
71 function TypedArray_GetLength() {
72 if (!%IsTypedArray(this)) {
adamk 2015/06/13 00:49:38 I don't know if we can afford a runtime call for t
Dan Ehrenberg 2015/06/13 05:54:09 This is sort of unrelated to v8:4182, except in th
73 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
adamk 2015/06/13 00:49:38 length
Dan Ehrenberg 2015/06/13 05:54:09 Done.
74 }
75 return %_TypedArrayGetLength(this);
76 }
77
48 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) 78 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
49 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { 79 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
50 if (!IS_UNDEFINED(byteOffset)) { 80 if (!IS_UNDEFINED(byteOffset)) {
51 byteOffset = 81 byteOffset =
52 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); 82 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength);
53 } 83 }
54 if (!IS_UNDEFINED(length)) { 84 if (!IS_UNDEFINED(length)) {
55 length = $toPositiveInteger(length, kInvalidTypedArrayLength); 85 length = $toPositiveInteger(length, kInvalidTypedArrayLength);
56 } 86 }
57 87
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { 168 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
139 NAMEConstructByLength(this, arg1); 169 NAMEConstructByLength(this, arg1);
140 } else { 170 } else {
141 NAMEConstructByArrayLike(this, arg1); 171 NAMEConstructByArrayLike(this, arg1);
142 } 172 }
143 } else { 173 } else {
144 throw MakeTypeError(kConstructorNotFunction, "NAME") 174 throw MakeTypeError(kConstructorNotFunction, "NAME")
145 } 175 }
146 } 176 }
147 177
148 function NAME_GetBuffer() {
149 if (!(%_ClassOf(this) === 'NAME')) {
150 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this);
151 }
152 return %TypedArrayGetBuffer(this);
153 }
154
155 function NAME_GetByteLength() {
156 if (!(%_ClassOf(this) === 'NAME')) {
157 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteLength", this);
158 }
159 return %_ArrayBufferViewGetByteLength(this);
160 }
161
162 function NAME_GetByteOffset() {
163 if (!(%_ClassOf(this) === 'NAME')) {
164 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteOffset", this);
165 }
166 return %_ArrayBufferViewGetByteOffset(this);
167 }
168
169 function NAME_GetLength() {
170 if (!(%_ClassOf(this) === 'NAME')) {
171 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this);
172 }
173 return %_TypedArrayGetLength(this);
174 }
175
176 function NAMESubArray(begin, end) { 178 function NAMESubArray(begin, end) {
177 if (!(%_ClassOf(this) === 'NAME')) { 179 if (!(%_ClassOf(this) === 'NAME')) {
178 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); 180 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this);
179 } 181 }
180 var beginInt = TO_INTEGER(begin); 182 var beginInt = TO_INTEGER(begin);
181 if (!IS_UNDEFINED(end)) { 183 if (!IS_UNDEFINED(end)) {
182 end = TO_INTEGER(end); 184 end = TO_INTEGER(end);
183 } 185 }
184 186
185 var srcLength = %_TypedArrayGetLength(this); 187 var srcLength = %_TypedArrayGetLength(this);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 315
314 function TypedArrayGetToStringTag() { 316 function TypedArrayGetToStringTag() {
315 if (!%IsTypedArray(this)) return; 317 if (!%IsTypedArray(this)) return;
316 var name = %_ClassOf(this); 318 var name = %_ClassOf(this);
317 if (IS_UNDEFINED(name)) return; 319 if (IS_UNDEFINED(name)) return;
318 return name; 320 return name;
319 } 321 }
320 322
321 // ------------------------------------------------------------------- 323 // -------------------------------------------------------------------
322 324
325 utils.InstallGetter(TypedArray.prototype, "buffer", TypedArray_GetBuffer);
326 utils.InstallGetter(TypedArray.prototype, "byteOffset", TypedArray_GetByteOffset ,
adamk 2015/06/13 00:49:38 Nit: wrap at 80 chars (I don't know why we don't h
Dan Ehrenberg 2015/06/13 05:54:09 Done.
327 DONT_ENUM | DONT_DELETE);
328 utils.InstallGetter(TypedArray.prototype, "byteLength", TypedArray_GetByteLength ,
329 DONT_ENUM | DONT_DELETE);
330 utils.InstallGetter(TypedArray.prototype, "length", TypedArray_GetLength,
331 DONT_ENUM | DONT_DELETE);
332 utils.InstallGetter(TypedArray.prototype, symbolToStringTag,
333 TypedArrayGetToStringTag);
334 utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [
335 "set", TypedArraySet
336 ]);
337
323 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 338 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
324 %SetCode(GlobalNAME, NAMEConstructor); 339 %SetCode(GlobalNAME, NAMEConstructor);
325 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); 340 %InternalSetPrototype(GlobalNAME, TypedArray);
341 %FunctionSetPrototype(GlobalNAME, new TypedArray());
342 %AddNamedProperty(GlobalNAME.prototype,
343 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
344 READ_ONLY | DONT_ENUM | DONT_DELETE);
326 345
327 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, 346 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
328 READ_ONLY | DONT_ENUM | DONT_DELETE); 347 READ_ONLY | DONT_ENUM | DONT_DELETE);
329 %AddNamedProperty(GlobalNAME.prototype, 348 %AddNamedProperty(GlobalNAME.prototype,
330 "constructor", global.NAME, DONT_ENUM); 349 "constructor", global.NAME, DONT_ENUM);
331 %AddNamedProperty(GlobalNAME.prototype,
332 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
333 READ_ONLY | DONT_ENUM | DONT_DELETE);
334 utils.InstallGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer);
335 utils.InstallGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset,
336 DONT_ENUM | DONT_DELETE);
337 utils.InstallGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength,
338 DONT_ENUM | DONT_DELETE);
339 utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength,
340 DONT_ENUM | DONT_DELETE);
341 utils.InstallGetter(GlobalNAME.prototype, symbolToStringTag,
342 TypedArrayGetToStringTag);
343 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ 350 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
344 "subarray", NAMESubArray, 351 "subarray", NAMESubArray
adamk 2015/06/13 00:49:38 I'm guessing this is also blocked on issue 4182?
Dan Ehrenberg 2015/06/13 05:54:09 Yep.
345 "set", TypedArraySet
346 ]); 352 ]);
347 endmacro 353 endmacro
348 354
349 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 355 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
350 356
351 // --------------------------- DataView ----------------------------- 357 // --------------------------- DataView -----------------------------
352 358
353 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 359 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
354 if (%_IsConstructCall()) { 360 if (%_IsConstructCall()) {
355 // TODO(binji): support SharedArrayBuffers? 361 // TODO(binji): support SharedArrayBuffers?
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 "getUint32", DataViewGetUint32JS, 478 "getUint32", DataViewGetUint32JS,
473 "setUint32", DataViewSetUint32JS, 479 "setUint32", DataViewSetUint32JS,
474 480
475 "getFloat32", DataViewGetFloat32JS, 481 "getFloat32", DataViewGetFloat32JS,
476 "setFloat32", DataViewSetFloat32JS, 482 "setFloat32", DataViewSetFloat32JS,
477 483
478 "getFloat64", DataViewGetFloat64JS, 484 "getFloat64", DataViewGetFloat64JS,
479 "setFloat64", DataViewSetFloat64JS 485 "setFloat64", DataViewSetFloat64JS
480 ]); 486 ]);
481 487
488 // -------------------------------------------------------------------
489 // Exports
490
491 utils.Export(function(to) {
492 to.TypedArray = TypedArray;
493 to.TypedArrayPrototype = TypedArray.prototype;
494 });
495
482 }) 496 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698