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

Side by Side Diff: src/typedarray.js

Issue 1118273004: Migrate error messages, part 8. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/runtime/runtime-typedarray.cc ('k') | test/mjsunit/messages.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 // 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() { 5 (function() {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 20 matching lines...) Expand all
31 endmacro 31 endmacro
32 32
33 TYPED_ARRAYS(DECLARE_GLOBALS) 33 TYPED_ARRAYS(DECLARE_GLOBALS)
34 34
35 // --------------- Typed Arrays --------------------- 35 // --------------- Typed Arrays ---------------------
36 36
37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) 37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { 38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
39 if (!IS_UNDEFINED(byteOffset)) { 39 if (!IS_UNDEFINED(byteOffset)) {
40 byteOffset = 40 byteOffset =
41 ToPositiveInteger(byteOffset, "invalid_typed_array_length"); 41 ToPositiveInteger(byteOffset, kInvalidTypedArrayLength);
42 } 42 }
43 if (!IS_UNDEFINED(length)) { 43 if (!IS_UNDEFINED(length)) {
44 length = ToPositiveInteger(length, "invalid_typed_array_length"); 44 length = ToPositiveInteger(length, kInvalidTypedArrayLength);
45 } 45 }
46 46
47 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); 47 var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
48 var offset; 48 var offset;
49 if (IS_UNDEFINED(byteOffset)) { 49 if (IS_UNDEFINED(byteOffset)) {
50 offset = 0; 50 offset = 0;
51 } else { 51 } else {
52 offset = byteOffset; 52 offset = byteOffset;
53 53
54 if (offset % ELEMENT_SIZE !== 0) { 54 if (offset % ELEMENT_SIZE !== 0) {
55 throw MakeRangeError("invalid_typed_array_alignment", 55 throw MakeRangeError(kInvalidTypedArrayAlignment,
56 ["start offset", "NAME", ELEMENT_SIZE]); 56 "start offset", "NAME", ELEMENT_SIZE);
57 } 57 }
58 if (offset > bufferByteLength) { 58 if (offset > bufferByteLength) {
59 throw MakeRangeError("invalid_typed_array_offset"); 59 throw MakeRangeError(kInvalidTypedArrayOffset);
60 } 60 }
61 } 61 }
62 62
63 var newByteLength; 63 var newByteLength;
64 var newLength; 64 var newLength;
65 if (IS_UNDEFINED(length)) { 65 if (IS_UNDEFINED(length)) {
66 if (bufferByteLength % ELEMENT_SIZE !== 0) { 66 if (bufferByteLength % ELEMENT_SIZE !== 0) {
67 throw MakeRangeError("invalid_typed_array_alignment", 67 throw MakeRangeError(kInvalidTypedArrayAlignment,
68 ["byte length", "NAME", ELEMENT_SIZE]); 68 "byte length", "NAME", ELEMENT_SIZE);
69 } 69 }
70 newByteLength = bufferByteLength - offset; 70 newByteLength = bufferByteLength - offset;
71 newLength = newByteLength / ELEMENT_SIZE; 71 newLength = newByteLength / ELEMENT_SIZE;
72 } else { 72 } else {
73 var newLength = length; 73 var newLength = length;
74 newByteLength = newLength * ELEMENT_SIZE; 74 newByteLength = newLength * ELEMENT_SIZE;
75 } 75 }
76 if ((offset + newByteLength > bufferByteLength) 76 if ((offset + newByteLength > bufferByteLength)
77 || (newLength > %_MaxSmi())) { 77 || (newLength > %_MaxSmi())) {
78 throw MakeRangeError("invalid_typed_array_length"); 78 throw MakeRangeError(kInvalidTypedArrayLength);
79 } 79 }
80 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); 80 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
81 } 81 }
82 82
83 function NAMEConstructByLength(obj, length) { 83 function NAMEConstructByLength(obj, length) {
84 var l = IS_UNDEFINED(length) ? 84 var l = IS_UNDEFINED(length) ?
85 0 : ToPositiveInteger(length, "invalid_typed_array_length"); 85 0 : ToPositiveInteger(length, kInvalidTypedArrayLength);
86 if (l > %_MaxSmi()) { 86 if (l > %_MaxSmi()) {
87 throw MakeRangeError("invalid_typed_array_length"); 87 throw MakeRangeError(kInvalidTypedArrayLength);
88 } 88 }
89 var byteLength = l * ELEMENT_SIZE; 89 var byteLength = l * ELEMENT_SIZE;
90 if (byteLength > %_TypedArrayMaxSizeInHeap()) { 90 if (byteLength > %_TypedArrayMaxSizeInHeap()) {
91 var buffer = new GlobalArrayBuffer(byteLength); 91 var buffer = new GlobalArrayBuffer(byteLength);
92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); 92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
93 } else { 93 } else {
94 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); 94 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength);
95 } 95 }
96 } 96 }
97 97
98 function NAMEConstructByArrayLike(obj, arrayLike) { 98 function NAMEConstructByArrayLike(obj, arrayLike) {
99 var length = arrayLike.length; 99 var length = arrayLike.length;
100 var l = ToPositiveInteger(length, "invalid_typed_array_length"); 100 var l = ToPositiveInteger(length, kInvalidTypedArrayLength);
101 101
102 if (l > %_MaxSmi()) { 102 if (l > %_MaxSmi()) {
103 throw MakeRangeError("invalid_typed_array_length"); 103 throw MakeRangeError(kInvalidTypedArrayLength);
104 } 104 }
105 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { 105 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
106 for (var i = 0; i < l; i++) { 106 for (var i = 0; i < l; i++) {
107 // It is crucial that we let any execptions from arrayLike[i] 107 // It is crucial that we let any execptions from arrayLike[i]
108 // propagate outside the function. 108 // propagate outside the function.
109 obj[i] = arrayLike[i]; 109 obj[i] = arrayLike[i];
110 } 110 }
111 } 111 }
112 } 112 }
113 113
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 for (var i = leftIndex; i <= rightIndex; i++) { 250 for (var i = leftIndex; i <= rightIndex; i++) {
251 temp[i - leftIndex] = source[i]; 251 temp[i - leftIndex] = source[i];
252 } 252 }
253 for (i = leftIndex; i <= rightIndex; i++) { 253 for (i = leftIndex; i <= rightIndex; i++) {
254 target[offset + i] = temp[i - leftIndex]; 254 target[offset + i] = temp[i - leftIndex];
255 } 255 }
256 } 256 }
257 257
258 function TypedArraySet(obj, offset) { 258 function TypedArraySet(obj, offset) {
259 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); 259 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
260 if (intOffset < 0) { 260 if (intOffset < 0) throw MakeTypeError(kTypedArraySetNegativeOffset);
261 throw MakeTypeError("typed_array_set_negative_offset");
262 }
263 261
264 if (intOffset > %_MaxSmi()) { 262 if (intOffset > %_MaxSmi()) {
265 throw MakeRangeError("typed_array_set_source_too_large"); 263 throw MakeRangeError(kTypedArraySetSourceTooLarge);
266 } 264 }
267 switch (%TypedArraySetFastCases(this, obj, intOffset)) { 265 switch (%TypedArraySetFastCases(this, obj, intOffset)) {
268 // These numbers should be synchronized with runtime.cc. 266 // These numbers should be synchronized with runtime.cc.
269 case 0: // TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE 267 case 0: // TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE
270 return; 268 return;
271 case 1: // TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING 269 case 1: // TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING
272 TypedArraySetFromOverlappingTypedArray(this, obj, intOffset); 270 TypedArraySetFromOverlappingTypedArray(this, obj, intOffset);
273 return; 271 return;
274 case 2: // TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING 272 case 2: // TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING
275 TypedArraySetFromArrayLike(this, obj, obj.length, intOffset); 273 TypedArraySetFromArrayLike(this, obj, obj.length, intOffset);
276 return; 274 return;
277 case 3: // TYPED_ARRAY_SET_NON_TYPED_ARRAY 275 case 3: // TYPED_ARRAY_SET_NON_TYPED_ARRAY
278 var l = obj.length; 276 var l = obj.length;
279 if (IS_UNDEFINED(l)) { 277 if (IS_UNDEFINED(l)) {
280 if (IS_NUMBER(obj)) { 278 if (IS_NUMBER(obj)) {
281 // For number as a first argument, throw TypeError 279 // For number as a first argument, throw TypeError
282 // instead of silently ignoring the call, so that 280 // instead of silently ignoring the call, so that
283 // the user knows (s)he did something wrong. 281 // the user knows (s)he did something wrong.
284 // (Consistent with Firefox and Blink/WebKit) 282 // (Consistent with Firefox and Blink/WebKit)
285 throw MakeTypeError("invalid_argument"); 283 throw MakeTypeError(kInvalidArgument);
286 } 284 }
287 return; 285 return;
288 } 286 }
289 if (intOffset + l > this.length) { 287 if (intOffset + l > this.length) {
290 throw MakeRangeError("typed_array_set_source_too_large"); 288 throw MakeRangeError(kTypedArraySetSourceTooLarge);
291 } 289 }
292 TypedArraySetFromArrayLike(this, obj, l, intOffset); 290 TypedArraySetFromArrayLike(this, obj, l, intOffset);
293 return; 291 return;
294 } 292 }
295 } 293 }
296 294
297 function TypedArrayGetToStringTag() { 295 function TypedArrayGetToStringTag() {
298 if (!%IsTypedArray(this)) return; 296 if (!%IsTypedArray(this)) return;
299 var name = %_ClassOf(this); 297 var name = %_ClassOf(this);
300 if (IS_UNDEFINED(name)) return; 298 if (IS_UNDEFINED(name)) return;
(...skipping 27 matching lines...) Expand all
328 "set", TypedArraySet 326 "set", TypedArraySet
329 ]); 327 ]);
330 endmacro 328 endmacro
331 329
332 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 330 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
333 331
334 // --------------------------- DataView ----------------------------- 332 // --------------------------- DataView -----------------------------
335 333
336 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
337 if (%_IsConstructCall()) { 335 if (%_IsConstructCall()) {
338 if (!IS_ARRAYBUFFER(buffer)) { 336 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer);
339 throw MakeTypeError('data_view_not_array_buffer', []);
340 }
341 if (!IS_UNDEFINED(byteOffset)) { 337 if (!IS_UNDEFINED(byteOffset)) {
342 byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); 338 byteOffset = ToPositiveInteger(byteOffset, kInvalidDataViewOffset);
343 } 339 }
344 if (!IS_UNDEFINED(byteLength)) { 340 if (!IS_UNDEFINED(byteLength)) {
345 byteLength = TO_INTEGER(byteLength); 341 byteLength = TO_INTEGER(byteLength);
346 } 342 }
347 343
348 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); 344 var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
349 345
350 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; 346 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset;
351 if (offset > bufferByteLength) { 347 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset);
352 throw MakeRangeError('invalid_data_view_offset');
353 }
354 348
355 var length = IS_UNDEFINED(byteLength) 349 var length = IS_UNDEFINED(byteLength)
356 ? bufferByteLength - offset 350 ? bufferByteLength - offset
357 : byteLength; 351 : byteLength;
358 if (length < 0 || offset + length > bufferByteLength) { 352 if (length < 0 || offset + length > bufferByteLength) {
359 throw new MakeRangeError('invalid_data_view_length'); 353 throw new MakeRangeError(kInvalidDataViewLength);
360 } 354 }
361 %_DataViewInitialize(this, buffer, offset, length); 355 %_DataViewInitialize(this, buffer, offset, length);
362 } else { 356 } else {
363 throw MakeTypeError(kConstructorNotFunction, "DataView"); 357 throw MakeTypeError(kConstructorNotFunction, "DataView");
364 } 358 }
365 } 359 }
366 360
367 function DataViewGetBufferJS() { 361 function DataViewGetBufferJS() {
368 if (!IS_DATAVIEW(this)) { 362 if (!IS_DATAVIEW(this)) {
369 throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this); 363 throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this);
(...skipping 22 matching lines...) Expand all
392 FUNCTION(Uint8) 386 FUNCTION(Uint8)
393 FUNCTION(Int16) 387 FUNCTION(Int16)
394 FUNCTION(Uint16) 388 FUNCTION(Uint16)
395 FUNCTION(Int32) 389 FUNCTION(Int32)
396 FUNCTION(Uint32) 390 FUNCTION(Uint32)
397 FUNCTION(Float32) 391 FUNCTION(Float32)
398 FUNCTION(Float64) 392 FUNCTION(Float64)
399 endmacro 393 endmacro
400 394
401 function ToPositiveDataViewOffset(offset) { 395 function ToPositiveDataViewOffset(offset) {
402 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); 396 return ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
403 } 397 }
404 398
405 399
406 macro DATA_VIEW_GETTER_SETTER(TYPENAME) 400 macro DATA_VIEW_GETTER_SETTER(TYPENAME)
407 function DataViewGetTYPENAMEJS(offset, little_endian) { 401 function DataViewGetTYPENAMEJS(offset, little_endian) {
408 if (!IS_DATAVIEW(this)) { 402 if (!IS_DATAVIEW(this)) {
409 throw MakeTypeError(kIncompatibleMethodReceiver, 403 throw MakeTypeError(kIncompatibleMethodReceiver,
410 'DataView.getTYPENAME', this); 404 'DataView.getTYPENAME', this);
411 } 405 }
412 if (%_ArgumentsLength() < 1) { 406 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument);
413 throw MakeTypeError('invalid_argument');
414 }
415 return %DataViewGetTYPENAME(this, 407 return %DataViewGetTYPENAME(this,
416 ToPositiveDataViewOffset(offset), 408 ToPositiveDataViewOffset(offset),
417 !!little_endian); 409 !!little_endian);
418 } 410 }
419 411
420 function DataViewSetTYPENAMEJS(offset, value, little_endian) { 412 function DataViewSetTYPENAMEJS(offset, value, little_endian) {
421 if (!IS_DATAVIEW(this)) { 413 if (!IS_DATAVIEW(this)) {
422 throw MakeTypeError(kIncompatibleMethodReceiver, 414 throw MakeTypeError(kIncompatibleMethodReceiver,
423 'DataView.setTYPENAME', this); 415 'DataView.setTYPENAME', this);
424 } 416 }
425 if (%_ArgumentsLength() < 2) { 417 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument);
426 throw MakeTypeError('invalid_argument');
427 }
428 %DataViewSetTYPENAME(this, 418 %DataViewSetTYPENAME(this,
429 ToPositiveDataViewOffset(offset), 419 ToPositiveDataViewOffset(offset),
430 TO_NUMBER_INLINE(value), 420 TO_NUMBER_INLINE(value),
431 !!little_endian); 421 !!little_endian);
432 } 422 }
433 endmacro 423 endmacro
434 424
435 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) 425 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
436 426
437 // Setup the DataView constructor. 427 // Setup the DataView constructor.
(...skipping 30 matching lines...) Expand all
468 "setUint32", DataViewSetUint32JS, 458 "setUint32", DataViewSetUint32JS,
469 459
470 "getFloat32", DataViewGetFloat32JS, 460 "getFloat32", DataViewGetFloat32JS,
471 "setFloat32", DataViewSetFloat32JS, 461 "setFloat32", DataViewSetFloat32JS,
472 462
473 "getFloat64", DataViewGetFloat64JS, 463 "getFloat64", DataViewGetFloat64JS,
474 "setFloat64", DataViewSetFloat64JS 464 "setFloat64", DataViewSetFloat64JS
475 ]); 465 ]);
476 466
477 })(); 467 })();
OLDNEW
« no previous file with comments | « src/runtime/runtime-typedarray.cc ('k') | test/mjsunit/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698