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

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: fix adam's issues 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.byteLength", th is);
arv (Not doing code reviews) 2015/06/15 16:23:12 long line
Dan Ehrenberg 2015/06/15 23:28:34 Done.
60 }
61 return %_ArrayBufferViewGetByteLength(this);
62 }
63
64 function TypedArray_GetByteOffset() {
65 if (!%IsTypedArray(this)) {
66 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteOffset", th is);
67 }
68 return %_ArrayBufferViewGetByteOffset(this);
69 }
70
71 function TypedArray_GetLength() {
72 if (!%IsTypedArray(this)) {
73 throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.length", this);
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",
327 TypedArray_GetByteOffset, DONT_ENUM | DONT_DELETE);
arv (Not doing code reviews) 2015/06/15 16:23:12 why DONT_DELETE?
Dan Ehrenberg 2015/06/15 23:28:34 Oops, fixed it.
328 utils.InstallGetter(TypedArray.prototype, "byteLength",
329 TypedArray_GetByteLength, DONT_ENUM | DONT_DELETE);
arv (Not doing code reviews) 2015/06/15 16:23:12 same here and other places. We should also have te
Dan Ehrenberg 2015/06/15 23:28:34 Done.
330 utils.InstallGetter(TypedArray.prototype, "length", TypedArray_GetLength,
331 DONT_ENUM | DONT_DELETE);
332 utils.InstallGetter(TypedArray.prototype, symbolToStringTag,
333 TypedArrayGetToStringTag);
arv (Not doing code reviews) 2015/06/15 16:23:12 DONT_ENUM?
Dan Ehrenberg 2015/06/15 23:28:34 Done.
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
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
482 }) 488 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698