OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/base/macros.h" | 5 #include "src/base/macros.h" |
6 #include "src/base/platform/mutex.h" | 6 #include "src/base/platform/mutex.h" |
7 #include "src/base/platform/time.h" | 7 #include "src/base/platform/time.h" |
8 #include "src/builtins/builtins-utils.h" | 8 #include "src/builtins/builtins-utils.h" |
9 #include "src/builtins/builtins.h" | 9 #include "src/builtins/builtins.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 HandleScope scope(isolate); | 282 HandleScope scope(isolate); |
283 Handle<Object> size = args.atOrUndefined(isolate, 1); | 283 Handle<Object> size = args.atOrUndefined(isolate, 1); |
284 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, size, Object::ToNumber(size)); | 284 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, size, Object::ToNumber(size)); |
285 return *isolate->factory()->ToBoolean(AtomicIsLockFree(size->Number())); | 285 return *isolate->factory()->ToBoolean(AtomicIsLockFree(size->Number())); |
286 } | 286 } |
287 | 287 |
288 // ES #sec-validatesharedintegertypedarray | 288 // ES #sec-validatesharedintegertypedarray |
289 MUST_USE_RESULT MaybeHandle<JSTypedArray> ValidateSharedIntegerTypedArray( | 289 MUST_USE_RESULT MaybeHandle<JSTypedArray> ValidateSharedIntegerTypedArray( |
290 Isolate* isolate, Handle<Object> object, bool only_int32 = false) { | 290 Isolate* isolate, Handle<Object> object, bool only_int32 = false) { |
291 if (object->IsJSTypedArray()) { | 291 if (object->IsJSTypedArray()) { |
292 Handle<JSTypedArray> typedArray = Handle<JSTypedArray>::cast(object); | 292 Handle<JSTypedArray> typed_array = Handle<JSTypedArray>::cast(object); |
293 if (typedArray->GetBuffer()->is_shared()) { | 293 if (typed_array->GetBuffer()->is_shared()) { |
294 if (only_int32) { | 294 if (only_int32) { |
295 if (typedArray->type() == kExternalInt32Array) return typedArray; | 295 if (typed_array->type() == kExternalInt32Array) return typed_array; |
296 } else { | 296 } else { |
297 if (typedArray->type() != kExternalFloat32Array && | 297 if (typed_array->type() != kExternalFloat32Array && |
298 typedArray->type() != kExternalFloat64Array && | 298 typed_array->type() != kExternalFloat64Array && |
299 typedArray->type() != kExternalUint8ClampedArray) | 299 typed_array->type() != kExternalUint8ClampedArray) |
300 return typedArray; | 300 return typed_array; |
301 } | 301 } |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 THROW_NEW_ERROR( | 305 THROW_NEW_ERROR( |
306 isolate, | 306 isolate, |
307 NewTypeError(only_int32 ? MessageTemplate::kNotInt32SharedTypedArray | 307 NewTypeError(only_int32 ? MessageTemplate::kNotInt32SharedTypedArray |
308 : MessageTemplate::kNotIntegerSharedTypedArray, | 308 : MessageTemplate::kNotIntegerSharedTypedArray, |
309 object), | 309 object), |
310 JSTypedArray); | 310 JSTypedArray); |
311 } | 311 } |
312 | 312 |
313 // ES #sec-validateatomicaccess | 313 // ES #sec-validateatomicaccess |
314 // ValidateAtomicAccess( typedArray, requestIndex ) | |
314 MUST_USE_RESULT Maybe<size_t> ValidateAtomicAccess( | 315 MUST_USE_RESULT Maybe<size_t> ValidateAtomicAccess( |
315 Isolate* isolate, Handle<JSTypedArray> typedArray, | 316 Isolate* isolate, Handle<JSTypedArray> typed_array, |
316 Handle<Object> requestIndex) { | 317 Handle<Object> request_index) { |
317 // TOOD(v8:5961): Use ToIndex for indexes | 318 // TOOD(v8:5961): Use ToIndex for indexes |
318 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 319 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, request_index, |
319 isolate, requestIndex, Object::ToNumber(requestIndex), Nothing<size_t>()); | 320 Object::ToNumber(request_index), |
321 Nothing<size_t>()); | |
320 Handle<Object> offset; | 322 Handle<Object> offset; |
321 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, offset, | 323 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, offset, |
322 Object::ToInteger(isolate, requestIndex), | 324 Object::ToInteger(isolate, request_index), |
323 Nothing<size_t>()); | 325 Nothing<size_t>()); |
324 if (!requestIndex->SameValue(*offset)) { | 326 if (!request_index->SameValue(*offset)) { |
325 isolate->Throw(*isolate->factory()->NewRangeError( | 327 isolate->Throw(*isolate->factory()->NewRangeError( |
326 MessageTemplate::kInvalidAtomicAccessIndex)); | 328 MessageTemplate::kInvalidAtomicAccessIndex)); |
327 return Nothing<size_t>(); | 329 return Nothing<size_t>(); |
328 } | 330 } |
329 size_t accessIndex; | 331 size_t access_index; |
330 uint32_t length = typedArray->length_value(); | 332 uint32_t length = typed_array->length_value(); |
331 if (!TryNumberToSize(*requestIndex, &accessIndex) || accessIndex >= length) { | 333 if (!TryNumberToSize(*request_index, &access_index) || |
334 access_index >= length) { | |
332 isolate->Throw(*isolate->factory()->NewRangeError( | 335 isolate->Throw(*isolate->factory()->NewRangeError( |
333 MessageTemplate::kInvalidAtomicAccessIndex)); | 336 MessageTemplate::kInvalidAtomicAccessIndex)); |
334 return Nothing<size_t>(); | 337 return Nothing<size_t>(); |
335 } | 338 } |
336 return Just<size_t>(accessIndex); | 339 return Just<size_t>(access_index); |
337 } | 340 } |
338 | 341 |
339 // ES #sec-atomics.wake | 342 // ES #sec-atomics.wake |
340 // Atomics.wake( typedArray, index, count ) | 343 // Atomics.wake( typedArray, index, count ) |
341 BUILTIN(AtomicsWake) { | 344 BUILTIN(AtomicsWake) { |
342 HandleScope scope(isolate); | 345 HandleScope scope(isolate); |
343 Handle<Object> array = args.atOrUndefined(isolate, 1); | 346 Handle<Object> array = args.atOrUndefined(isolate, 1); |
344 Handle<Object> index = args.atOrUndefined(isolate, 2); | 347 Handle<Object> index = args.atOrUndefined(isolate, 2); |
345 Handle<Object> count = args.atOrUndefined(isolate, 3); | 348 Handle<Object> count = args.atOrUndefined(isolate, 3); |
346 | 349 |
347 Handle<JSTypedArray> sta; | 350 Handle<JSTypedArray> sta; |
348 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 351 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
349 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array, true)); | 352 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array, true)); |
350 | 353 |
351 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 354 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
352 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 355 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
353 size_t i = maybeIndex.FromJust(); | 356 size_t i = maybe_index.FromJust(); |
354 | 357 |
355 uint32_t c; | 358 uint32_t c; |
356 if (count->IsUndefined(isolate)) { | 359 if (count->IsUndefined(isolate)) { |
357 c = kMaxUInt32; | 360 c = kMaxUInt32; |
358 } else { | 361 } else { |
359 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, count, | 362 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, count, |
360 Object::ToInteger(isolate, count)); | 363 Object::ToInteger(isolate, count)); |
361 double countDouble = count->Number(); | 364 double count_double = count->Number(); |
362 if (countDouble < 0) | 365 if (count_double < 0) |
363 countDouble = 0; | 366 count_double = 0; |
364 else if (countDouble > kMaxUInt32) | 367 else if (count_double > kMaxUInt32) |
365 countDouble = kMaxUInt32; | 368 count_double = kMaxUInt32; |
366 c = static_cast<uint32_t>(countDouble); | 369 c = static_cast<uint32_t>(count_double); |
367 } | 370 } |
368 | 371 |
369 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); | 372 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); |
370 size_t addr = (i << 2) + NumberToSize(sta->byte_offset()); | 373 size_t addr = (i << 2) + NumberToSize(sta->byte_offset()); |
371 | 374 |
372 return FutexEmulation::Wake(isolate, array_buffer, addr, c); | 375 return FutexEmulation::Wake(isolate, array_buffer, addr, c); |
373 } | 376 } |
374 | 377 |
375 // ES #sec-atomics.wait | 378 // ES #sec-atomics.wait |
376 // Atomics.wait( typedArray, index, value, timeout ) | 379 // Atomics.wait( typedArray, index, value, timeout ) |
377 BUILTIN(AtomicsWait) { | 380 BUILTIN(AtomicsWait) { |
378 HandleScope scope(isolate); | 381 HandleScope scope(isolate); |
379 Handle<Object> array = args.atOrUndefined(isolate, 1); | 382 Handle<Object> array = args.atOrUndefined(isolate, 1); |
380 Handle<Object> index = args.atOrUndefined(isolate, 2); | 383 Handle<Object> index = args.atOrUndefined(isolate, 2); |
381 Handle<Object> value = args.atOrUndefined(isolate, 3); | 384 Handle<Object> value = args.atOrUndefined(isolate, 3); |
382 Handle<Object> timeout = args.atOrUndefined(isolate, 4); | 385 Handle<Object> timeout = args.atOrUndefined(isolate, 4); |
383 | 386 |
384 Handle<JSTypedArray> sta; | 387 Handle<JSTypedArray> sta; |
385 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 388 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
386 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array, true)); | 389 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array, true)); |
387 | 390 |
388 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 391 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
389 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 392 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
390 size_t i = maybeIndex.FromJust(); | 393 size_t i = maybe_index.FromJust(); |
391 | 394 |
392 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 395 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
393 Object::ToInt32(isolate, value)); | 396 Object::ToInt32(isolate, value)); |
394 int32_t valueInt32 = NumberToInt32(*value); | 397 int32_t value_int32 = NumberToInt32(*value); |
395 | 398 |
396 double timeoutNumber; | 399 double timeout_number; |
397 if (timeout->IsUndefined(isolate)) { | 400 if (timeout->IsUndefined(isolate)) { |
398 timeoutNumber = isolate->heap()->infinity_value()->Number(); | 401 timeout_number = isolate->heap()->infinity_value()->Number(); |
399 } else { | 402 } else { |
400 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, timeout, | 403 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, timeout, |
401 Object::ToNumber(timeout)); | 404 Object::ToNumber(timeout)); |
402 timeoutNumber = timeout->Number(); | 405 timeout_number = timeout->Number(); |
403 if (std::isnan(timeoutNumber)) | 406 if (std::isnan(timeout_number)) |
404 timeoutNumber = isolate->heap()->infinity_value()->Number(); | 407 timeout_number = isolate->heap()->infinity_value()->Number(); |
405 else if (timeoutNumber < 0) | 408 else if (timeout_number < 0) |
406 timeoutNumber = 0; | 409 timeout_number = 0; |
407 } | 410 } |
408 | 411 |
409 if (!isolate->allow_atomics_wait()) { | 412 if (!isolate->allow_atomics_wait()) { |
410 THROW_NEW_ERROR_RETURN_FAILURE( | 413 THROW_NEW_ERROR_RETURN_FAILURE( |
411 isolate, NewTypeError(MessageTemplate::kAtomicsWaitNotAllowed)); | 414 isolate, NewTypeError(MessageTemplate::kAtomicsWaitNotAllowed)); |
412 } | 415 } |
413 | 416 |
414 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); | 417 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); |
415 size_t addr = (i << 2) + NumberToSize(sta->byte_offset()); | 418 size_t addr = (i << 2) + NumberToSize(sta->byte_offset()); |
416 | 419 |
417 return FutexEmulation::Wait(isolate, array_buffer, addr, valueInt32, | 420 return FutexEmulation::Wait(isolate, array_buffer, addr, value_int32, |
418 timeoutNumber); | 421 value_int32); |
419 } | 422 } |
420 | 423 |
421 namespace { | 424 namespace { |
422 | 425 |
423 #if V8_CC_GNU | 426 #if V8_CC_GNU |
424 | 427 |
425 template <typename T> | 428 template <typename T> |
426 inline T CompareExchangeSeqCst(T* p, T oldval, T newval) { | 429 inline T CompareExchangeSeqCst(T* p, T oldval, T newval) { |
427 (void)__atomic_compare_exchange_n(p, &oldval, newval, 0, __ATOMIC_SEQ_CST, | 430 (void)__atomic_compare_exchange_n(p, &oldval, newval, 0, __ATOMIC_SEQ_CST, |
428 __ATOMIC_SEQ_CST); | 431 __ATOMIC_SEQ_CST); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 } | 634 } |
632 | 635 |
633 template <typename T> | 636 template <typename T> |
634 inline Object* DoExchange(Isolate* isolate, void* buffer, size_t index, | 637 inline Object* DoExchange(Isolate* isolate, void* buffer, size_t index, |
635 Handle<Object> obj) { | 638 Handle<Object> obj) { |
636 T value = FromObject<T>(obj); | 639 T value = FromObject<T>(obj); |
637 T result = ExchangeSeqCst(static_cast<T*>(buffer) + index, value); | 640 T result = ExchangeSeqCst(static_cast<T*>(buffer) + index, value); |
638 return ToObject(isolate, result); | 641 return ToObject(isolate, result); |
639 } | 642 } |
640 | 643 |
641 // Uint8Clamped functions | |
642 | |
643 uint8_t ClampToUint8(int32_t value) { | |
644 if (value < 0) return 0; | |
645 if (value > 255) return 255; | |
646 return value; | |
647 } | |
648 | |
649 inline Object* DoCompareExchangeUint8Clamped(Isolate* isolate, void* buffer, | |
650 size_t index, | |
651 Handle<Object> oldobj, | |
652 Handle<Object> newobj) { | |
653 typedef int32_t convert_type; | |
654 uint8_t oldval = ClampToUint8(FromObject<convert_type>(oldobj)); | |
655 uint8_t newval = ClampToUint8(FromObject<convert_type>(newobj)); | |
656 uint8_t result = CompareExchangeSeqCst(static_cast<uint8_t*>(buffer) + index, | |
657 oldval, newval); | |
658 return ToObject(isolate, result); | |
659 } | |
660 | |
661 #define DO_UINT8_CLAMPED_OP(name, op) \ | |
662 inline Object* Do##name##Uint8Clamped(Isolate* isolate, void* buffer, \ | |
663 size_t index, Handle<Object> obj) { \ | |
664 typedef int32_t convert_type; \ | |
665 uint8_t* p = static_cast<uint8_t*>(buffer) + index; \ | |
666 convert_type operand = FromObject<convert_type>(obj); \ | |
667 uint8_t expected; \ | |
668 uint8_t result; \ | |
669 do { \ | |
670 expected = *p; \ | |
671 result = ClampToUint8(static_cast<convert_type>(expected) op operand); \ | |
672 } while (CompareExchangeSeqCst(p, expected, result) != expected); \ | |
673 return ToObject(isolate, expected); \ | |
674 } | |
675 | |
676 DO_UINT8_CLAMPED_OP(Add, +) | |
677 DO_UINT8_CLAMPED_OP(Sub, -) | |
678 DO_UINT8_CLAMPED_OP(And, &) | |
679 DO_UINT8_CLAMPED_OP(Or, |) | |
680 DO_UINT8_CLAMPED_OP(Xor, ^) | |
681 | |
682 #undef DO_UINT8_CLAMPED_OP | |
683 | |
684 inline Object* DoExchangeUint8Clamped(Isolate* isolate, void* buffer, | |
685 size_t index, Handle<Object> obj) { | |
686 typedef int32_t convert_type; | |
687 uint8_t* p = static_cast<uint8_t*>(buffer) + index; | |
688 uint8_t result = ClampToUint8(FromObject<convert_type>(obj)); | |
689 uint8_t expected; | |
690 do { | |
691 expected = *p; | |
692 } while (CompareExchangeSeqCst(p, expected, result) != expected); | |
693 return ToObject(isolate, expected); | |
694 } | |
695 | |
696 } // anonymous namespace | 644 } // anonymous namespace |
697 | 645 |
698 // Duplicated from objects.h | 646 // Duplicated from objects.h |
699 // V has parameters (Type, type, TYPE, C type, element_size) | 647 // V has parameters (Type, type, TYPE, C type, element_size) |
700 #define INTEGER_TYPED_ARRAYS(V) \ | 648 #define INTEGER_TYPED_ARRAYS(V) \ |
701 V(Uint8, uint8, UINT8, uint8_t, 1) \ | 649 V(Uint8, uint8, UINT8, uint8_t, 1) \ |
702 V(Int8, int8, INT8, int8_t, 1) \ | 650 V(Int8, int8, INT8, int8_t, 1) \ |
703 V(Uint16, uint16, UINT16, uint16_t, 2) \ | 651 V(Uint16, uint16, UINT16, uint16_t, 2) \ |
704 V(Int16, int16, INT16, int16_t, 2) \ | 652 V(Int16, int16, INT16, int16_t, 2) \ |
705 V(Uint32, uint32, UINT32, uint32_t, 4) \ | 653 V(Uint32, uint32, UINT32, uint32_t, 4) \ |
706 V(Int32, int32, INT32, int32_t, 4) | 654 V(Int32, int32, INT32, int32_t, 4) |
707 | 655 |
708 // ES #sec-atomics.wait | 656 // ES #sec-atomics.wait |
709 // Atomics.compareExchange( typedArray, index, expectedValue, replacementValue ) | 657 // Atomics.compareExchange( typedArray, index, expectedValue, replacementValue ) |
710 BUILTIN(AtomicsCompareExchange) { | 658 BUILTIN(AtomicsCompareExchange) { |
711 HandleScope scope(isolate); | 659 HandleScope scope(isolate); |
712 Handle<Object> array = args.atOrUndefined(isolate, 1); | 660 Handle<Object> array = args.atOrUndefined(isolate, 1); |
713 Handle<Object> index = args.atOrUndefined(isolate, 2); | 661 Handle<Object> index = args.atOrUndefined(isolate, 2); |
714 Handle<Object> expectedValue = args.atOrUndefined(isolate, 3); | 662 Handle<Object> expected_value = args.atOrUndefined(isolate, 3); |
715 Handle<Object> replacementValue = args.atOrUndefined(isolate, 4); | 663 Handle<Object> replacement_value = args.atOrUndefined(isolate, 4); |
716 | 664 |
717 Handle<JSTypedArray> sta; | 665 Handle<JSTypedArray> sta; |
718 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 666 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
719 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 667 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
720 | 668 |
721 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 669 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
722 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 670 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
723 size_t i = maybeIndex.FromJust(); | 671 size_t i = maybe_index.FromJust(); |
724 | |
725 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, expectedValue, | |
726 Object::ToInteger(isolate, expectedValue)); | |
727 | 672 |
728 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 673 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
729 isolate, replacementValue, Object::ToInteger(isolate, replacementValue)); | 674 isolate, expected_value, Object::ToInteger(isolate, expected_value)); |
675 | |
676 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
677 isolate, replacement_value, | |
678 Object::ToInteger(isolate, replacement_value)); | |
730 | 679 |
731 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 680 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
732 NumberToSize(sta->byte_offset()); | 681 NumberToSize(sta->byte_offset()); |
733 | 682 |
734 switch (sta->type()) { | 683 switch (sta->type()) { |
735 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 684 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
736 case kExternal##Type##Array: \ | 685 case kExternal##Type##Array: \ |
737 return DoCompareExchange<ctype>(isolate, source, i, expectedValue, \ | 686 return DoCompareExchange<ctype>(isolate, source, i, expected_value, \ |
738 replacementValue); | 687 replacement_value); |
739 | 688 |
740 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 689 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
741 #undef TYPED_ARRAY_CASE | 690 #undef TYPED_ARRAY_CASE |
742 | 691 |
743 case kExternalUint8ClampedArray: | 692 case kExternalUint8ClampedArray: |
744 return DoCompareExchangeUint8Clamped(isolate, source, i, expectedValue, | 693 UNREACHABLE(); |
binji
2017/02/21 18:16:52
May as well just fall through to the unreachable b
Dan Ehrenberg
2017/02/22 15:57:59
Done.
| |
745 replacementValue); | |
746 | 694 |
747 default: | 695 default: |
748 break; | 696 break; |
749 } | 697 } |
750 | 698 |
751 UNREACHABLE(); | 699 UNREACHABLE(); |
752 return isolate->heap()->undefined_value(); | 700 return isolate->heap()->undefined_value(); |
753 } | 701 } |
754 | 702 |
755 // ES #sec-atomics.add | 703 // ES #sec-atomics.add |
756 // Atomics.add( typedArray, index, value ) | 704 // Atomics.add( typedArray, index, value ) |
757 BUILTIN(AtomicsAdd) { | 705 BUILTIN(AtomicsAdd) { |
758 HandleScope scope(isolate); | 706 HandleScope scope(isolate); |
759 Handle<Object> array = args.atOrUndefined(isolate, 1); | 707 Handle<Object> array = args.atOrUndefined(isolate, 1); |
760 Handle<Object> index = args.atOrUndefined(isolate, 2); | 708 Handle<Object> index = args.atOrUndefined(isolate, 2); |
761 Handle<Object> value = args.atOrUndefined(isolate, 3); | 709 Handle<Object> value = args.atOrUndefined(isolate, 3); |
762 | 710 |
763 Handle<JSTypedArray> sta; | 711 Handle<JSTypedArray> sta; |
764 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 712 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
765 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 713 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
766 | 714 |
767 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 715 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
768 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 716 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
769 size_t i = maybeIndex.FromJust(); | 717 size_t i = maybe_index.FromJust(); |
770 | 718 |
771 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 719 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
772 Object::ToInteger(isolate, value)); | 720 Object::ToInteger(isolate, value)); |
773 | 721 |
774 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 722 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
775 NumberToSize(sta->byte_offset()); | 723 NumberToSize(sta->byte_offset()); |
776 | 724 |
777 switch (sta->type()) { | 725 switch (sta->type()) { |
778 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 726 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
779 case kExternal##Type##Array: \ | 727 case kExternal##Type##Array: \ |
780 return DoAdd<ctype>(isolate, source, i, value); | 728 return DoAdd<ctype>(isolate, source, i, value); |
781 | 729 |
782 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 730 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
783 #undef TYPED_ARRAY_CASE | 731 #undef TYPED_ARRAY_CASE |
784 | 732 |
785 case kExternalUint8ClampedArray: | 733 case kExternalUint8ClampedArray: |
786 return DoAddUint8Clamped(isolate, source, i, value); | 734 UNREACHABLE(); |
787 | 735 |
788 default: | 736 default: |
789 break; | 737 break; |
790 } | 738 } |
791 | 739 |
792 UNREACHABLE(); | 740 UNREACHABLE(); |
793 return isolate->heap()->undefined_value(); | 741 return isolate->heap()->undefined_value(); |
794 } | 742 } |
795 | 743 |
796 // ES #sec-atomics.sub | 744 // ES #sec-atomics.sub |
797 // Atomics.sub( typedArray, index, value ) | 745 // Atomics.sub( typedArray, index, value ) |
798 BUILTIN(AtomicsSub) { | 746 BUILTIN(AtomicsSub) { |
799 HandleScope scope(isolate); | 747 HandleScope scope(isolate); |
800 Handle<Object> array = args.atOrUndefined(isolate, 1); | 748 Handle<Object> array = args.atOrUndefined(isolate, 1); |
801 Handle<Object> index = args.atOrUndefined(isolate, 2); | 749 Handle<Object> index = args.atOrUndefined(isolate, 2); |
802 Handle<Object> value = args.atOrUndefined(isolate, 3); | 750 Handle<Object> value = args.atOrUndefined(isolate, 3); |
803 | 751 |
804 Handle<JSTypedArray> sta; | 752 Handle<JSTypedArray> sta; |
805 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 753 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
806 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 754 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
807 | 755 |
808 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 756 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
809 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 757 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
810 size_t i = maybeIndex.FromJust(); | 758 size_t i = maybe_index.FromJust(); |
811 | 759 |
812 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 760 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
813 Object::ToInteger(isolate, value)); | 761 Object::ToInteger(isolate, value)); |
814 | 762 |
815 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 763 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
816 NumberToSize(sta->byte_offset()); | 764 NumberToSize(sta->byte_offset()); |
817 | 765 |
818 switch (sta->type()) { | 766 switch (sta->type()) { |
819 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 767 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
820 case kExternal##Type##Array: \ | 768 case kExternal##Type##Array: \ |
821 return DoSub<ctype>(isolate, source, i, value); | 769 return DoSub<ctype>(isolate, source, i, value); |
822 | 770 |
823 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 771 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
824 #undef TYPED_ARRAY_CASE | 772 #undef TYPED_ARRAY_CASE |
825 | 773 |
826 case kExternalUint8ClampedArray: | 774 case kExternalUint8ClampedArray: |
827 return DoSubUint8Clamped(isolate, source, i, value); | 775 UNREACHABLE(); |
828 | 776 |
829 default: | 777 default: |
830 break; | 778 break; |
831 } | 779 } |
832 | 780 |
833 UNREACHABLE(); | 781 UNREACHABLE(); |
834 return isolate->heap()->undefined_value(); | 782 return isolate->heap()->undefined_value(); |
835 } | 783 } |
836 | 784 |
837 // ES #sec-atomics.and | 785 // ES #sec-atomics.and |
838 // Atomics.and( typedArray, index, value ) | 786 // Atomics.and( typedArray, index, value ) |
839 BUILTIN(AtomicsAnd) { | 787 BUILTIN(AtomicsAnd) { |
840 HandleScope scope(isolate); | 788 HandleScope scope(isolate); |
841 Handle<Object> array = args.atOrUndefined(isolate, 1); | 789 Handle<Object> array = args.atOrUndefined(isolate, 1); |
842 Handle<Object> index = args.atOrUndefined(isolate, 2); | 790 Handle<Object> index = args.atOrUndefined(isolate, 2); |
843 Handle<Object> value = args.atOrUndefined(isolate, 3); | 791 Handle<Object> value = args.atOrUndefined(isolate, 3); |
844 | 792 |
845 Handle<JSTypedArray> sta; | 793 Handle<JSTypedArray> sta; |
846 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 794 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
847 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 795 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
848 | 796 |
849 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 797 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
850 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 798 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
851 size_t i = maybeIndex.FromJust(); | 799 size_t i = maybe_index.FromJust(); |
852 | 800 |
853 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 801 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
854 Object::ToInteger(isolate, value)); | 802 Object::ToInteger(isolate, value)); |
855 | 803 |
856 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 804 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
857 NumberToSize(sta->byte_offset()); | 805 NumberToSize(sta->byte_offset()); |
858 | 806 |
859 switch (sta->type()) { | 807 switch (sta->type()) { |
860 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 808 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
861 case kExternal##Type##Array: \ | 809 case kExternal##Type##Array: \ |
862 return DoAnd<ctype>(isolate, source, i, value); | 810 return DoAnd<ctype>(isolate, source, i, value); |
863 | 811 |
864 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 812 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
865 #undef TYPED_ARRAY_CASE | 813 #undef TYPED_ARRAY_CASE |
866 | 814 |
867 case kExternalUint8ClampedArray: | 815 case kExternalUint8ClampedArray: |
868 return DoAndUint8Clamped(isolate, source, i, value); | 816 UNREACHABLE(); |
869 | 817 |
870 default: | 818 default: |
871 break; | 819 break; |
872 } | 820 } |
873 | 821 |
874 UNREACHABLE(); | 822 UNREACHABLE(); |
875 return isolate->heap()->undefined_value(); | 823 return isolate->heap()->undefined_value(); |
876 } | 824 } |
877 | 825 |
878 // ES #sec-atomics.or | 826 // ES #sec-atomics.or |
879 // Atomics.or( typedArray, index, value ) | 827 // Atomics.or( typedArray, index, value ) |
880 BUILTIN(AtomicsOr) { | 828 BUILTIN(AtomicsOr) { |
881 HandleScope scope(isolate); | 829 HandleScope scope(isolate); |
882 Handle<Object> array = args.atOrUndefined(isolate, 1); | 830 Handle<Object> array = args.atOrUndefined(isolate, 1); |
883 Handle<Object> index = args.atOrUndefined(isolate, 2); | 831 Handle<Object> index = args.atOrUndefined(isolate, 2); |
884 Handle<Object> value = args.atOrUndefined(isolate, 3); | 832 Handle<Object> value = args.atOrUndefined(isolate, 3); |
885 | 833 |
886 Handle<JSTypedArray> sta; | 834 Handle<JSTypedArray> sta; |
887 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 835 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
888 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 836 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
889 | 837 |
890 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 838 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
891 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 839 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
892 size_t i = maybeIndex.FromJust(); | 840 size_t i = maybe_index.FromJust(); |
893 | 841 |
894 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 842 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
895 Object::ToInteger(isolate, value)); | 843 Object::ToInteger(isolate, value)); |
896 | 844 |
897 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 845 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
898 NumberToSize(sta->byte_offset()); | 846 NumberToSize(sta->byte_offset()); |
899 | 847 |
900 switch (sta->type()) { | 848 switch (sta->type()) { |
901 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 849 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
902 case kExternal##Type##Array: \ | 850 case kExternal##Type##Array: \ |
903 return DoOr<ctype>(isolate, source, i, value); | 851 return DoOr<ctype>(isolate, source, i, value); |
904 | 852 |
905 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 853 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
906 #undef TYPED_ARRAY_CASE | 854 #undef TYPED_ARRAY_CASE |
907 | 855 |
908 case kExternalUint8ClampedArray: | 856 case kExternalUint8ClampedArray: |
909 return DoOrUint8Clamped(isolate, source, i, value); | 857 UNREACHABLE(); |
910 | 858 |
911 default: | 859 default: |
912 break; | 860 break; |
913 } | 861 } |
914 | 862 |
915 UNREACHABLE(); | 863 UNREACHABLE(); |
916 return isolate->heap()->undefined_value(); | 864 return isolate->heap()->undefined_value(); |
917 } | 865 } |
918 | 866 |
919 // ES #sec-atomics.xor | 867 // ES #sec-atomics.xor |
920 // Atomics.xor( typedArray, index, value ) | 868 // Atomics.xor( typedArray, index, value ) |
921 BUILTIN(AtomicsXor) { | 869 BUILTIN(AtomicsXor) { |
922 HandleScope scope(isolate); | 870 HandleScope scope(isolate); |
923 Handle<Object> array = args.atOrUndefined(isolate, 1); | 871 Handle<Object> array = args.atOrUndefined(isolate, 1); |
924 Handle<Object> index = args.atOrUndefined(isolate, 2); | 872 Handle<Object> index = args.atOrUndefined(isolate, 2); |
925 Handle<Object> value = args.atOrUndefined(isolate, 3); | 873 Handle<Object> value = args.atOrUndefined(isolate, 3); |
926 | 874 |
927 Handle<JSTypedArray> sta; | 875 Handle<JSTypedArray> sta; |
928 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 876 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
929 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 877 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
930 | 878 |
931 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 879 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
932 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 880 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
933 size_t i = maybeIndex.FromJust(); | 881 size_t i = maybe_index.FromJust(); |
934 | 882 |
935 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 883 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
936 Object::ToInteger(isolate, value)); | 884 Object::ToInteger(isolate, value)); |
937 | 885 |
938 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 886 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
939 NumberToSize(sta->byte_offset()); | 887 NumberToSize(sta->byte_offset()); |
940 | 888 |
941 switch (sta->type()) { | 889 switch (sta->type()) { |
942 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 890 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
943 case kExternal##Type##Array: \ | 891 case kExternal##Type##Array: \ |
944 return DoXor<ctype>(isolate, source, i, value); | 892 return DoXor<ctype>(isolate, source, i, value); |
945 | 893 |
946 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 894 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
947 #undef TYPED_ARRAY_CASE | 895 #undef TYPED_ARRAY_CASE |
948 | 896 |
949 case kExternalUint8ClampedArray: | 897 case kExternalUint8ClampedArray: |
950 return DoXorUint8Clamped(isolate, source, i, value); | 898 UNREACHABLE(); |
951 | 899 |
952 default: | 900 default: |
953 break; | 901 break; |
954 } | 902 } |
955 | 903 |
956 UNREACHABLE(); | 904 UNREACHABLE(); |
957 return isolate->heap()->undefined_value(); | 905 return isolate->heap()->undefined_value(); |
958 } | 906 } |
959 | 907 |
960 // ES #sec-atomics.exchange | 908 // ES #sec-atomics.exchange |
961 // Atomics.exchange( typedArray, index, value ) | 909 // Atomics.exchange( typedArray, index, value ) |
962 BUILTIN(AtomicsExchange) { | 910 BUILTIN(AtomicsExchange) { |
963 HandleScope scope(isolate); | 911 HandleScope scope(isolate); |
964 Handle<Object> array = args.atOrUndefined(isolate, 1); | 912 Handle<Object> array = args.atOrUndefined(isolate, 1); |
965 Handle<Object> index = args.atOrUndefined(isolate, 2); | 913 Handle<Object> index = args.atOrUndefined(isolate, 2); |
966 Handle<Object> value = args.atOrUndefined(isolate, 3); | 914 Handle<Object> value = args.atOrUndefined(isolate, 3); |
967 | 915 |
968 Handle<JSTypedArray> sta; | 916 Handle<JSTypedArray> sta; |
969 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 917 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
970 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); | 918 isolate, sta, ValidateSharedIntegerTypedArray(isolate, array)); |
971 | 919 |
972 Maybe<size_t> maybeIndex = ValidateAtomicAccess(isolate, sta, index); | 920 Maybe<size_t> maybe_index = ValidateAtomicAccess(isolate, sta, index); |
973 if (maybeIndex.IsNothing()) return isolate->heap()->exception(); | 921 if (maybe_index.IsNothing()) return isolate->heap()->exception(); |
974 size_t i = maybeIndex.FromJust(); | 922 size_t i = maybe_index.FromJust(); |
975 | 923 |
976 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 924 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
977 Object::ToInteger(isolate, value)); | 925 Object::ToInteger(isolate, value)); |
978 | 926 |
979 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 927 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
980 NumberToSize(sta->byte_offset()); | 928 NumberToSize(sta->byte_offset()); |
981 | 929 |
982 switch (sta->type()) { | 930 switch (sta->type()) { |
983 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 931 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
984 case kExternal##Type##Array: \ | 932 case kExternal##Type##Array: \ |
985 return DoExchange<ctype>(isolate, source, i, value); | 933 return DoExchange<ctype>(isolate, source, i, value); |
986 | 934 |
987 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 935 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
988 #undef TYPED_ARRAY_CASE | 936 #undef TYPED_ARRAY_CASE |
989 | 937 |
990 case kExternalUint8ClampedArray: | 938 case kExternalUint8ClampedArray: |
991 return DoExchangeUint8Clamped(isolate, source, i, value); | 939 UNREACHABLE(); |
992 | 940 |
993 default: | 941 default: |
994 break; | 942 break; |
995 } | 943 } |
996 | 944 |
997 UNREACHABLE(); | 945 UNREACHABLE(); |
998 return isolate->heap()->undefined_value(); | 946 return isolate->heap()->undefined_value(); |
999 } | 947 } |
1000 | 948 |
1001 } // namespace internal | 949 } // namespace internal |
1002 } // namespace v8 | 950 } // namespace v8 |
OLD | NEW |