| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 function TypedArraySet(obj, offset) { | 147 function TypedArraySet(obj, offset) { |
| 148 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); | 148 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); |
| 149 if (intOffset < 0) { | 149 if (intOffset < 0) { |
| 150 throw MakeTypeError("typed_array_set_negative_offset"); | 150 throw MakeTypeError("typed_array_set_negative_offset"); |
| 151 } | 151 } |
| 152 if (%TypedArraySetFastCases(this, obj, intOffset)) | 152 if (%TypedArraySetFastCases(this, obj, intOffset)) |
| 153 return; | 153 return; |
| 154 | 154 |
| 155 var l = obj.length; | 155 var l = obj.length; |
| 156 if (IS_UNDEFINED(l)) { | 156 if (IS_UNDEFINED(l)) { |
| 157 throw MakeTypeError("invalid_argument"); | 157 if (IS_NUMBER(obj)) { |
| 158 // For number as a first argument, throw TypeError |
| 159 // instead of silently ignoring the call, so that |
| 160 // the user knows (s)he did something wrong. |
| 161 // (Consistent with Firefox and Blink/WebKit) |
| 162 throw MakeTypeError("invalid_argument"); |
| 163 } |
| 164 return; |
| 158 } | 165 } |
| 159 if (intOffset + l > this.length) { | 166 if (intOffset + l > this.length) { |
| 160 throw MakeRangeError("typed_array_set_source_too_large"); | 167 throw MakeRangeError("typed_array_set_source_too_large"); |
| 161 } | 168 } |
| 162 for (var i = 0; i < l; i++) { | 169 for (var i = 0; i < l; i++) { |
| 163 this[intOffset + i] = obj[i]; | 170 this[intOffset + i] = obj[i]; |
| 164 } | 171 } |
| 165 } | 172 } |
| 166 | 173 |
| 167 // ------------------------------------------------------------------- | 174 // ------------------------------------------------------------------- |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 259 |
| 253 function ToPositiveDataViewOffset(offset) { | 260 function ToPositiveDataViewOffset(offset) { |
| 254 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); | 261 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); |
| 255 } | 262 } |
| 256 | 263 |
| 257 function DataViewGetInt8(offset, little_endian) { | 264 function DataViewGetInt8(offset, little_endian) { |
| 258 if (!IS_DATAVIEW(this)) { | 265 if (!IS_DATAVIEW(this)) { |
| 259 throw MakeTypeError('incompatible_method_reciever', | 266 throw MakeTypeError('incompatible_method_reciever', |
| 260 ['DataView.getInt8', this]); | 267 ['DataView.getInt8', this]); |
| 261 } | 268 } |
| 269 if (%_ArgumentsLength() < 1) { |
| 270 throw MakeTypeError('invalid_argument'); |
| 271 } |
| 262 return %DataViewGetInt8(this, | 272 return %DataViewGetInt8(this, |
| 263 ToPositiveDataViewOffset(offset), | 273 ToPositiveDataViewOffset(offset), |
| 264 !!little_endian); | 274 !!little_endian); |
| 265 } | 275 } |
| 266 | 276 |
| 267 function DataViewSetInt8(offset, value, little_endian) { | 277 function DataViewSetInt8(offset, value, little_endian) { |
| 268 if (!IS_DATAVIEW(this)) { | 278 if (!IS_DATAVIEW(this)) { |
| 269 throw MakeTypeError('incompatible_method_reciever', | 279 throw MakeTypeError('incompatible_method_reciever', |
| 270 ['DataView.setInt8', this]); | 280 ['DataView.setInt8', this]); |
| 271 } | 281 } |
| 282 if (%_ArgumentsLength() < 1) { |
| 283 throw MakeTypeError('invalid_argument'); |
| 284 } |
| 272 %DataViewSetInt8(this, | 285 %DataViewSetInt8(this, |
| 273 ToPositiveDataViewOffset(offset), | 286 ToPositiveDataViewOffset(offset), |
| 274 TO_NUMBER_INLINE(value), | 287 TO_NUMBER_INLINE(value), |
| 275 !!little_endian); | 288 !!little_endian); |
| 276 } | 289 } |
| 277 | 290 |
| 278 function DataViewGetUint8(offset, little_endian) { | 291 function DataViewGetUint8(offset, little_endian) { |
| 279 if (!IS_DATAVIEW(this)) { | 292 if (!IS_DATAVIEW(this)) { |
| 280 throw MakeTypeError('incompatible_method_reciever', | 293 throw MakeTypeError('incompatible_method_reciever', |
| 281 ['DataView.getUint8', this]); | 294 ['DataView.getUint8', this]); |
| 282 } | 295 } |
| 296 if (%_ArgumentsLength() < 1) { |
| 297 throw MakeTypeError('invalid_argument'); |
| 298 } |
| 283 return %DataViewGetUint8(this, | 299 return %DataViewGetUint8(this, |
| 284 ToPositiveDataViewOffset(offset), | 300 ToPositiveDataViewOffset(offset), |
| 285 !!little_endian); | 301 !!little_endian); |
| 286 } | 302 } |
| 287 | 303 |
| 288 function DataViewSetUint8(offset, value, little_endian) { | 304 function DataViewSetUint8(offset, value, little_endian) { |
| 289 if (!IS_DATAVIEW(this)) { | 305 if (!IS_DATAVIEW(this)) { |
| 290 throw MakeTypeError('incompatible_method_reciever', | 306 throw MakeTypeError('incompatible_method_reciever', |
| 291 ['DataView.setUint8', this]); | 307 ['DataView.setUint8', this]); |
| 292 } | 308 } |
| 309 if (%_ArgumentsLength() < 1) { |
| 310 throw MakeTypeError('invalid_argument'); |
| 311 } |
| 293 %DataViewSetUint8(this, | 312 %DataViewSetUint8(this, |
| 294 ToPositiveDataViewOffset(offset), | 313 ToPositiveDataViewOffset(offset), |
| 295 TO_NUMBER_INLINE(value), | 314 TO_NUMBER_INLINE(value), |
| 296 !!little_endian); | 315 !!little_endian); |
| 297 } | 316 } |
| 298 | 317 |
| 299 function DataViewGetInt16(offset, little_endian) { | 318 function DataViewGetInt16(offset, little_endian) { |
| 300 if (!IS_DATAVIEW(this)) { | 319 if (!IS_DATAVIEW(this)) { |
| 301 throw MakeTypeError('incompatible_method_reciever', | 320 throw MakeTypeError('incompatible_method_reciever', |
| 302 ['DataView.getInt16', this]); | 321 ['DataView.getInt16', this]); |
| 303 } | 322 } |
| 323 if (%_ArgumentsLength() < 1) { |
| 324 throw MakeTypeError('invalid_argument'); |
| 325 } |
| 304 return %DataViewGetInt16(this, | 326 return %DataViewGetInt16(this, |
| 305 ToPositiveDataViewOffset(offset), | 327 ToPositiveDataViewOffset(offset), |
| 306 !!little_endian); | 328 !!little_endian); |
| 307 } | 329 } |
| 308 | 330 |
| 309 function DataViewSetInt16(offset, value, little_endian) { | 331 function DataViewSetInt16(offset, value, little_endian) { |
| 310 if (!IS_DATAVIEW(this)) { | 332 if (!IS_DATAVIEW(this)) { |
| 311 throw MakeTypeError('incompatible_method_reciever', | 333 throw MakeTypeError('incompatible_method_reciever', |
| 312 ['DataView.setInt16', this]); | 334 ['DataView.setInt16', this]); |
| 313 } | 335 } |
| 336 if (%_ArgumentsLength() < 1) { |
| 337 throw MakeTypeError('invalid_argument'); |
| 338 } |
| 314 %DataViewSetInt16(this, | 339 %DataViewSetInt16(this, |
| 315 ToPositiveDataViewOffset(offset), | 340 ToPositiveDataViewOffset(offset), |
| 316 TO_NUMBER_INLINE(value), | 341 TO_NUMBER_INLINE(value), |
| 317 !!little_endian); | 342 !!little_endian); |
| 318 } | 343 } |
| 319 | 344 |
| 320 function DataViewGetUint16(offset, little_endian) { | 345 function DataViewGetUint16(offset, little_endian) { |
| 321 if (!IS_DATAVIEW(this)) { | 346 if (!IS_DATAVIEW(this)) { |
| 322 throw MakeTypeError('incompatible_method_reciever', | 347 throw MakeTypeError('incompatible_method_reciever', |
| 323 ['DataView.getUint16', this]); | 348 ['DataView.getUint16', this]); |
| 324 } | 349 } |
| 350 if (%_ArgumentsLength() < 1) { |
| 351 throw MakeTypeError('invalid_argument'); |
| 352 } |
| 325 return %DataViewGetUint16(this, | 353 return %DataViewGetUint16(this, |
| 326 ToPositiveDataViewOffset(offset), | 354 ToPositiveDataViewOffset(offset), |
| 327 !!little_endian); | 355 !!little_endian); |
| 328 } | 356 } |
| 329 | 357 |
| 330 function DataViewSetUint16(offset, value, little_endian) { | 358 function DataViewSetUint16(offset, value, little_endian) { |
| 331 if (!IS_DATAVIEW(this)) { | 359 if (!IS_DATAVIEW(this)) { |
| 332 throw MakeTypeError('incompatible_method_reciever', | 360 throw MakeTypeError('incompatible_method_reciever', |
| 333 ['DataView.setUint16', this]); | 361 ['DataView.setUint16', this]); |
| 334 } | 362 } |
| 363 if (%_ArgumentsLength() < 1) { |
| 364 throw MakeTypeError('invalid_argument'); |
| 365 } |
| 335 %DataViewSetUint16(this, | 366 %DataViewSetUint16(this, |
| 336 ToPositiveDataViewOffset(offset), | 367 ToPositiveDataViewOffset(offset), |
| 337 TO_NUMBER_INLINE(value), | 368 TO_NUMBER_INLINE(value), |
| 338 !!little_endian); | 369 !!little_endian); |
| 339 } | 370 } |
| 340 | 371 |
| 341 function DataViewGetInt32(offset, little_endian) { | 372 function DataViewGetInt32(offset, little_endian) { |
| 342 if (!IS_DATAVIEW(this)) { | 373 if (!IS_DATAVIEW(this)) { |
| 343 throw MakeTypeError('incompatible_method_reciever', | 374 throw MakeTypeError('incompatible_method_reciever', |
| 344 ['DataView.getInt32', this]); | 375 ['DataView.getInt32', this]); |
| 345 } | 376 } |
| 377 if (%_ArgumentsLength() < 1) { |
| 378 throw MakeTypeError('invalid_argument'); |
| 379 } |
| 346 return %DataViewGetInt32(this, | 380 return %DataViewGetInt32(this, |
| 347 ToPositiveDataViewOffset(offset), | 381 ToPositiveDataViewOffset(offset), |
| 348 !!little_endian); | 382 !!little_endian); |
| 349 } | 383 } |
| 350 | 384 |
| 351 function DataViewSetInt32(offset, value, little_endian) { | 385 function DataViewSetInt32(offset, value, little_endian) { |
| 352 if (!IS_DATAVIEW(this)) { | 386 if (!IS_DATAVIEW(this)) { |
| 353 throw MakeTypeError('incompatible_method_reciever', | 387 throw MakeTypeError('incompatible_method_reciever', |
| 354 ['DataView.setInt32', this]); | 388 ['DataView.setInt32', this]); |
| 355 } | 389 } |
| 390 if (%_ArgumentsLength() < 2) { |
| 391 throw MakeTypeError('invalid_argument'); |
| 392 } |
| 356 %DataViewSetInt32(this, | 393 %DataViewSetInt32(this, |
| 357 ToPositiveDataViewOffset(offset), | 394 ToPositiveDataViewOffset(offset), |
| 358 TO_NUMBER_INLINE(value), | 395 TO_NUMBER_INLINE(value), |
| 359 !!little_endian); | 396 !!little_endian); |
| 360 } | 397 } |
| 361 | 398 |
| 362 function DataViewGetUint32(offset, little_endian) { | 399 function DataViewGetUint32(offset, little_endian) { |
| 363 if (!IS_DATAVIEW(this)) { | 400 if (!IS_DATAVIEW(this)) { |
| 364 throw MakeTypeError('incompatible_method_reciever', | 401 throw MakeTypeError('incompatible_method_reciever', |
| 365 ['DataView.getUint32', this]); | 402 ['DataView.getUint32', this]); |
| 366 } | 403 } |
| 404 if (%_ArgumentsLength() < 1) { |
| 405 throw MakeTypeError('invalid_argument'); |
| 406 } |
| 367 return %DataViewGetUint32(this, | 407 return %DataViewGetUint32(this, |
| 368 ToPositiveDataViewOffset(offset), | 408 ToPositiveDataViewOffset(offset), |
| 369 !!little_endian); | 409 !!little_endian); |
| 370 } | 410 } |
| 371 | 411 |
| 372 function DataViewSetUint32(offset, value, little_endian) { | 412 function DataViewSetUint32(offset, value, little_endian) { |
| 373 if (!IS_DATAVIEW(this)) { | 413 if (!IS_DATAVIEW(this)) { |
| 374 throw MakeTypeError('incompatible_method_reciever', | 414 throw MakeTypeError('incompatible_method_reciever', |
| 375 ['DataView.setUint32', this]); | 415 ['DataView.setUint32', this]); |
| 376 } | 416 } |
| 417 if (%_ArgumentsLength() < 1) { |
| 418 throw MakeTypeError('invalid_argument'); |
| 419 } |
| 377 %DataViewSetUint32(this, | 420 %DataViewSetUint32(this, |
| 378 ToPositiveDataViewOffset(offset), | 421 ToPositiveDataViewOffset(offset), |
| 379 TO_NUMBER_INLINE(value), | 422 TO_NUMBER_INLINE(value), |
| 380 !!little_endian); | 423 !!little_endian); |
| 381 } | 424 } |
| 382 | 425 |
| 383 function DataViewGetFloat32(offset, little_endian) { | 426 function DataViewGetFloat32(offset, little_endian) { |
| 384 if (!IS_DATAVIEW(this)) { | 427 if (!IS_DATAVIEW(this)) { |
| 385 throw MakeTypeError('incompatible_method_reciever', | 428 throw MakeTypeError('incompatible_method_reciever', |
| 386 ['DataView.getFloat32', this]); | 429 ['DataView.getFloat32', this]); |
| 387 } | 430 } |
| 431 if (%_ArgumentsLength() < 1) { |
| 432 throw MakeTypeError('invalid_argument'); |
| 433 } |
| 388 return %DataViewGetFloat32(this, | 434 return %DataViewGetFloat32(this, |
| 389 ToPositiveDataViewOffset(offset), | 435 ToPositiveDataViewOffset(offset), |
| 390 !!little_endian); | 436 !!little_endian); |
| 391 } | 437 } |
| 392 | 438 |
| 393 function DataViewSetFloat32(offset, value, little_endian) { | 439 function DataViewSetFloat32(offset, value, little_endian) { |
| 394 if (!IS_DATAVIEW(this)) { | 440 if (!IS_DATAVIEW(this)) { |
| 395 throw MakeTypeError('incompatible_method_reciever', | 441 throw MakeTypeError('incompatible_method_reciever', |
| 396 ['DataView.setFloat32', this]); | 442 ['DataView.setFloat32', this]); |
| 397 } | 443 } |
| 444 if (%_ArgumentsLength() < 1) { |
| 445 throw MakeTypeError('invalid_argument'); |
| 446 } |
| 398 %DataViewSetFloat32(this, | 447 %DataViewSetFloat32(this, |
| 399 ToPositiveDataViewOffset(offset), | 448 ToPositiveDataViewOffset(offset), |
| 400 TO_NUMBER_INLINE(value), | 449 TO_NUMBER_INLINE(value), |
| 401 !!little_endian); | 450 !!little_endian); |
| 402 } | 451 } |
| 403 | 452 |
| 404 function DataViewGetFloat64(offset, little_endian) { | 453 function DataViewGetFloat64(offset, little_endian) { |
| 405 if (!IS_DATAVIEW(this)) { | 454 if (!IS_DATAVIEW(this)) { |
| 406 throw MakeTypeError('incompatible_method_reciever', | 455 throw MakeTypeError('incompatible_method_reciever', |
| 407 ['DataView.getFloat64', this]); | 456 ['DataView.getFloat64', this]); |
| 408 } | 457 } |
| 409 offset = TO_INTEGER(offset); | 458 if (%_ArgumentsLength() < 1) { |
| 410 if (offset < 0) { | 459 throw MakeTypeError('invalid_argument'); |
| 411 throw MakeRangeError("invalid_data_view_accessor_offset"); | |
| 412 } | 460 } |
| 413 return %DataViewGetFloat64(this, | 461 return %DataViewGetFloat64(this, |
| 414 ToPositiveDataViewOffset(offset), | 462 ToPositiveDataViewOffset(offset), |
| 415 !!little_endian); | 463 !!little_endian); |
| 416 } | 464 } |
| 417 | 465 |
| 418 function DataViewSetFloat64(offset, value, little_endian) { | 466 function DataViewSetFloat64(offset, value, little_endian) { |
| 419 if (!IS_DATAVIEW(this)) { | 467 if (!IS_DATAVIEW(this)) { |
| 420 throw MakeTypeError('incompatible_method_reciever', | 468 throw MakeTypeError('incompatible_method_reciever', |
| 421 ['DataView.setFloat64', this]); | 469 ['DataView.setFloat64', this]); |
| 422 } | 470 } |
| 423 offset = TO_INTEGER(offset); | 471 if (%_ArgumentsLength() < 1) { |
| 424 if (offset < 0) { | 472 throw MakeTypeError('invalid_argument'); |
| 425 throw MakeRangeError("invalid_data_view_accessor_offset"); | |
| 426 } | 473 } |
| 427 %DataViewSetFloat64(this, | 474 %DataViewSetFloat64(this, |
| 428 ToPositiveDataViewOffset(offset), | 475 ToPositiveDataViewOffset(offset), |
| 429 TO_NUMBER_INLINE(value), | 476 TO_NUMBER_INLINE(value), |
| 430 !!little_endian); | 477 !!little_endian); |
| 431 } | 478 } |
| 432 | 479 |
| 433 function SetupDataView() { | 480 function SetupDataView() { |
| 434 %CheckIsBootstrapping(); | 481 %CheckIsBootstrapping(); |
| 435 | 482 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 465 | 512 |
| 466 "getFloat32", DataViewGetFloat32, | 513 "getFloat32", DataViewGetFloat32, |
| 467 "setFloat32", DataViewSetFloat32, | 514 "setFloat32", DataViewSetFloat32, |
| 468 | 515 |
| 469 "getFloat64", DataViewGetFloat64, | 516 "getFloat64", DataViewGetFloat64, |
| 470 "setFloat64", DataViewSetFloat64 | 517 "setFloat64", DataViewSetFloat64 |
| 471 )); | 518 )); |
| 472 } | 519 } |
| 473 | 520 |
| 474 SetupDataView(); | 521 SetupDataView(); |
| OLD | NEW |