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

Side by Side Diff: src/typedarray.js

Issue 21924007: Make new Harmony constructors subclassing-friendly (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/collections.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 var length = arrayLike.length; 78 var length = arrayLike.length;
79 var l = ToPositiveInteger(length, "invalid_typed_array_length"); 79 var l = ToPositiveInteger(length, "invalid_typed_array_length");
80 if(!%TypedArrayInitializeFromArrayLike(obj, arrayId, arrayLike, l)) { 80 if(!%TypedArrayInitializeFromArrayLike(obj, arrayId, arrayLike, l)) {
81 for (var i = 0; i < l; i++) { 81 for (var i = 0; i < l; i++) {
82 obj[i] = arrayLike[i]; 82 obj[i] = arrayLike[i];
83 } 83 }
84 } 84 }
85 } 85 }
86 86
87 return function (arg1, arg2, arg3) { 87 return function (arg1, arg2, arg3) {
88 if (%_IsConstructCall()) { 88 if (IS_ARRAYBUFFER(arg1)) {
89 if (IS_ARRAYBUFFER(arg1)) { 89 ConstructByArrayBuffer(this, arg1, arg2, arg3);
90 ConstructByArrayBuffer(this, arg1, arg2, arg3); 90 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
91 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || 91 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
92 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { 92 ConstructByLength(this, arg1);
93 ConstructByLength(this, arg1);
94 } else {
95 ConstructByArrayLike(this, arg1);
96 }
97 } else { 93 } else {
98 throw MakeTypeError("constructor_not_function", [name]) 94 ConstructByArrayLike(this, arg1);
99 } 95 }
100 } 96 }
101 } 97 }
102 98
103 function TypedArrayGetBuffer() { 99 function TypedArrayGetBuffer() {
104 return %TypedArrayGetBuffer(this); 100 return %TypedArrayGetBuffer(this);
105 } 101 }
106 102
107 function TypedArrayGetByteLength() { 103 function TypedArrayGetByteLength() {
108 return %TypedArrayGetByteLength(this); 104 return %TypedArrayGetByteLength(this);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); 276 SetupTypedArray(7, "Float32Array", global.Float32Array, 4);
281 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); 277 SetupTypedArray(8, "Float64Array", global.Float64Array, 8);
282 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); 278 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1);
283 279
284 280
285 // --------------------------- DataView ----------------------------- 281 // --------------------------- DataView -----------------------------
286 282
287 var $DataView = global.DataView; 283 var $DataView = global.DataView;
288 284
289 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 285 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
290 if (%_IsConstructCall()) { 286 if (!IS_ARRAYBUFFER(buffer)) {
291 if (!IS_ARRAYBUFFER(buffer)) { 287 throw MakeTypeError('data_view_not_array_buffer', []);
292 throw MakeTypeError('data_view_not_array_buffer', []);
293 }
294 var bufferByteLength = %ArrayBufferGetByteLength(buffer);
295 var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
296 if (offset > bufferByteLength) {
297 throw MakeRangeError('invalid_data_view_offset');
298 }
299 var length = IS_UNDEFINED(byteLength) ?
300 bufferByteLength - offset : TO_INTEGER(byteLength);
301 if (length < 0 || offset + length > bufferByteLength) {
302 throw new MakeRangeError('invalid_data_view_length');
303 }
304 %DataViewInitialize(this, buffer, offset, length);
305 } else {
306 throw MakeTypeError('constructor_not_function', ["DataView"]);
307 } 288 }
289 var bufferByteLength = %ArrayBufferGetByteLength(buffer);
290 var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
291 if (offset > bufferByteLength) {
292 throw MakeRangeError('invalid_data_view_offset');
293 }
294 var length = IS_UNDEFINED(byteLength) ?
295 bufferByteLength - offset : TO_INTEGER(byteLength);
296 if (length < 0 || offset + length > bufferByteLength) {
297 throw new MakeRangeError('invalid_data_view_length');
298 }
299 %DataViewInitialize(this, buffer, offset, length);
308 } 300 }
309 301
310 function DataViewGetBuffer() { 302 function DataViewGetBuffer() {
311 if (!IS_DATAVIEW(this)) { 303 if (!IS_DATAVIEW(this)) {
312 throw MakeTypeError('incompatible_method_receiver', 304 throw MakeTypeError('incompatible_method_receiver',
313 ['DataView.buffer', this]); 305 ['DataView.buffer', this]);
314 } 306 }
315 return %DataViewGetBuffer(this); 307 return %DataViewGetBuffer(this);
316 } 308 }
317 309
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 578
587 "getFloat32", DataViewGetFloat32, 579 "getFloat32", DataViewGetFloat32,
588 "setFloat32", DataViewSetFloat32, 580 "setFloat32", DataViewSetFloat32,
589 581
590 "getFloat64", DataViewGetFloat64, 582 "getFloat64", DataViewGetFloat64,
591 "setFloat64", DataViewSetFloat64 583 "setFloat64", DataViewSetFloat64
592 )); 584 ));
593 } 585 }
594 586
595 SetupDataView(); 587 SetupDataView();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/collections.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698