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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 190 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
191 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); | 191 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); |
192 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); | 192 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); |
193 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); | 193 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); |
194 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); | 194 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); |
195 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); | 195 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); |
196 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); | 196 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); |
197 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); | 197 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); |
198 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); | 198 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); |
199 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); | 199 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); |
| 200 |
| 201 |
| 202 // --------------------------- DataView ----------------------------- |
| 203 |
| 204 var $DataView = global.DataView; |
| 205 |
| 206 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| 207 if (%_IsConstructCall()) { |
| 208 if (!IS_ARRAYBUFFER(buffer)) { |
| 209 throw MakeTypeError('data_view_not_array_buffer', []); |
| 210 } |
| 211 var bufferByteLength = %ArrayBufferGetByteLength(buffer); |
| 212 var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_POSITIVE_INTEGER(byteOffset); |
| 213 if (offset > bufferByteLength) { |
| 214 throw MakeRangeError('invalid_data_view_offset', []); |
| 215 } |
| 216 var length = IS_UNDEFINED(byteLength) ? |
| 217 bufferByteLength - offset : TO_POSITIVE_INTEGER(byteLength); |
| 218 if (offset + length > bufferByteLength) { |
| 219 throw new MakeRangeError('invalid_data_view_length'); |
| 220 } |
| 221 %DataViewInitialize(this, buffer, offset, length); |
| 222 } else { |
| 223 return new $DataView(buffer, byteOffset, byteLength) |
| 224 } |
| 225 } |
| 226 |
| 227 function DataViewGetBuffer() { |
| 228 if (!IS_DATAVIEW(this)) { |
| 229 throw MakeTypeError('incompatible_method_reciever', |
| 230 ['DataView.buffer', this]); |
| 231 } |
| 232 return %DataViewGetBuffer(this); |
| 233 } |
| 234 |
| 235 function DataViewGetByteOffset() { |
| 236 if (!IS_DATAVIEW(this)) { |
| 237 throw MakeTypeError('incompatible_method_reciever', |
| 238 ['DataView.byteOffset', this]); |
| 239 } |
| 240 return %DataViewGetByteOffset(this); |
| 241 } |
| 242 |
| 243 function DataViewGetByteLength() { |
| 244 if (!IS_DATAVIEW(this)) { |
| 245 throw MakeTypeError('incompatible_method_reciever', |
| 246 ['DataView.byteLength', this]); |
| 247 } |
| 248 return %DataViewGetByteLength(this); |
| 249 } |
| 250 |
| 251 function DataViewGetInt8(offset, little_endian) { |
| 252 if (!IS_DATAVIEW(this)) { |
| 253 throw MakeTypeError('incompatible_method_reciever', |
| 254 ['DataView.getInt8', this]); |
| 255 } |
| 256 return %DataViewGetInt8(this, TO_POSITIVE_INTEGER(offset), !!little_endian); |
| 257 } |
| 258 |
| 259 function DataViewSetInt8(offset, value, little_endian) { |
| 260 if (!IS_DATAVIEW(this)) { |
| 261 throw MakeTypeError('incompatible_method_reciever', |
| 262 ['DataView.setInt8', this]); |
| 263 } |
| 264 %DataViewSetInt8(this, |
| 265 TO_POSITIVE_INTEGER(offset), |
| 266 TO_NUMBER_INLINE(value), |
| 267 !!little_endian); |
| 268 } |
| 269 |
| 270 function DataViewGetUint8(offset, little_endian) { |
| 271 if (!IS_DATAVIEW(this)) { |
| 272 throw MakeTypeError('incompatible_method_reciever', |
| 273 ['DataView.getUint8', this]); |
| 274 } |
| 275 return %DataViewGetUint8(this, TO_POSITIVE_INTEGER(offset), !!little_endian); |
| 276 } |
| 277 |
| 278 function DataViewSetUint8(offset, value, little_endian) { |
| 279 if (!IS_DATAVIEW(this)) { |
| 280 throw MakeTypeError('incompatible_method_reciever', |
| 281 ['DataView.setUint8', this]); |
| 282 } |
| 283 %DataViewSetUint8(this, |
| 284 TO_POSITIVE_INTEGER(offset), |
| 285 TO_NUMBER_INLINE(value), |
| 286 !!little_endian); |
| 287 } |
| 288 |
| 289 function DataViewGetInt16(offset, little_endian) { |
| 290 if (!IS_DATAVIEW(this)) { |
| 291 throw MakeTypeError('incompatible_method_reciever', |
| 292 ['DataView.getInt16', this]); |
| 293 } |
| 294 return %DataViewGetInt16(this, TO_POSITIVE_INTEGER(offset), !!little_endian); |
| 295 } |
| 296 |
| 297 function DataViewSetInt16(offset, value, little_endian) { |
| 298 if (!IS_DATAVIEW(this)) { |
| 299 throw MakeTypeError('incompatible_method_reciever', |
| 300 ['DataView.setInt16', this]); |
| 301 } |
| 302 %DataViewSetInt16(this, |
| 303 TO_POSITIVE_INTEGER(offset), |
| 304 TO_NUMBER_INLINE(value), |
| 305 !!little_endian); |
| 306 } |
| 307 |
| 308 function DataViewGetUint16(offset, little_endian) { |
| 309 if (!IS_DATAVIEW(this)) { |
| 310 throw MakeTypeError('incompatible_method_reciever', |
| 311 ['DataView.getUint16', this]); |
| 312 } |
| 313 return %DataViewGetUint16(this, TO_POSITIVE_INTEGER(offset), !!little_endian); |
| 314 } |
| 315 |
| 316 function DataViewSetUint16(offset, value, little_endian) { |
| 317 if (!IS_DATAVIEW(this)) { |
| 318 throw MakeTypeError('incompatible_method_reciever', |
| 319 ['DataView.setUint16', this]); |
| 320 } |
| 321 %DataViewSetUint16(this, |
| 322 TO_POSITIVE_INTEGER(offset), |
| 323 TO_NUMBER_INLINE(value), |
| 324 !!little_endian); |
| 325 } |
| 326 |
| 327 function DataViewGetInt32(offset, little_endian) { |
| 328 if (!IS_DATAVIEW(this)) { |
| 329 throw MakeTypeError('incompatible_method_reciever', |
| 330 ['DataView.getInt32', this]); |
| 331 } |
| 332 return %DataViewGetInt32(this, TO_POSITIVE_INTEGER(offset), !!little_endian); |
| 333 } |
| 334 |
| 335 function DataViewSetInt32(offset, value, little_endian) { |
| 336 if (!IS_DATAVIEW(this)) { |
| 337 throw MakeTypeError('incompatible_method_reciever', |
| 338 ['DataView.setInt32', this]); |
| 339 } |
| 340 %DataViewSetInt32(this, |
| 341 TO_POSITIVE_INTEGER(offset), |
| 342 TO_NUMBER_INLINE(value), |
| 343 !!little_endian); |
| 344 } |
| 345 |
| 346 function DataViewGetUint32(offset, little_endian) { |
| 347 if (!IS_DATAVIEW(this)) { |
| 348 throw MakeTypeError('incompatible_method_reciever', |
| 349 ['DataView.getUint32', this]); |
| 350 } |
| 351 return %DataViewGetUint32(this, TO_POSITIVE_INTEGER(offset), !!little_endian); |
| 352 } |
| 353 |
| 354 function DataViewSetUint32(offset, value, little_endian) { |
| 355 if (!IS_DATAVIEW(this)) { |
| 356 throw MakeTypeError('incompatible_method_reciever', |
| 357 ['DataView.setUint32', this]); |
| 358 } |
| 359 %DataViewSetUint32(this, |
| 360 TO_POSITIVE_INTEGER(offset), |
| 361 TO_NUMBER_INLINE(value), |
| 362 !!little_endian); |
| 363 } |
| 364 |
| 365 function DataViewGetFloat32(offset, little_endian) { |
| 366 if (!IS_DATAVIEW(this)) { |
| 367 throw MakeTypeError('incompatible_method_reciever', |
| 368 ['DataView.getFloat32', this]); |
| 369 } |
| 370 return %DataViewGetFloat32(this, TO_POSITIVE_INTEGER(offset), !!little_endian)
; |
| 371 } |
| 372 |
| 373 function DataViewSetFloat32(offset, value, little_endian) { |
| 374 if (!IS_DATAVIEW(this)) { |
| 375 throw MakeTypeError('incompatible_method_reciever', |
| 376 ['DataView.setFloat32', this]); |
| 377 } |
| 378 %DataViewSetFloat32(this, |
| 379 TO_POSITIVE_INTEGER(offset), |
| 380 TO_NUMBER_INLINE(value), |
| 381 !!little_endian); |
| 382 } |
| 383 |
| 384 function DataViewGetFloat64(offset, little_endian) { |
| 385 if (!IS_DATAVIEW(this)) { |
| 386 throw MakeTypeError('incompatible_method_reciever', |
| 387 ['DataView.getFloat64', this]); |
| 388 } |
| 389 return %DataViewGetFloat64(this, TO_POSITIVE_INTEGER(offset), !!little_endian)
; |
| 390 } |
| 391 |
| 392 function DataViewSetFloat64(offset, value, little_endian) { |
| 393 if (!IS_DATAVIEW(this)) { |
| 394 throw MakeTypeError('incompatible_method_reciever', |
| 395 ['DataView.setFloat64', this]); |
| 396 } |
| 397 %DataViewSetFloat64(this, |
| 398 TO_POSITIVE_INTEGER(offset), |
| 399 TO_NUMBER_INLINE(value), |
| 400 !!little_endian); |
| 401 } |
| 402 |
| 403 function SetupDataView() { |
| 404 %CheckIsBootstrapping(); |
| 405 |
| 406 // Setup the DataView constructor. |
| 407 %SetCode($DataView, DataViewConstructor); |
| 408 %FunctionSetPrototype($DataView, new $Object); |
| 409 |
| 410 // Set up constructor property on the DataView prototype. |
| 411 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); |
| 412 |
| 413 InstallGetter($DataView.prototype, "buffer", DataViewGetBuffer); |
| 414 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); |
| 415 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength); |
| 416 |
| 417 InstallFunctions($DataView.prototype, DONT_ENUM, $Array( |
| 418 "getInt8", DataViewGetInt8, |
| 419 "setInt8", DataViewSetInt8, |
| 420 |
| 421 "getUint8", DataViewGetUint8, |
| 422 "setUint8", DataViewSetUint8, |
| 423 |
| 424 "getInt16", DataViewGetInt16, |
| 425 "setInt16", DataViewSetInt16, |
| 426 |
| 427 "getUint16", DataViewGetUint16, |
| 428 "setUint16", DataViewSetUint16, |
| 429 |
| 430 "getInt32", DataViewGetInt32, |
| 431 "setInt32", DataViewSetInt32, |
| 432 |
| 433 "getUint32", DataViewGetUint32, |
| 434 "setUint32", DataViewSetUint32, |
| 435 |
| 436 "getFloat32", DataViewGetFloat32, |
| 437 "setFloat32", DataViewSetFloat32, |
| 438 |
| 439 "getFloat64", DataViewGetFloat64, |
| 440 "setFloat64", DataViewSetFloat64 |
| 441 )); |
| 442 } |
| 443 |
| 444 SetupDataView(); |
OLD | NEW |