| OLD | NEW |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 if (offset + newByteLength > bufferByteLength) { | 81 if (offset + newByteLength > bufferByteLength) { |
| 82 throw MakeRangeError("invalid_typed_array_length"); | 82 throw MakeRangeError("invalid_typed_array_length"); |
| 83 } | 83 } |
| 84 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); | 84 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); |
| 85 } | 85 } |
| 86 | 86 |
| 87 function NAMEConstructByLength(obj, length) { | 87 function NAMEConstructByLength(obj, length) { |
| 88 var l = IS_UNDEFINED(length) ? | 88 var l = IS_UNDEFINED(length) ? |
| 89 0 : ToPositiveInteger(length, "invalid_typed_array_length"); | 89 0 : ToPositiveInteger(length, "invalid_typed_array_length"); |
| 90 if (l > %MaxSmi()) { |
| 91 throw MakeRangeError("invalid_typed_array_length"); |
| 92 } |
| 90 var byteLength = l * ELEMENT_SIZE; | 93 var byteLength = l * ELEMENT_SIZE; |
| 91 var buffer = new $ArrayBuffer(byteLength); | 94 var buffer = new $ArrayBuffer(byteLength); |
| 92 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 95 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
| 93 } | 96 } |
| 94 | 97 |
| 95 function NAMEConstructByArrayLike(obj, arrayLike) { | 98 function NAMEConstructByArrayLike(obj, arrayLike) { |
| 96 var length = arrayLike.length; | 99 var length = arrayLike.length; |
| 97 var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 100 var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 98 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { | 101 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |
| 99 for (var i = 0; i < l; i++) { | 102 for (var i = 0; i < l; i++) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 302 |
| 300 // --------------------------- DataView ----------------------------- | 303 // --------------------------- DataView ----------------------------- |
| 301 | 304 |
| 302 var $DataView = global.DataView; | 305 var $DataView = global.DataView; |
| 303 | 306 |
| 304 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 307 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| 305 if (%_IsConstructCall()) { | 308 if (%_IsConstructCall()) { |
| 306 if (!IS_ARRAYBUFFER(buffer)) { | 309 if (!IS_ARRAYBUFFER(buffer)) { |
| 307 throw MakeTypeError('data_view_not_array_buffer', []); | 310 throw MakeTypeError('data_view_not_array_buffer', []); |
| 308 } | 311 } |
| 309 var bufferByteLength = %ArrayBufferGetByteLength(buffer); | 312 var bufferByteLength = buffer.byteLength; |
| 310 var offset = IS_UNDEFINED(byteOffset) ? | 313 var offset = IS_UNDEFINED(byteOffset) ? |
| 311 0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); | 314 0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); |
| 312 if (offset > bufferByteLength) { | 315 if (offset > bufferByteLength) { |
| 313 throw MakeRangeError('invalid_data_view_offset'); | 316 throw MakeRangeError('invalid_data_view_offset'); |
| 314 } | 317 } |
| 315 var length = IS_UNDEFINED(byteLength) ? | 318 var length = IS_UNDEFINED(byteLength) ? |
| 316 bufferByteLength - offset : TO_INTEGER(byteLength); | 319 bufferByteLength - offset : TO_INTEGER(byteLength); |
| 317 if (length < 0 || offset + length > bufferByteLength) { | 320 if (length < 0 || offset + length > bufferByteLength) { |
| 318 throw new MakeRangeError('invalid_data_view_length'); | 321 throw new MakeRangeError('invalid_data_view_length'); |
| 319 } | 322 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 340 } | 343 } |
| 341 | 344 |
| 342 function DataViewGetByteLength() { | 345 function DataViewGetByteLength() { |
| 343 if (!IS_DATAVIEW(this)) { | 346 if (!IS_DATAVIEW(this)) { |
| 344 throw MakeTypeError('incompatible_method_receiver', | 347 throw MakeTypeError('incompatible_method_receiver', |
| 345 ['DataView.byteLength', this]); | 348 ['DataView.byteLength', this]); |
| 346 } | 349 } |
| 347 return %DataViewGetByteLength(this); | 350 return %DataViewGetByteLength(this); |
| 348 } | 351 } |
| 349 | 352 |
| 353 macro DATA_VIEW_TYPES(FUNCTION) |
| 354 FUNCTION(Int8) |
| 355 FUNCTION(Uint8) |
| 356 FUNCTION(Int16) |
| 357 FUNCTION(Uint16) |
| 358 FUNCTION(Int32) |
| 359 FUNCTION(Uint32) |
| 360 FUNCTION(Float32) |
| 361 FUNCTION(Float64) |
| 362 endmacro |
| 363 |
| 350 function ToPositiveDataViewOffset(offset) { | 364 function ToPositiveDataViewOffset(offset) { |
| 351 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); | 365 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); |
| 352 } | 366 } |
| 353 | 367 |
| 354 function DataViewGetInt8(offset, little_endian) { | 368 |
| 369 macro DATA_VIEW_GETTER_SETTER(TYPENAME) |
| 370 function DataViewGetTYPENAME(offset, little_endian) { |
| 355 if (!IS_DATAVIEW(this)) { | 371 if (!IS_DATAVIEW(this)) { |
| 356 throw MakeTypeError('incompatible_method_receiver', | 372 throw MakeTypeError('incompatible_method_receiver', |
| 357 ['DataView.getInt8', this]); | 373 ['DataView.getTYPENAME', this]); |
| 358 } | 374 } |
| 359 if (%_ArgumentsLength() < 1) { | 375 if (%_ArgumentsLength() < 1) { |
| 360 throw MakeTypeError('invalid_argument'); | 376 throw MakeTypeError('invalid_argument'); |
| 361 } | 377 } |
| 362 return %DataViewGetInt8(this, | 378 return %DataViewGetTYPENAME(this, |
| 363 ToPositiveDataViewOffset(offset), | 379 ToPositiveDataViewOffset(offset), |
| 364 !!little_endian); | 380 !!little_endian); |
| 365 } | 381 } |
| 366 | 382 |
| 367 function DataViewSetInt8(offset, value, little_endian) { | 383 function DataViewSetTYPENAME(offset, value, little_endian) { |
| 368 if (!IS_DATAVIEW(this)) { | 384 if (!IS_DATAVIEW(this)) { |
| 369 throw MakeTypeError('incompatible_method_receiver', | 385 throw MakeTypeError('incompatible_method_receiver', |
| 370 ['DataView.setInt8', this]); | 386 ['DataView.setTYPENAME', this]); |
| 371 } | 387 } |
| 372 if (%_ArgumentsLength() < 2) { | 388 if (%_ArgumentsLength() < 2) { |
| 373 throw MakeTypeError('invalid_argument'); | 389 throw MakeTypeError('invalid_argument'); |
| 374 } | 390 } |
| 375 %DataViewSetInt8(this, | 391 %DataViewSetTYPENAME(this, |
| 376 ToPositiveDataViewOffset(offset), | 392 ToPositiveDataViewOffset(offset), |
| 377 TO_NUMBER_INLINE(value), | 393 TO_NUMBER_INLINE(value), |
| 378 !!little_endian); | 394 !!little_endian); |
| 379 } | 395 } |
| 396 endmacro |
| 380 | 397 |
| 381 function DataViewGetUint8(offset, little_endian) { | 398 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
| 382 if (!IS_DATAVIEW(this)) { | |
| 383 throw MakeTypeError('incompatible_method_receiver', | |
| 384 ['DataView.getUint8', this]); | |
| 385 } | |
| 386 if (%_ArgumentsLength() < 1) { | |
| 387 throw MakeTypeError('invalid_argument'); | |
| 388 } | |
| 389 return %DataViewGetUint8(this, | |
| 390 ToPositiveDataViewOffset(offset), | |
| 391 !!little_endian); | |
| 392 } | |
| 393 | |
| 394 function DataViewSetUint8(offset, value, little_endian) { | |
| 395 if (!IS_DATAVIEW(this)) { | |
| 396 throw MakeTypeError('incompatible_method_receiver', | |
| 397 ['DataView.setUint8', this]); | |
| 398 } | |
| 399 if (%_ArgumentsLength() < 2) { | |
| 400 throw MakeTypeError('invalid_argument'); | |
| 401 } | |
| 402 %DataViewSetUint8(this, | |
| 403 ToPositiveDataViewOffset(offset), | |
| 404 TO_NUMBER_INLINE(value), | |
| 405 !!little_endian); | |
| 406 } | |
| 407 | |
| 408 function DataViewGetInt16(offset, little_endian) { | |
| 409 if (!IS_DATAVIEW(this)) { | |
| 410 throw MakeTypeError('incompatible_method_receiver', | |
| 411 ['DataView.getInt16', this]); | |
| 412 } | |
| 413 if (%_ArgumentsLength() < 1) { | |
| 414 throw MakeTypeError('invalid_argument'); | |
| 415 } | |
| 416 return %DataViewGetInt16(this, | |
| 417 ToPositiveDataViewOffset(offset), | |
| 418 !!little_endian); | |
| 419 } | |
| 420 | |
| 421 function DataViewSetInt16(offset, value, little_endian) { | |
| 422 if (!IS_DATAVIEW(this)) { | |
| 423 throw MakeTypeError('incompatible_method_receiver', | |
| 424 ['DataView.setInt16', this]); | |
| 425 } | |
| 426 if (%_ArgumentsLength() < 2) { | |
| 427 throw MakeTypeError('invalid_argument'); | |
| 428 } | |
| 429 %DataViewSetInt16(this, | |
| 430 ToPositiveDataViewOffset(offset), | |
| 431 TO_NUMBER_INLINE(value), | |
| 432 !!little_endian); | |
| 433 } | |
| 434 | |
| 435 function DataViewGetUint16(offset, little_endian) { | |
| 436 if (!IS_DATAVIEW(this)) { | |
| 437 throw MakeTypeError('incompatible_method_receiver', | |
| 438 ['DataView.getUint16', this]); | |
| 439 } | |
| 440 if (%_ArgumentsLength() < 1) { | |
| 441 throw MakeTypeError('invalid_argument'); | |
| 442 } | |
| 443 return %DataViewGetUint16(this, | |
| 444 ToPositiveDataViewOffset(offset), | |
| 445 !!little_endian); | |
| 446 } | |
| 447 | |
| 448 function DataViewSetUint16(offset, value, little_endian) { | |
| 449 if (!IS_DATAVIEW(this)) { | |
| 450 throw MakeTypeError('incompatible_method_receiver', | |
| 451 ['DataView.setUint16', this]); | |
| 452 } | |
| 453 if (%_ArgumentsLength() < 2) { | |
| 454 throw MakeTypeError('invalid_argument'); | |
| 455 } | |
| 456 %DataViewSetUint16(this, | |
| 457 ToPositiveDataViewOffset(offset), | |
| 458 TO_NUMBER_INLINE(value), | |
| 459 !!little_endian); | |
| 460 } | |
| 461 | |
| 462 function DataViewGetInt32(offset, little_endian) { | |
| 463 if (!IS_DATAVIEW(this)) { | |
| 464 throw MakeTypeError('incompatible_method_receiver', | |
| 465 ['DataView.getInt32', this]); | |
| 466 } | |
| 467 if (%_ArgumentsLength() < 1) { | |
| 468 throw MakeTypeError('invalid_argument'); | |
| 469 } | |
| 470 return %DataViewGetInt32(this, | |
| 471 ToPositiveDataViewOffset(offset), | |
| 472 !!little_endian); | |
| 473 } | |
| 474 | |
| 475 function DataViewSetInt32(offset, value, little_endian) { | |
| 476 if (!IS_DATAVIEW(this)) { | |
| 477 throw MakeTypeError('incompatible_method_receiver', | |
| 478 ['DataView.setInt32', this]); | |
| 479 } | |
| 480 if (%_ArgumentsLength() < 2) { | |
| 481 throw MakeTypeError('invalid_argument'); | |
| 482 } | |
| 483 %DataViewSetInt32(this, | |
| 484 ToPositiveDataViewOffset(offset), | |
| 485 TO_NUMBER_INLINE(value), | |
| 486 !!little_endian); | |
| 487 } | |
| 488 | |
| 489 function DataViewGetUint32(offset, little_endian) { | |
| 490 if (!IS_DATAVIEW(this)) { | |
| 491 throw MakeTypeError('incompatible_method_receiver', | |
| 492 ['DataView.getUint32', this]); | |
| 493 } | |
| 494 if (%_ArgumentsLength() < 1) { | |
| 495 throw MakeTypeError('invalid_argument'); | |
| 496 } | |
| 497 return %DataViewGetUint32(this, | |
| 498 ToPositiveDataViewOffset(offset), | |
| 499 !!little_endian); | |
| 500 } | |
| 501 | |
| 502 function DataViewSetUint32(offset, value, little_endian) { | |
| 503 if (!IS_DATAVIEW(this)) { | |
| 504 throw MakeTypeError('incompatible_method_receiver', | |
| 505 ['DataView.setUint32', this]); | |
| 506 } | |
| 507 if (%_ArgumentsLength() < 2) { | |
| 508 throw MakeTypeError('invalid_argument'); | |
| 509 } | |
| 510 %DataViewSetUint32(this, | |
| 511 ToPositiveDataViewOffset(offset), | |
| 512 TO_NUMBER_INLINE(value), | |
| 513 !!little_endian); | |
| 514 } | |
| 515 | |
| 516 function DataViewGetFloat32(offset, little_endian) { | |
| 517 if (!IS_DATAVIEW(this)) { | |
| 518 throw MakeTypeError('incompatible_method_receiver', | |
| 519 ['DataView.getFloat32', this]); | |
| 520 } | |
| 521 if (%_ArgumentsLength() < 1) { | |
| 522 throw MakeTypeError('invalid_argument'); | |
| 523 } | |
| 524 return %DataViewGetFloat32(this, | |
| 525 ToPositiveDataViewOffset(offset), | |
| 526 !!little_endian); | |
| 527 } | |
| 528 | |
| 529 function DataViewSetFloat32(offset, value, little_endian) { | |
| 530 if (!IS_DATAVIEW(this)) { | |
| 531 throw MakeTypeError('incompatible_method_receiver', | |
| 532 ['DataView.setFloat32', this]); | |
| 533 } | |
| 534 if (%_ArgumentsLength() < 2) { | |
| 535 throw MakeTypeError('invalid_argument'); | |
| 536 } | |
| 537 %DataViewSetFloat32(this, | |
| 538 ToPositiveDataViewOffset(offset), | |
| 539 TO_NUMBER_INLINE(value), | |
| 540 !!little_endian); | |
| 541 } | |
| 542 | |
| 543 function DataViewGetFloat64(offset, little_endian) { | |
| 544 if (!IS_DATAVIEW(this)) { | |
| 545 throw MakeTypeError('incompatible_method_receiver', | |
| 546 ['DataView.getFloat64', this]); | |
| 547 } | |
| 548 if (%_ArgumentsLength() < 1) { | |
| 549 throw MakeTypeError('invalid_argument'); | |
| 550 } | |
| 551 return %DataViewGetFloat64(this, | |
| 552 ToPositiveDataViewOffset(offset), | |
| 553 !!little_endian); | |
| 554 } | |
| 555 | |
| 556 function DataViewSetFloat64(offset, value, little_endian) { | |
| 557 if (!IS_DATAVIEW(this)) { | |
| 558 throw MakeTypeError('incompatible_method_receiver', | |
| 559 ['DataView.setFloat64', this]); | |
| 560 } | |
| 561 if (%_ArgumentsLength() < 2) { | |
| 562 throw MakeTypeError('invalid_argument'); | |
| 563 } | |
| 564 %DataViewSetFloat64(this, | |
| 565 ToPositiveDataViewOffset(offset), | |
| 566 TO_NUMBER_INLINE(value), | |
| 567 !!little_endian); | |
| 568 } | |
| 569 | 399 |
| 570 function SetupDataView() { | 400 function SetupDataView() { |
| 571 %CheckIsBootstrapping(); | 401 %CheckIsBootstrapping(); |
| 572 | 402 |
| 573 // Setup the DataView constructor. | 403 // Setup the DataView constructor. |
| 574 %SetCode($DataView, DataViewConstructor); | 404 %SetCode($DataView, DataViewConstructor); |
| 575 %FunctionSetPrototype($DataView, new $Object); | 405 %FunctionSetPrototype($DataView, new $Object); |
| 576 | 406 |
| 577 // Set up constructor property on the DataView prototype. | 407 // Set up constructor property on the DataView prototype. |
| 578 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); | 408 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 602 | 432 |
| 603 "getFloat32", DataViewGetFloat32, | 433 "getFloat32", DataViewGetFloat32, |
| 604 "setFloat32", DataViewSetFloat32, | 434 "setFloat32", DataViewSetFloat32, |
| 605 | 435 |
| 606 "getFloat64", DataViewGetFloat64, | 436 "getFloat64", DataViewGetFloat64, |
| 607 "setFloat64", DataViewSetFloat64 | 437 "setFloat64", DataViewSetFloat64 |
| 608 )); | 438 )); |
| 609 } | 439 } |
| 610 | 440 |
| 611 SetupDataView(); | 441 SetupDataView(); |
| OLD | NEW |