| OLD | NEW |
| 1 # Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 # Copyright 2006-2009 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 const COMPILATION_TYPE_JSON = 2; | 264 const COMPILATION_TYPE_JSON = 2; |
| 265 | 265 |
| 266 # Matches Messages::kNoLineNumberInfo from v8.h | 266 # Matches Messages::kNoLineNumberInfo from v8.h |
| 267 const kNoLineNumberInfo = 0; | 267 const kNoLineNumberInfo = 0; |
| 268 | 268 |
| 269 # Matches PropertyAttributes from property-details.h | 269 # Matches PropertyAttributes from property-details.h |
| 270 const PROPERTY_ATTRIBUTES_NONE = 0; | 270 const PROPERTY_ATTRIBUTES_NONE = 0; |
| 271 const PROPERTY_ATTRIBUTES_STRING = 8; | 271 const PROPERTY_ATTRIBUTES_STRING = 8; |
| 272 const PROPERTY_ATTRIBUTES_SYMBOLIC = 16; | 272 const PROPERTY_ATTRIBUTES_SYMBOLIC = 16; |
| 273 const PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32; | 273 const PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32; |
| 274 |
| 275 # Typed Arrays |
| 276 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 277 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| 278 var bufferByteLength = buffer.byteLength; |
| 279 var offset; |
| 280 if (IS_UNDEFINED(byteOffset)) { |
| 281 offset = 0; |
| 282 } else { |
| 283 offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length"); |
| 284 |
| 285 if (offset % ELEMENT_SIZE !== 0) { |
| 286 throw MakeRangeError("invalid_typed_array_alignment", |
| 287 "start offset", "NAME", ELEMENT_SIZE); |
| 288 } |
| 289 if (offset > bufferByteLength) { |
| 290 throw MakeRangeError("invalid_typed_array_offset"); |
| 291 } |
| 292 } |
| 293 |
| 294 var newByteLength; |
| 295 var newLength; |
| 296 if (IS_UNDEFINED(length)) { |
| 297 if (bufferByteLength % ELEMENT_SIZE !== 0) { |
| 298 throw MakeRangeError("invalid_typed_array_alignment", |
| 299 "byte length", "NAME", ELEMENT_SIZE); |
| 300 } |
| 301 newByteLength = bufferByteLength - offset; |
| 302 newLength = newByteLength / ELEMENT_SIZE; |
| 303 } else { |
| 304 var newLength = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 305 newByteLength = newLength * ELEMENT_SIZE; |
| 306 } |
| 307 if ((offset + newByteLength > bufferByteLength) |
| 308 || (newLength > %MaxSmi())) { |
| 309 throw MakeRangeError("invalid_typed_array_length"); |
| 310 } |
| 311 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); |
| 312 } |
| 313 |
| 314 function NAMEConstructByLength(obj, length) { |
| 315 var l = IS_UNDEFINED(length) ? |
| 316 0 : ToPositiveInteger(length, "invalid_typed_array_length"); |
| 317 if (l > %MaxSmi()) { |
| 318 throw MakeRangeError("invalid_typed_array_length"); |
| 319 } |
| 320 var byteLength = l * ELEMENT_SIZE; |
| 321 var buffer = new $ArrayBuffer(byteLength); |
| 322 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
| 323 } |
| 324 |
| 325 function NAMEConstructByArrayLike(obj, arrayLike) { |
| 326 var length = arrayLike.length; |
| 327 var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 328 if (l > %MaxSmi()) { |
| 329 throw MakeRangeError("invalid_typed_array_length"); |
| 330 } |
| 331 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |
| 332 for (var i = 0; i < l; i++) { |
| 333 // It is crucial that we let any execptions from arrayLike[i] |
| 334 // propagate outside the function. |
| 335 obj[i] = arrayLike[i]; |
| 336 } |
| 337 } |
| 338 } |
| 339 |
| 340 function NAMEConstructor(arg1, arg2, arg3) { |
| 341 |
| 342 if (%_IsConstructCall()) { |
| 343 if (IS_ARRAYBUFFER(arg1)) { |
| 344 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
| 345 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
| 346 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| 347 NAMEConstructByLength(this, arg1); |
| 348 } else { |
| 349 NAMEConstructByArrayLike(this, arg1); |
| 350 } |
| 351 } else { |
| 352 throw MakeTypeError("constructor_not_function", ["NAME"]) |
| 353 } |
| 354 } |
| 355 endmacro |
| 356 |
| 357 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 358 SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE); |
| 359 endmacro |
| 360 |
| 361 macro TYPED_ARRAYS(FUNCTION) |
| 362 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 363 FUNCTION(1, Uint8Array, 1) |
| 364 FUNCTION(2, Int8Array, 1) |
| 365 FUNCTION(3, Uint16Array, 2) |
| 366 FUNCTION(4, Int16Array, 2) |
| 367 FUNCTION(5, Uint32Array, 4) |
| 368 FUNCTION(6, Int32Array, 4) |
| 369 FUNCTION(7, Float32Array, 4) |
| 370 FUNCTION(8, Float64Array, 8) |
| 371 FUNCTION(9, Uint8ClampedArray, 1) |
| 372 endmacro |
| 373 |
| 374 # DataView |
| 375 macro DATA_VIEW_GETTER_SETTER(TYPENAME) |
| 376 function DataViewGetTYPENAME(offset, little_endian) { |
| 377 if (!IS_DATAVIEW(this)) { |
| 378 throw MakeTypeError('incompatible_method_receiver', |
| 379 ['DataView.getTYPENAME', this]); |
| 380 } |
| 381 if (%_ArgumentsLength() < 1) { |
| 382 throw MakeTypeError('invalid_argument'); |
| 383 } |
| 384 return %DataViewGetTYPENAME(this, |
| 385 ToPositiveDataViewOffset(offset), |
| 386 !!little_endian); |
| 387 } |
| 388 |
| 389 function DataViewSetTYPENAME(offset, value, little_endian) { |
| 390 if (!IS_DATAVIEW(this)) { |
| 391 throw MakeTypeError('incompatible_method_receiver', |
| 392 ['DataView.setTYPENAME', this]); |
| 393 } |
| 394 if (%_ArgumentsLength() < 2) { |
| 395 throw MakeTypeError('invalid_argument'); |
| 396 } |
| 397 %DataViewSetTYPENAME(this, |
| 398 ToPositiveDataViewOffset(offset), |
| 399 TO_NUMBER_INLINE(value), |
| 400 !!little_endian); |
| 401 } |
| 402 endmacro |
| 403 |
| 404 macro DATA_VIEW_TYPES(FUNCTION) |
| 405 FUNCTION(Int8) |
| 406 FUNCTION(Uint8) |
| 407 FUNCTION(Int16) |
| 408 FUNCTION(Uint16) |
| 409 FUNCTION(Int32) |
| 410 FUNCTION(Uint32) |
| 411 FUNCTION(Float32) |
| 412 FUNCTION(Float64) |
| 413 endmacro |
| OLD | NEW |