| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins/builtins.h" |
| 6 | 6 |
| 7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/base/ieee754.h" | 10 #include "src/base/ieee754.h" |
| 11 #include "src/base/once.h" | 11 #include "src/base/once.h" |
| 12 #include "src/bootstrapper.h" | 12 #include "src/bootstrapper.h" |
| 13 #include "src/code-factory.h" | 13 #include "src/code-factory.h" |
| 14 #include "src/code-stub-assembler.h" | 14 #include "src/code-stub-assembler.h" |
| 15 #include "src/dateparser-inl.h" | 15 #include "src/dateparser-inl.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Arguments object passed to C++ builtins. | 37 // Arguments object passed to C++ builtins. |
| 38 class BuiltinArguments : public Arguments { | 38 class BuiltinArguments : public Arguments { |
| 39 public: | 39 public: |
| 40 BuiltinArguments(int length, Object** arguments) | 40 BuiltinArguments(int length, Object** arguments) |
| 41 : Arguments(length, arguments) { | 41 : Arguments(length, arguments) { |
| 42 // Check we have at least the receiver. | 42 // Check we have at least the receiver. |
| 43 DCHECK_LE(1, this->length()); | 43 DCHECK_LE(1, this->length()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 Object*& operator[] (int index) { | 46 Object*& operator[](int index) { |
| 47 DCHECK_LT(index, length()); | 47 DCHECK_LT(index, length()); |
| 48 return Arguments::operator[](index); | 48 return Arguments::operator[](index); |
| 49 } | 49 } |
| 50 | 50 |
| 51 template <class S> Handle<S> at(int index) { | 51 template <class S> |
| 52 Handle<S> at(int index) { |
| 52 DCHECK_LT(index, length()); | 53 DCHECK_LT(index, length()); |
| 53 return Arguments::at<S>(index); | 54 return Arguments::at<S>(index); |
| 54 } | 55 } |
| 55 | 56 |
| 56 Handle<Object> atOrUndefined(Isolate* isolate, int index) { | 57 Handle<Object> atOrUndefined(Isolate* isolate, int index) { |
| 57 if (index >= length()) { | 58 if (index >= length()) { |
| 58 return isolate->factory()->undefined_value(); | 59 return isolate->factory()->undefined_value(); |
| 59 } | 60 } |
| 60 return at<Object>(index); | 61 return at<Object>(index); |
| 61 } | 62 } |
| 62 | 63 |
| 63 Handle<Object> receiver() { | 64 Handle<Object> receiver() { return Arguments::at<Object>(0); } |
| 64 return Arguments::at<Object>(0); | |
| 65 } | |
| 66 | 65 |
| 67 static const int kNewTargetOffset = 0; | 66 static const int kNewTargetOffset = 0; |
| 68 static const int kTargetOffset = 1; | 67 static const int kTargetOffset = 1; |
| 69 static const int kArgcOffset = 2; | 68 static const int kArgcOffset = 2; |
| 70 static const int kNumExtraArgs = 3; | 69 static const int kNumExtraArgs = 3; |
| 71 static const int kNumExtraArgsWithReceiver = 4; | 70 static const int kNumExtraArgsWithReceiver = 4; |
| 72 | 71 |
| 73 template <class S> | 72 template <class S> |
| 74 Handle<S> target() { | 73 Handle<S> target() { |
| 75 return Arguments::at<S>(Arguments::length() - 1 - kTargetOffset); | 74 return Arguments::at<S>(Arguments::length() - 1 - kTargetOffset); |
| 76 } | 75 } |
| 77 Handle<HeapObject> new_target() { | 76 Handle<HeapObject> new_target() { |
| 78 return Arguments::at<HeapObject>(Arguments::length() - 1 - | 77 return Arguments::at<HeapObject>(Arguments::length() - 1 - |
| 79 kNewTargetOffset); | 78 kNewTargetOffset); |
| 80 } | 79 } |
| 81 | 80 |
| 82 // Gets the total number of arguments including the receiver (but | 81 // Gets the total number of arguments including the receiver (but |
| 83 // excluding extra arguments). | 82 // excluding extra arguments). |
| 84 int length() const { return Arguments::length() - kNumExtraArgs; } | 83 int length() const { return Arguments::length() - kNumExtraArgs; } |
| 85 }; | 84 }; |
| 86 | 85 |
| 87 | |
| 88 // ---------------------------------------------------------------------------- | 86 // ---------------------------------------------------------------------------- |
| 89 // Support macro for defining builtins in C++. | 87 // Support macro for defining builtins in C++. |
| 90 // ---------------------------------------------------------------------------- | 88 // ---------------------------------------------------------------------------- |
| 91 // | 89 // |
| 92 // A builtin function is defined by writing: | 90 // A builtin function is defined by writing: |
| 93 // | 91 // |
| 94 // BUILTIN(name) { | 92 // BUILTIN(name) { |
| 95 // ... | 93 // ... |
| 96 // } | 94 // } |
| 97 // | 95 // |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } else if (object->IsUndefined(isolate) || object->IsNull(isolate)) { | 170 } else if (object->IsUndefined(isolate) || object->IsNull(isolate)) { |
| 173 *out = 0; | 171 *out = 0; |
| 174 return true; | 172 return true; |
| 175 } else if (object->IsBoolean()) { | 173 } else if (object->IsBoolean()) { |
| 176 *out = object->IsTrue(isolate); | 174 *out = object->IsTrue(isolate); |
| 177 return true; | 175 return true; |
| 178 } | 176 } |
| 179 return false; | 177 return false; |
| 180 } | 178 } |
| 181 | 179 |
| 182 | |
| 183 inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object, | 180 inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object, |
| 184 int* out) { | 181 int* out) { |
| 185 Context* context = *isolate->native_context(); | 182 Context* context = *isolate->native_context(); |
| 186 Map* map = object->map(); | 183 Map* map = object->map(); |
| 187 if (map != context->sloppy_arguments_map() && | 184 if (map != context->sloppy_arguments_map() && |
| 188 map != context->strict_arguments_map() && | 185 map != context->strict_arguments_map() && |
| 189 map != context->fast_aliased_arguments_map()) { | 186 map != context->fast_aliased_arguments_map()) { |
| 190 return false; | 187 return false; |
| 191 } | 188 } |
| 192 DCHECK(object->HasFastElements() || object->HasFastArgumentsElements()); | 189 DCHECK(object->HasFastElements() || object->HasFastArgumentsElements()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 JSObject::TransitionElementsKind(array, target_kind); | 284 JSObject::TransitionElementsKind(array, target_kind); |
| 288 } | 285 } |
| 289 return true; | 286 return true; |
| 290 } | 287 } |
| 291 | 288 |
| 292 MUST_USE_RESULT static Object* CallJsIntrinsic(Isolate* isolate, | 289 MUST_USE_RESULT static Object* CallJsIntrinsic(Isolate* isolate, |
| 293 Handle<JSFunction> function, | 290 Handle<JSFunction> function, |
| 294 BuiltinArguments args) { | 291 BuiltinArguments args) { |
| 295 HandleScope handleScope(isolate); | 292 HandleScope handleScope(isolate); |
| 296 int argc = args.length() - 1; | 293 int argc = args.length() - 1; |
| 297 ScopedVector<Handle<Object> > argv(argc); | 294 ScopedVector<Handle<Object>> argv(argc); |
| 298 for (int i = 0; i < argc; ++i) { | 295 for (int i = 0; i < argc; ++i) { |
| 299 argv[i] = args.at<Object>(i + 1); | 296 argv[i] = args.at<Object>(i + 1); |
| 300 } | 297 } |
| 301 RETURN_RESULT_OR_FAILURE( | 298 RETURN_RESULT_OR_FAILURE( |
| 302 isolate, | 299 isolate, |
| 303 Execution::Call(isolate, function, args.receiver(), argc, argv.start())); | 300 Execution::Call(isolate, function, args.receiver(), argc, argv.start())); |
| 304 } | 301 } |
| 305 | 302 |
| 306 | |
| 307 } // namespace | 303 } // namespace |
| 308 | 304 |
| 309 | |
| 310 BUILTIN(Illegal) { | 305 BUILTIN(Illegal) { |
| 311 UNREACHABLE(); | 306 UNREACHABLE(); |
| 312 return isolate->heap()->undefined_value(); // Make compiler happy. | 307 return isolate->heap()->undefined_value(); // Make compiler happy. |
| 313 } | 308 } |
| 314 | 309 |
| 315 | |
| 316 BUILTIN(EmptyFunction) { return isolate->heap()->undefined_value(); } | 310 BUILTIN(EmptyFunction) { return isolate->heap()->undefined_value(); } |
| 317 | 311 |
| 318 void Builtins::Generate_ArrayIsArray(CodeStubAssembler* assembler) { | 312 void Builtins::Generate_ArrayIsArray(CodeStubAssembler* assembler) { |
| 319 typedef compiler::Node Node; | 313 typedef compiler::Node Node; |
| 320 typedef CodeStubAssembler::Label Label; | 314 typedef CodeStubAssembler::Label Label; |
| 321 | 315 |
| 322 Node* object = assembler->Parameter(1); | 316 Node* object = assembler->Parameter(1); |
| 323 Node* context = assembler->Parameter(4); | 317 Node* context = assembler->Parameter(4); |
| 324 | 318 |
| 325 Label call_runtime(assembler), return_true(assembler), | 319 Label call_runtime(assembler), return_true(assembler), |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } else { | 452 } else { |
| 459 // Use Slow Lookup otherwise | 453 // Use Slow Lookup otherwise |
| 460 uint32_t new_length = len - 1; | 454 uint32_t new_length = len - 1; |
| 461 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 455 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 462 isolate, result, JSReceiver::GetElement(isolate, array, new_length)); | 456 isolate, result, JSReceiver::GetElement(isolate, array, new_length)); |
| 463 JSArray::SetLength(array, new_length); | 457 JSArray::SetLength(array, new_length); |
| 464 } | 458 } |
| 465 return *result; | 459 return *result; |
| 466 } | 460 } |
| 467 | 461 |
| 468 | |
| 469 BUILTIN(ArrayShift) { | 462 BUILTIN(ArrayShift) { |
| 470 HandleScope scope(isolate); | 463 HandleScope scope(isolate); |
| 471 Heap* heap = isolate->heap(); | 464 Heap* heap = isolate->heap(); |
| 472 Handle<Object> receiver = args.receiver(); | 465 Handle<Object> receiver = args.receiver(); |
| 473 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, nullptr, 0) || | 466 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, nullptr, 0) || |
| 474 !IsJSArrayFastElementMovingAllowed(isolate, JSArray::cast(*receiver))) { | 467 !IsJSArrayFastElementMovingAllowed(isolate, JSArray::cast(*receiver))) { |
| 475 return CallJsIntrinsic(isolate, isolate->array_shift(), args); | 468 return CallJsIntrinsic(isolate, isolate->array_shift(), args); |
| 476 } | 469 } |
| 477 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 470 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 478 | 471 |
| 479 int len = Smi::cast(array->length())->value(); | 472 int len = Smi::cast(array->length())->value(); |
| 480 if (len == 0) return heap->undefined_value(); | 473 if (len == 0) return heap->undefined_value(); |
| 481 | 474 |
| 482 if (JSArray::HasReadOnlyLength(array)) { | 475 if (JSArray::HasReadOnlyLength(array)) { |
| 483 return CallJsIntrinsic(isolate, isolate->array_shift(), args); | 476 return CallJsIntrinsic(isolate, isolate->array_shift(), args); |
| 484 } | 477 } |
| 485 | 478 |
| 486 Handle<Object> first = array->GetElementsAccessor()->Shift(array); | 479 Handle<Object> first = array->GetElementsAccessor()->Shift(array); |
| 487 return *first; | 480 return *first; |
| 488 } | 481 } |
| 489 | 482 |
| 490 | |
| 491 BUILTIN(ArrayUnshift) { | 483 BUILTIN(ArrayUnshift) { |
| 492 HandleScope scope(isolate); | 484 HandleScope scope(isolate); |
| 493 Handle<Object> receiver = args.receiver(); | 485 Handle<Object> receiver = args.receiver(); |
| 494 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1)) { | 486 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1)) { |
| 495 return CallJsIntrinsic(isolate, isolate->array_unshift(), args); | 487 return CallJsIntrinsic(isolate, isolate->array_unshift(), args); |
| 496 } | 488 } |
| 497 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 489 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 498 int to_add = args.length() - 1; | 490 int to_add = args.length() - 1; |
| 499 if (to_add == 0) return array->length(); | 491 if (to_add == 0) return array->length(); |
| 500 | 492 |
| 501 // Currently fixed arrays cannot grow too big, so we should never hit this. | 493 // Currently fixed arrays cannot grow too big, so we should never hit this. |
| 502 DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); | 494 DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); |
| 503 | 495 |
| 504 if (JSArray::HasReadOnlyLength(array)) { | 496 if (JSArray::HasReadOnlyLength(array)) { |
| 505 return CallJsIntrinsic(isolate, isolate->array_unshift(), args); | 497 return CallJsIntrinsic(isolate, isolate->array_unshift(), args); |
| 506 } | 498 } |
| 507 | 499 |
| 508 ElementsAccessor* accessor = array->GetElementsAccessor(); | 500 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 509 int new_length = accessor->Unshift(array, &args, to_add); | 501 int new_length = accessor->Unshift(array, &args, to_add); |
| 510 return Smi::FromInt(new_length); | 502 return Smi::FromInt(new_length); |
| 511 } | 503 } |
| 512 | 504 |
| 513 | |
| 514 BUILTIN(ArraySlice) { | 505 BUILTIN(ArraySlice) { |
| 515 HandleScope scope(isolate); | 506 HandleScope scope(isolate); |
| 516 Handle<Object> receiver = args.receiver(); | 507 Handle<Object> receiver = args.receiver(); |
| 517 int len = -1; | 508 int len = -1; |
| 518 int relative_start = 0; | 509 int relative_start = 0; |
| 519 int relative_end = 0; | 510 int relative_end = 0; |
| 520 | 511 |
| 521 if (receiver->IsJSArray()) { | 512 if (receiver->IsJSArray()) { |
| 522 DisallowHeapAllocation no_gc; | 513 DisallowHeapAllocation no_gc; |
| 523 JSArray* array = JSArray::cast(*receiver); | 514 JSArray* array = JSArray::cast(*receiver); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 564 |
| 574 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8. | 565 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8. |
| 575 uint32_t actual_end = | 566 uint32_t actual_end = |
| 576 (relative_end < 0) ? Max(len + relative_end, 0) : Min(relative_end, len); | 567 (relative_end < 0) ? Max(len + relative_end, 0) : Min(relative_end, len); |
| 577 | 568 |
| 578 Handle<JSObject> object = Handle<JSObject>::cast(receiver); | 569 Handle<JSObject> object = Handle<JSObject>::cast(receiver); |
| 579 ElementsAccessor* accessor = object->GetElementsAccessor(); | 570 ElementsAccessor* accessor = object->GetElementsAccessor(); |
| 580 return *accessor->Slice(object, actual_start, actual_end); | 571 return *accessor->Slice(object, actual_start, actual_end); |
| 581 } | 572 } |
| 582 | 573 |
| 583 | |
| 584 BUILTIN(ArraySplice) { | 574 BUILTIN(ArraySplice) { |
| 585 HandleScope scope(isolate); | 575 HandleScope scope(isolate); |
| 586 Handle<Object> receiver = args.receiver(); | 576 Handle<Object> receiver = args.receiver(); |
| 587 if (V8_UNLIKELY( | 577 if (V8_UNLIKELY( |
| 588 !EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3) || | 578 !EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3) || |
| 589 // If this is a subclass of Array, then call out to JS. | 579 // If this is a subclass of Array, then call out to JS. |
| 590 !Handle<JSArray>::cast(receiver)->HasArrayPrototype(isolate) || | 580 !Handle<JSArray>::cast(receiver)->HasArrayPrototype(isolate) || |
| 591 // If anything with @@species has been messed with, call out to JS. | 581 // If anything with @@species has been messed with, call out to JS. |
| 592 !isolate->IsArraySpeciesLookupChainIntact())) { | 582 !isolate->IsArraySpeciesLookupChainIntact())) { |
| 593 return CallJsIntrinsic(isolate, isolate->array_splice(), args); | 583 return CallJsIntrinsic(isolate, isolate->array_splice(), args); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 if (new_length != len && JSArray::HasReadOnlyLength(array)) { | 624 if (new_length != len && JSArray::HasReadOnlyLength(array)) { |
| 635 AllowHeapAllocation allow_allocation; | 625 AllowHeapAllocation allow_allocation; |
| 636 return CallJsIntrinsic(isolate, isolate->array_splice(), args); | 626 return CallJsIntrinsic(isolate, isolate->array_splice(), args); |
| 637 } | 627 } |
| 638 ElementsAccessor* accessor = array->GetElementsAccessor(); | 628 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 639 Handle<JSArray> result_array = accessor->Splice( | 629 Handle<JSArray> result_array = accessor->Splice( |
| 640 array, actual_start, actual_delete_count, &args, add_count); | 630 array, actual_start, actual_delete_count, &args, add_count); |
| 641 return *result_array; | 631 return *result_array; |
| 642 } | 632 } |
| 643 | 633 |
| 644 | |
| 645 // Array Concat ------------------------------------------------------------- | 634 // Array Concat ------------------------------------------------------------- |
| 646 | 635 |
| 647 namespace { | 636 namespace { |
| 648 | 637 |
| 649 /** | 638 /** |
| 650 * A simple visitor visits every element of Array's. | 639 * A simple visitor visits every element of Array's. |
| 651 * The backend storage can be a fixed array for fast elements case, | 640 * The backend storage can be a fixed array for fast elements case, |
| 652 * or a dictionary for sparse array. Since Dictionary is a subtype | 641 * or a dictionary for sparse array. Since Dictionary is a subtype |
| 653 * of FixedArray, the class can be used by both fast and slow cases. | 642 * of FixedArray, the class can be used by both fast and slow cases. |
| 654 * The second parameter of the constructor, fast_elements, specifies | 643 * The second parameter of the constructor, fast_elements, specifies |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 bool is_fixed_array() const { return IsFixedArrayField::decode(bit_field_); } | 799 bool is_fixed_array() const { return IsFixedArrayField::decode(bit_field_); } |
| 811 | 800 |
| 812 Isolate* isolate_; | 801 Isolate* isolate_; |
| 813 Handle<Object> storage_; // Always a global handle. | 802 Handle<Object> storage_; // Always a global handle. |
| 814 // Index after last seen index. Always less than or equal to | 803 // Index after last seen index. Always less than or equal to |
| 815 // JSObject::kMaxElementCount. | 804 // JSObject::kMaxElementCount. |
| 816 uint32_t index_offset_; | 805 uint32_t index_offset_; |
| 817 uint32_t bit_field_; | 806 uint32_t bit_field_; |
| 818 }; | 807 }; |
| 819 | 808 |
| 820 | |
| 821 uint32_t EstimateElementCount(Handle<JSArray> array) { | 809 uint32_t EstimateElementCount(Handle<JSArray> array) { |
| 822 DisallowHeapAllocation no_gc; | 810 DisallowHeapAllocation no_gc; |
| 823 uint32_t length = static_cast<uint32_t>(array->length()->Number()); | 811 uint32_t length = static_cast<uint32_t>(array->length()->Number()); |
| 824 int element_count = 0; | 812 int element_count = 0; |
| 825 switch (array->GetElementsKind()) { | 813 switch (array->GetElementsKind()) { |
| 826 case FAST_SMI_ELEMENTS: | 814 case FAST_SMI_ELEMENTS: |
| 827 case FAST_HOLEY_SMI_ELEMENTS: | 815 case FAST_HOLEY_SMI_ELEMENTS: |
| 828 case FAST_ELEMENTS: | 816 case FAST_ELEMENTS: |
| 829 case FAST_HOLEY_ELEMENTS: { | 817 case FAST_HOLEY_ELEMENTS: { |
| 830 // Fast elements can't have lengths that are not representable by | 818 // Fast elements can't have lengths that are not representable by |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 case FAST_STRING_WRAPPER_ELEMENTS: | 868 case FAST_STRING_WRAPPER_ELEMENTS: |
| 881 case SLOW_STRING_WRAPPER_ELEMENTS: | 869 case SLOW_STRING_WRAPPER_ELEMENTS: |
| 882 UNREACHABLE(); | 870 UNREACHABLE(); |
| 883 return 0; | 871 return 0; |
| 884 } | 872 } |
| 885 // As an estimate, we assume that the prototype doesn't contain any | 873 // As an estimate, we assume that the prototype doesn't contain any |
| 886 // inherited elements. | 874 // inherited elements. |
| 887 return element_count; | 875 return element_count; |
| 888 } | 876 } |
| 889 | 877 |
| 890 | |
| 891 // Used for sorting indices in a List<uint32_t>. | 878 // Used for sorting indices in a List<uint32_t>. |
| 892 int compareUInt32(const uint32_t* ap, const uint32_t* bp) { | 879 int compareUInt32(const uint32_t* ap, const uint32_t* bp) { |
| 893 uint32_t a = *ap; | 880 uint32_t a = *ap; |
| 894 uint32_t b = *bp; | 881 uint32_t b = *bp; |
| 895 return (a == b) ? 0 : (a < b) ? -1 : 1; | 882 return (a == b) ? 0 : (a < b) ? -1 : 1; |
| 896 } | 883 } |
| 897 | 884 |
| 898 | |
| 899 void CollectElementIndices(Handle<JSObject> object, uint32_t range, | 885 void CollectElementIndices(Handle<JSObject> object, uint32_t range, |
| 900 List<uint32_t>* indices) { | 886 List<uint32_t>* indices) { |
| 901 Isolate* isolate = object->GetIsolate(); | 887 Isolate* isolate = object->GetIsolate(); |
| 902 ElementsKind kind = object->GetElementsKind(); | 888 ElementsKind kind = object->GetElementsKind(); |
| 903 switch (kind) { | 889 switch (kind) { |
| 904 case FAST_SMI_ELEMENTS: | 890 case FAST_SMI_ELEMENTS: |
| 905 case FAST_ELEMENTS: | 891 case FAST_ELEMENTS: |
| 906 case FAST_HOLEY_SMI_ELEMENTS: | 892 case FAST_HOLEY_SMI_ELEMENTS: |
| 907 case FAST_HOLEY_ELEMENTS: { | 893 case FAST_HOLEY_ELEMENTS: { |
| 908 DisallowHeapAllocation no_gc; | 894 DisallowHeapAllocation no_gc; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 | 990 |
| 1005 PrototypeIterator iter(isolate, object); | 991 PrototypeIterator iter(isolate, object); |
| 1006 if (!iter.IsAtEnd()) { | 992 if (!iter.IsAtEnd()) { |
| 1007 // The prototype will usually have no inherited element indices, | 993 // The prototype will usually have no inherited element indices, |
| 1008 // but we have to check. | 994 // but we have to check. |
| 1009 CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range, | 995 CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range, |
| 1010 indices); | 996 indices); |
| 1011 } | 997 } |
| 1012 } | 998 } |
| 1013 | 999 |
| 1014 | |
| 1015 bool IterateElementsSlow(Isolate* isolate, Handle<JSReceiver> receiver, | 1000 bool IterateElementsSlow(Isolate* isolate, Handle<JSReceiver> receiver, |
| 1016 uint32_t length, ArrayConcatVisitor* visitor) { | 1001 uint32_t length, ArrayConcatVisitor* visitor) { |
| 1017 FOR_WITH_HANDLE_SCOPE(isolate, uint32_t, i = 0, i, i < length, ++i, { | 1002 FOR_WITH_HANDLE_SCOPE(isolate, uint32_t, i = 0, i, i < length, ++i, { |
| 1018 Maybe<bool> maybe = JSReceiver::HasElement(receiver, i); | 1003 Maybe<bool> maybe = JSReceiver::HasElement(receiver, i); |
| 1019 if (!maybe.IsJust()) return false; | 1004 if (!maybe.IsJust()) return false; |
| 1020 if (maybe.FromJust()) { | 1005 if (maybe.FromJust()) { |
| 1021 Handle<Object> element_value; | 1006 Handle<Object> element_value; |
| 1022 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 1007 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 1023 isolate, element_value, JSReceiver::GetElement(isolate, receiver, i), | 1008 isolate, element_value, JSReceiver::GetElement(isolate, receiver, i), |
| 1024 false); | 1009 false); |
| 1025 if (!visitor->visit(i, element_value)) return false; | 1010 if (!visitor->visit(i, element_value)) return false; |
| 1026 } | 1011 } |
| 1027 }); | 1012 }); |
| 1028 visitor->increase_index_offset(length); | 1013 visitor->increase_index_offset(length); |
| 1029 return true; | 1014 return true; |
| 1030 } | 1015 } |
| 1031 | 1016 |
| 1032 | |
| 1033 /** | 1017 /** |
| 1034 * A helper function that visits "array" elements of a JSReceiver in numerical | 1018 * A helper function that visits "array" elements of a JSReceiver in numerical |
| 1035 * order. | 1019 * order. |
| 1036 * | 1020 * |
| 1037 * The visitor argument called for each existing element in the array | 1021 * The visitor argument called for each existing element in the array |
| 1038 * with the element index and the element's value. | 1022 * with the element index and the element's value. |
| 1039 * Afterwards it increments the base-index of the visitor by the array | 1023 * Afterwards it increments the base-index of the visitor by the array |
| 1040 * length. | 1024 * length. |
| 1041 * Returns false if any access threw an exception, otherwise true. | 1025 * Returns false if any access threw an exception, otherwise true. |
| 1042 */ | 1026 */ |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 NewRangeError(MessageTemplate::kInvalidArrayLength), | 1419 NewRangeError(MessageTemplate::kInvalidArrayLength), |
| 1436 JSArray); | 1420 JSArray); |
| 1437 } | 1421 } |
| 1438 } | 1422 } |
| 1439 } | 1423 } |
| 1440 return ElementsAccessor::Concat(isolate, args, n_arguments, result_len); | 1424 return ElementsAccessor::Concat(isolate, args, n_arguments, result_len); |
| 1441 } | 1425 } |
| 1442 | 1426 |
| 1443 } // namespace | 1427 } // namespace |
| 1444 | 1428 |
| 1445 | |
| 1446 // ES6 22.1.3.1 Array.prototype.concat | 1429 // ES6 22.1.3.1 Array.prototype.concat |
| 1447 BUILTIN(ArrayConcat) { | 1430 BUILTIN(ArrayConcat) { |
| 1448 HandleScope scope(isolate); | 1431 HandleScope scope(isolate); |
| 1449 | 1432 |
| 1450 Handle<Object> receiver = args.receiver(); | 1433 Handle<Object> receiver = args.receiver(); |
| 1451 // TODO(bmeurer): Do we really care about the exact exception message here? | 1434 // TODO(bmeurer): Do we really care about the exact exception message here? |
| 1452 if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) { | 1435 if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) { |
| 1453 THROW_NEW_ERROR_RETURN_FAILURE( | 1436 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1454 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, | 1437 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, |
| 1455 isolate->factory()->NewStringFromAsciiChecked( | 1438 isolate->factory()->NewStringFromAsciiChecked( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1477 isolate, species, Object::ArraySpeciesConstructor(isolate, receiver)); | 1460 isolate, species, Object::ArraySpeciesConstructor(isolate, receiver)); |
| 1478 if (*species == *isolate->array_function()) { | 1461 if (*species == *isolate->array_function()) { |
| 1479 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { | 1462 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { |
| 1480 return *result_array; | 1463 return *result_array; |
| 1481 } | 1464 } |
| 1482 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 1465 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
| 1483 } | 1466 } |
| 1484 return Slow_ArrayConcat(&args, species, isolate); | 1467 return Slow_ArrayConcat(&args, species, isolate); |
| 1485 } | 1468 } |
| 1486 | 1469 |
| 1487 | |
| 1488 namespace { | 1470 namespace { |
| 1489 | 1471 |
| 1490 MUST_USE_RESULT Maybe<bool> FastAssign(Handle<JSReceiver> to, | 1472 MUST_USE_RESULT Maybe<bool> FastAssign(Handle<JSReceiver> to, |
| 1491 Handle<Object> next_source) { | 1473 Handle<Object> next_source) { |
| 1492 // Non-empty strings are the only non-JSReceivers that need to be handled | 1474 // Non-empty strings are the only non-JSReceivers that need to be handled |
| 1493 // explicitly by Object.assign. | 1475 // explicitly by Object.assign. |
| 1494 if (!next_source->IsJSReceiver()) { | 1476 if (!next_source->IsJSReceiver()) { |
| 1495 return Just(!next_source->IsString() || | 1477 return Just(!next_source->IsString() || |
| 1496 String::cast(*next_source)->length() == 0); | 1478 String::cast(*next_source)->length() == 0); |
| 1497 } | 1479 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1599 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1618 isolate, status, Runtime::SetObjectProperty(isolate, to, next_key, | 1600 isolate, status, Runtime::SetObjectProperty(isolate, to, next_key, |
| 1619 prop_value, STRICT)); | 1601 prop_value, STRICT)); |
| 1620 } | 1602 } |
| 1621 } | 1603 } |
| 1622 } | 1604 } |
| 1623 // 5. Return to. | 1605 // 5. Return to. |
| 1624 return *to; | 1606 return *to; |
| 1625 } | 1607 } |
| 1626 | 1608 |
| 1627 | |
| 1628 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) | 1609 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) |
| 1629 // TODO(verwaest): Support the common cases with precached map directly in | 1610 // TODO(verwaest): Support the common cases with precached map directly in |
| 1630 // an Object.create stub. | 1611 // an Object.create stub. |
| 1631 BUILTIN(ObjectCreate) { | 1612 BUILTIN(ObjectCreate) { |
| 1632 HandleScope scope(isolate); | 1613 HandleScope scope(isolate); |
| 1633 Handle<Object> prototype = args.atOrUndefined(isolate, 1); | 1614 Handle<Object> prototype = args.atOrUndefined(isolate, 1); |
| 1634 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { | 1615 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { |
| 1635 THROW_NEW_ERROR_RETURN_FAILURE( | 1616 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1636 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); | 1617 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); |
| 1637 } | 1618 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 HandleScope scope(isolate); | 1815 HandleScope scope(isolate); |
| 1835 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1816 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1836 if (object->IsJSReceiver()) { | 1817 if (object->IsJSReceiver()) { |
| 1837 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), | 1818 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), |
| 1838 FROZEN, Object::THROW_ON_ERROR), | 1819 FROZEN, Object::THROW_ON_ERROR), |
| 1839 isolate->heap()->exception()); | 1820 isolate->heap()->exception()); |
| 1840 } | 1821 } |
| 1841 return *object; | 1822 return *object; |
| 1842 } | 1823 } |
| 1843 | 1824 |
| 1844 | |
| 1845 // ES section 19.1.2.9 Object.getPrototypeOf ( O ) | 1825 // ES section 19.1.2.9 Object.getPrototypeOf ( O ) |
| 1846 BUILTIN(ObjectGetPrototypeOf) { | 1826 BUILTIN(ObjectGetPrototypeOf) { |
| 1847 HandleScope scope(isolate); | 1827 HandleScope scope(isolate); |
| 1848 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1828 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1849 | 1829 |
| 1850 Handle<JSReceiver> receiver; | 1830 Handle<JSReceiver> receiver; |
| 1851 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1831 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 1852 isolate, receiver, Object::ToObject(isolate, object)); | 1832 Object::ToObject(isolate, object)); |
| 1853 | 1833 |
| 1854 RETURN_RESULT_OR_FAILURE(isolate, | 1834 RETURN_RESULT_OR_FAILURE(isolate, |
| 1855 JSReceiver::GetPrototype(isolate, receiver)); | 1835 JSReceiver::GetPrototype(isolate, receiver)); |
| 1856 } | 1836 } |
| 1857 | 1837 |
| 1858 | |
| 1859 // ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) | 1838 // ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) |
| 1860 BUILTIN(ObjectGetOwnPropertyDescriptor) { | 1839 BUILTIN(ObjectGetOwnPropertyDescriptor) { |
| 1861 HandleScope scope(isolate); | 1840 HandleScope scope(isolate); |
| 1862 // 1. Let obj be ? ToObject(O). | 1841 // 1. Let obj be ? ToObject(O). |
| 1863 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1842 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1864 Handle<JSReceiver> receiver; | 1843 Handle<JSReceiver> receiver; |
| 1865 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1844 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 1866 Object::ToObject(isolate, object)); | 1845 Object::ToObject(isolate, object)); |
| 1867 // 2. Let key be ? ToPropertyKey(P). | 1846 // 2. Let key be ? ToPropertyKey(P). |
| 1868 Handle<Object> property = args.atOrUndefined(isolate, 2); | 1847 Handle<Object> property = args.atOrUndefined(isolate, 2); |
| 1869 Handle<Name> key; | 1848 Handle<Name> key; |
| 1870 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, | 1849 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, |
| 1871 Object::ToName(isolate, property)); | 1850 Object::ToName(isolate, property)); |
| 1872 // 3. Let desc be ? obj.[[GetOwnProperty]](key). | 1851 // 3. Let desc be ? obj.[[GetOwnProperty]](key). |
| 1873 PropertyDescriptor desc; | 1852 PropertyDescriptor desc; |
| 1874 Maybe<bool> found = | 1853 Maybe<bool> found = |
| 1875 JSReceiver::GetOwnPropertyDescriptor(isolate, receiver, key, &desc); | 1854 JSReceiver::GetOwnPropertyDescriptor(isolate, receiver, key, &desc); |
| 1876 MAYBE_RETURN(found, isolate->heap()->exception()); | 1855 MAYBE_RETURN(found, isolate->heap()->exception()); |
| 1877 // 4. Return FromPropertyDescriptor(desc). | 1856 // 4. Return FromPropertyDescriptor(desc). |
| 1878 if (!found.FromJust()) return isolate->heap()->undefined_value(); | 1857 if (!found.FromJust()) return isolate->heap()->undefined_value(); |
| 1879 return *desc.ToObject(isolate); | 1858 return *desc.ToObject(isolate); |
| 1880 } | 1859 } |
| 1881 | 1860 |
| 1882 | |
| 1883 namespace { | 1861 namespace { |
| 1884 | 1862 |
| 1885 Object* GetOwnPropertyKeys(Isolate* isolate, BuiltinArguments args, | 1863 Object* GetOwnPropertyKeys(Isolate* isolate, BuiltinArguments args, |
| 1886 PropertyFilter filter) { | 1864 PropertyFilter filter) { |
| 1887 HandleScope scope(isolate); | 1865 HandleScope scope(isolate); |
| 1888 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1866 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1889 Handle<JSReceiver> receiver; | 1867 Handle<JSReceiver> receiver; |
| 1890 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1868 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 1891 Object::ToObject(isolate, object)); | 1869 Object::ToObject(isolate, object)); |
| 1892 Handle<FixedArray> keys; | 1870 Handle<FixedArray> keys; |
| 1893 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1871 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1894 isolate, keys, | 1872 isolate, keys, |
| 1895 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, filter, | 1873 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, filter, |
| 1896 GetKeysConversion::kConvertToString)); | 1874 GetKeysConversion::kConvertToString)); |
| 1897 return *isolate->factory()->NewJSArrayWithElements(keys); | 1875 return *isolate->factory()->NewJSArrayWithElements(keys); |
| 1898 } | 1876 } |
| 1899 | 1877 |
| 1900 } // namespace | 1878 } // namespace |
| 1901 | 1879 |
| 1902 | |
| 1903 // ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O ) | 1880 // ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O ) |
| 1904 BUILTIN(ObjectGetOwnPropertyNames) { | 1881 BUILTIN(ObjectGetOwnPropertyNames) { |
| 1905 return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS); | 1882 return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS); |
| 1906 } | 1883 } |
| 1907 | 1884 |
| 1908 | |
| 1909 // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O ) | 1885 // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O ) |
| 1910 BUILTIN(ObjectGetOwnPropertySymbols) { | 1886 BUILTIN(ObjectGetOwnPropertySymbols) { |
| 1911 return GetOwnPropertyKeys(isolate, args, SKIP_STRINGS); | 1887 return GetOwnPropertyKeys(isolate, args, SKIP_STRINGS); |
| 1912 } | 1888 } |
| 1913 | 1889 |
| 1914 | |
| 1915 // ES#sec-object.is Object.is ( value1, value2 ) | 1890 // ES#sec-object.is Object.is ( value1, value2 ) |
| 1916 BUILTIN(ObjectIs) { | 1891 BUILTIN(ObjectIs) { |
| 1917 SealHandleScope shs(isolate); | 1892 SealHandleScope shs(isolate); |
| 1918 DCHECK_EQ(3, args.length()); | 1893 DCHECK_EQ(3, args.length()); |
| 1919 Handle<Object> value1 = args.at<Object>(1); | 1894 Handle<Object> value1 = args.at<Object>(1); |
| 1920 Handle<Object> value2 = args.at<Object>(2); | 1895 Handle<Object> value2 = args.at<Object>(2); |
| 1921 return isolate->heap()->ToBoolean(value1->SameValue(*value2)); | 1896 return isolate->heap()->ToBoolean(value1->SameValue(*value2)); |
| 1922 } | 1897 } |
| 1923 | 1898 |
| 1924 | |
| 1925 // ES6 section 19.1.2.11 Object.isExtensible ( O ) | 1899 // ES6 section 19.1.2.11 Object.isExtensible ( O ) |
| 1926 BUILTIN(ObjectIsExtensible) { | 1900 BUILTIN(ObjectIsExtensible) { |
| 1927 HandleScope scope(isolate); | 1901 HandleScope scope(isolate); |
| 1928 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1902 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1929 Maybe<bool> result = | 1903 Maybe<bool> result = |
| 1930 object->IsJSReceiver() | 1904 object->IsJSReceiver() |
| 1931 ? JSReceiver::IsExtensible(Handle<JSReceiver>::cast(object)) | 1905 ? JSReceiver::IsExtensible(Handle<JSReceiver>::cast(object)) |
| 1932 : Just(false); | 1906 : Just(false); |
| 1933 MAYBE_RETURN(result, isolate->heap()->exception()); | 1907 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 1934 return isolate->heap()->ToBoolean(result.FromJust()); | 1908 return isolate->heap()->ToBoolean(result.FromJust()); |
| 1935 } | 1909 } |
| 1936 | 1910 |
| 1937 | |
| 1938 // ES6 section 19.1.2.12 Object.isFrozen ( O ) | 1911 // ES6 section 19.1.2.12 Object.isFrozen ( O ) |
| 1939 BUILTIN(ObjectIsFrozen) { | 1912 BUILTIN(ObjectIsFrozen) { |
| 1940 HandleScope scope(isolate); | 1913 HandleScope scope(isolate); |
| 1941 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1914 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1942 Maybe<bool> result = object->IsJSReceiver() | 1915 Maybe<bool> result = object->IsJSReceiver() |
| 1943 ? JSReceiver::TestIntegrityLevel( | 1916 ? JSReceiver::TestIntegrityLevel( |
| 1944 Handle<JSReceiver>::cast(object), FROZEN) | 1917 Handle<JSReceiver>::cast(object), FROZEN) |
| 1945 : Just(true); | 1918 : Just(true); |
| 1946 MAYBE_RETURN(result, isolate->heap()->exception()); | 1919 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 1947 return isolate->heap()->ToBoolean(result.FromJust()); | 1920 return isolate->heap()->ToBoolean(result.FromJust()); |
| 1948 } | 1921 } |
| 1949 | 1922 |
| 1950 | |
| 1951 // ES6 section 19.1.2.13 Object.isSealed ( O ) | 1923 // ES6 section 19.1.2.13 Object.isSealed ( O ) |
| 1952 BUILTIN(ObjectIsSealed) { | 1924 BUILTIN(ObjectIsSealed) { |
| 1953 HandleScope scope(isolate); | 1925 HandleScope scope(isolate); |
| 1954 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1926 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1955 Maybe<bool> result = object->IsJSReceiver() | 1927 Maybe<bool> result = object->IsJSReceiver() |
| 1956 ? JSReceiver::TestIntegrityLevel( | 1928 ? JSReceiver::TestIntegrityLevel( |
| 1957 Handle<JSReceiver>::cast(object), SEALED) | 1929 Handle<JSReceiver>::cast(object), SEALED) |
| 1958 : Just(true); | 1930 : Just(true); |
| 1959 MAYBE_RETURN(result, isolate->heap()->exception()); | 1931 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 1960 return isolate->heap()->ToBoolean(result.FromJust()); | 1932 return isolate->heap()->ToBoolean(result.FromJust()); |
| 1961 } | 1933 } |
| 1962 | 1934 |
| 1963 | |
| 1964 // ES6 section 19.1.2.14 Object.keys ( O ) | 1935 // ES6 section 19.1.2.14 Object.keys ( O ) |
| 1965 BUILTIN(ObjectKeys) { | 1936 BUILTIN(ObjectKeys) { |
| 1966 HandleScope scope(isolate); | 1937 HandleScope scope(isolate); |
| 1967 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1938 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 1968 Handle<JSReceiver> receiver; | 1939 Handle<JSReceiver> receiver; |
| 1969 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1940 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 1970 Object::ToObject(isolate, object)); | 1941 Object::ToObject(isolate, object)); |
| 1971 | 1942 |
| 1972 Handle<FixedArray> keys; | 1943 Handle<FixedArray> keys; |
| 1973 int enum_length = receiver->map()->EnumLength(); | 1944 int enum_length = receiver->map()->EnumLength(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2001 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1972 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 2002 Handle<JSReceiver> receiver; | 1973 Handle<JSReceiver> receiver; |
| 2003 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1974 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 2004 Object::ToObject(isolate, object)); | 1975 Object::ToObject(isolate, object)); |
| 2005 Handle<FixedArray> values; | 1976 Handle<FixedArray> values; |
| 2006 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1977 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2007 isolate, values, JSReceiver::GetOwnValues(receiver, ENUMERABLE_STRINGS)); | 1978 isolate, values, JSReceiver::GetOwnValues(receiver, ENUMERABLE_STRINGS)); |
| 2008 return *isolate->factory()->NewJSArrayWithElements(values); | 1979 return *isolate->factory()->NewJSArrayWithElements(values); |
| 2009 } | 1980 } |
| 2010 | 1981 |
| 2011 | |
| 2012 BUILTIN(ObjectEntries) { | 1982 BUILTIN(ObjectEntries) { |
| 2013 HandleScope scope(isolate); | 1983 HandleScope scope(isolate); |
| 2014 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1984 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 2015 Handle<JSReceiver> receiver; | 1985 Handle<JSReceiver> receiver; |
| 2016 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1986 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 2017 Object::ToObject(isolate, object)); | 1987 Object::ToObject(isolate, object)); |
| 2018 Handle<FixedArray> entries; | 1988 Handle<FixedArray> entries; |
| 2019 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1989 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2020 isolate, entries, | 1990 isolate, entries, |
| 2021 JSReceiver::GetOwnEntries(receiver, ENUMERABLE_STRINGS)); | 1991 JSReceiver::GetOwnEntries(receiver, ENUMERABLE_STRINGS)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 HandleScope scope(isolate); | 2034 HandleScope scope(isolate); |
| 2065 Handle<Object> object = args.atOrUndefined(isolate, 1); | 2035 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 2066 if (object->IsJSReceiver()) { | 2036 if (object->IsJSReceiver()) { |
| 2067 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), | 2037 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), |
| 2068 Object::THROW_ON_ERROR), | 2038 Object::THROW_ON_ERROR), |
| 2069 isolate->heap()->exception()); | 2039 isolate->heap()->exception()); |
| 2070 } | 2040 } |
| 2071 return *object; | 2041 return *object; |
| 2072 } | 2042 } |
| 2073 | 2043 |
| 2074 | |
| 2075 // ES6 section 19.1.2.17 Object.seal ( O ) | 2044 // ES6 section 19.1.2.17 Object.seal ( O ) |
| 2076 BUILTIN(ObjectSeal) { | 2045 BUILTIN(ObjectSeal) { |
| 2077 HandleScope scope(isolate); | 2046 HandleScope scope(isolate); |
| 2078 Handle<Object> object = args.atOrUndefined(isolate, 1); | 2047 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 2079 if (object->IsJSReceiver()) { | 2048 if (object->IsJSReceiver()) { |
| 2080 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), | 2049 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), |
| 2081 SEALED, Object::THROW_ON_ERROR), | 2050 SEALED, Object::THROW_ON_ERROR), |
| 2082 isolate->heap()->exception()); | 2051 isolate->heap()->exception()); |
| 2083 } | 2052 } |
| 2084 return *object; | 2053 return *object; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2162 if (callback == NULL) { | 2131 if (callback == NULL) { |
| 2163 // No callback set and code generation disallowed. | 2132 // No callback set and code generation disallowed. |
| 2164 return false; | 2133 return false; |
| 2165 } else { | 2134 } else { |
| 2166 // Callback set. Let it decide if code generation is allowed. | 2135 // Callback set. Let it decide if code generation is allowed. |
| 2167 VMState<EXTERNAL> state(isolate); | 2136 VMState<EXTERNAL> state(isolate); |
| 2168 return callback(v8::Utils::ToLocal(context)); | 2137 return callback(v8::Utils::ToLocal(context)); |
| 2169 } | 2138 } |
| 2170 } | 2139 } |
| 2171 | 2140 |
| 2172 | |
| 2173 MaybeHandle<JSFunction> CompileString(Handle<Context> context, | 2141 MaybeHandle<JSFunction> CompileString(Handle<Context> context, |
| 2174 Handle<String> source, | 2142 Handle<String> source, |
| 2175 ParseRestriction restriction) { | 2143 ParseRestriction restriction) { |
| 2176 Isolate* const isolate = context->GetIsolate(); | 2144 Isolate* const isolate = context->GetIsolate(); |
| 2177 Handle<Context> native_context(context->native_context(), isolate); | 2145 Handle<Context> native_context(context->native_context(), isolate); |
| 2178 | 2146 |
| 2179 // Check if native context allows code generation from | 2147 // Check if native context allows code generation from |
| 2180 // strings. Throw an exception if it doesn't. | 2148 // strings. Throw an exception if it doesn't. |
| 2181 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && | 2149 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && |
| 2182 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 2150 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
| 2183 Handle<Object> error_message = | 2151 Handle<Object> error_message = |
| 2184 native_context->ErrorMessageForCodeGenerationFromStrings(); | 2152 native_context->ErrorMessageForCodeGenerationFromStrings(); |
| 2185 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, | 2153 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, |
| 2186 error_message), | 2154 error_message), |
| 2187 JSFunction); | 2155 JSFunction); |
| 2188 } | 2156 } |
| 2189 | 2157 |
| 2190 // Compile source string in the native context. | 2158 // Compile source string in the native context. |
| 2191 int eval_scope_position = 0; | 2159 int eval_scope_position = 0; |
| 2192 int eval_position = kNoSourcePosition; | 2160 int eval_position = kNoSourcePosition; |
| 2193 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); | 2161 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); |
| 2194 return Compiler::GetFunctionFromEval(source, outer_info, native_context, | 2162 return Compiler::GetFunctionFromEval(source, outer_info, native_context, |
| 2195 SLOPPY, restriction, eval_scope_position, | 2163 SLOPPY, restriction, eval_scope_position, |
| 2196 eval_position); | 2164 eval_position); |
| 2197 } | 2165 } |
| 2198 | 2166 |
| 2199 } // namespace | 2167 } // namespace |
| 2200 | 2168 |
| 2201 | |
| 2202 // ES6 section 18.2.1 eval (x) | 2169 // ES6 section 18.2.1 eval (x) |
| 2203 BUILTIN(GlobalEval) { | 2170 BUILTIN(GlobalEval) { |
| 2204 HandleScope scope(isolate); | 2171 HandleScope scope(isolate); |
| 2205 Handle<Object> x = args.atOrUndefined(isolate, 1); | 2172 Handle<Object> x = args.atOrUndefined(isolate, 1); |
| 2206 Handle<JSFunction> target = args.target<JSFunction>(); | 2173 Handle<JSFunction> target = args.target<JSFunction>(); |
| 2207 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); | 2174 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); |
| 2208 if (!x->IsString()) return *x; | 2175 if (!x->IsString()) return *x; |
| 2209 Handle<JSFunction> function; | 2176 Handle<JSFunction> function; |
| 2210 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2177 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2211 isolate, function, | 2178 isolate, function, |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 | 2993 |
| 3027 void Generate_GeneratorPrototypeResume( | 2994 void Generate_GeneratorPrototypeResume( |
| 3028 CodeStubAssembler* assembler, JSGeneratorObject::ResumeMode resume_mode, | 2995 CodeStubAssembler* assembler, JSGeneratorObject::ResumeMode resume_mode, |
| 3029 char const* const method_name) { | 2996 char const* const method_name) { |
| 3030 typedef CodeStubAssembler::Label Label; | 2997 typedef CodeStubAssembler::Label Label; |
| 3031 typedef compiler::Node Node; | 2998 typedef compiler::Node Node; |
| 3032 | 2999 |
| 3033 Node* receiver = assembler->Parameter(0); | 3000 Node* receiver = assembler->Parameter(0); |
| 3034 Node* value = assembler->Parameter(1); | 3001 Node* value = assembler->Parameter(1); |
| 3035 Node* context = assembler->Parameter(4); | 3002 Node* context = assembler->Parameter(4); |
| 3036 Node* closed = assembler->SmiConstant( | 3003 Node* closed = |
| 3037 Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); | 3004 assembler->SmiConstant(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); |
| 3038 | 3005 |
| 3039 // Check if the {receiver} is actually a JSGeneratorObject. | 3006 // Check if the {receiver} is actually a JSGeneratorObject. |
| 3040 Label if_receiverisincompatible(assembler, Label::kDeferred); | 3007 Label if_receiverisincompatible(assembler, Label::kDeferred); |
| 3041 assembler->GotoIf(assembler->WordIsSmi(receiver), &if_receiverisincompatible); | 3008 assembler->GotoIf(assembler->WordIsSmi(receiver), &if_receiverisincompatible); |
| 3042 Node* receiver_instance_type = assembler->LoadInstanceType(receiver); | 3009 Node* receiver_instance_type = assembler->LoadInstanceType(receiver); |
| 3043 assembler->GotoUnless(assembler->Word32Equal( | 3010 assembler->GotoUnless(assembler->Word32Equal( |
| 3044 receiver_instance_type, | 3011 receiver_instance_type, |
| 3045 assembler->Int32Constant(JS_GENERATOR_OBJECT_TYPE)), | 3012 assembler->Int32Constant(JS_GENERATOR_OBJECT_TYPE)), |
| 3046 &if_receiverisincompatible); | 3013 &if_receiverisincompatible); |
| 3047 | 3014 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3151 return isolate->heap()->exception(); | 3118 return isolate->heap()->exception(); |
| 3152 } | 3119 } |
| 3153 | 3120 |
| 3154 Maybe<bool> result = | 3121 Maybe<bool> result = |
| 3155 JSReceiver::DefineOwnProperty(isolate, Handle<JSReceiver>::cast(target), | 3122 JSReceiver::DefineOwnProperty(isolate, Handle<JSReceiver>::cast(target), |
| 3156 name, &desc, Object::DONT_THROW); | 3123 name, &desc, Object::DONT_THROW); |
| 3157 MAYBE_RETURN(result, isolate->heap()->exception()); | 3124 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 3158 return *isolate->factory()->ToBoolean(result.FromJust()); | 3125 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 3159 } | 3126 } |
| 3160 | 3127 |
| 3161 | |
| 3162 // ES6 section 26.1.4 Reflect.deleteProperty | 3128 // ES6 section 26.1.4 Reflect.deleteProperty |
| 3163 BUILTIN(ReflectDeleteProperty) { | 3129 BUILTIN(ReflectDeleteProperty) { |
| 3164 HandleScope scope(isolate); | 3130 HandleScope scope(isolate); |
| 3165 DCHECK_EQ(3, args.length()); | 3131 DCHECK_EQ(3, args.length()); |
| 3166 Handle<Object> target = args.at<Object>(1); | 3132 Handle<Object> target = args.at<Object>(1); |
| 3167 Handle<Object> key = args.at<Object>(2); | 3133 Handle<Object> key = args.at<Object>(2); |
| 3168 | 3134 |
| 3169 if (!target->IsJSReceiver()) { | 3135 if (!target->IsJSReceiver()) { |
| 3170 THROW_NEW_ERROR_RETURN_FAILURE( | 3136 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3171 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3137 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3172 isolate->factory()->NewStringFromAsciiChecked( | 3138 isolate->factory()->NewStringFromAsciiChecked( |
| 3173 "Reflect.deleteProperty"))); | 3139 "Reflect.deleteProperty"))); |
| 3174 } | 3140 } |
| 3175 | 3141 |
| 3176 Handle<Name> name; | 3142 Handle<Name> name; |
| 3177 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 3143 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 3178 Object::ToName(isolate, key)); | 3144 Object::ToName(isolate, key)); |
| 3179 | 3145 |
| 3180 Maybe<bool> result = JSReceiver::DeletePropertyOrElement( | 3146 Maybe<bool> result = JSReceiver::DeletePropertyOrElement( |
| 3181 Handle<JSReceiver>::cast(target), name, SLOPPY); | 3147 Handle<JSReceiver>::cast(target), name, SLOPPY); |
| 3182 MAYBE_RETURN(result, isolate->heap()->exception()); | 3148 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 3183 return *isolate->factory()->ToBoolean(result.FromJust()); | 3149 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 3184 } | 3150 } |
| 3185 | 3151 |
| 3186 | |
| 3187 // ES6 section 26.1.6 Reflect.get | 3152 // ES6 section 26.1.6 Reflect.get |
| 3188 BUILTIN(ReflectGet) { | 3153 BUILTIN(ReflectGet) { |
| 3189 HandleScope scope(isolate); | 3154 HandleScope scope(isolate); |
| 3190 Handle<Object> target = args.atOrUndefined(isolate, 1); | 3155 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 3191 Handle<Object> key = args.atOrUndefined(isolate, 2); | 3156 Handle<Object> key = args.atOrUndefined(isolate, 2); |
| 3192 Handle<Object> receiver = args.length() > 3 ? args.at<Object>(3) : target; | 3157 Handle<Object> receiver = args.length() > 3 ? args.at<Object>(3) : target; |
| 3193 | 3158 |
| 3194 if (!target->IsJSReceiver()) { | 3159 if (!target->IsJSReceiver()) { |
| 3195 THROW_NEW_ERROR_RETURN_FAILURE( | 3160 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3196 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3161 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3197 isolate->factory()->NewStringFromAsciiChecked( | 3162 isolate->factory()->NewStringFromAsciiChecked( |
| 3198 "Reflect.get"))); | 3163 "Reflect.get"))); |
| 3199 } | 3164 } |
| 3200 | 3165 |
| 3201 Handle<Name> name; | 3166 Handle<Name> name; |
| 3202 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 3167 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 3203 Object::ToName(isolate, key)); | 3168 Object::ToName(isolate, key)); |
| 3204 | 3169 |
| 3205 RETURN_RESULT_OR_FAILURE( | 3170 RETURN_RESULT_OR_FAILURE( |
| 3206 isolate, Object::GetPropertyOrElement(receiver, name, | 3171 isolate, Object::GetPropertyOrElement(receiver, name, |
| 3207 Handle<JSReceiver>::cast(target))); | 3172 Handle<JSReceiver>::cast(target))); |
| 3208 } | 3173 } |
| 3209 | 3174 |
| 3210 | |
| 3211 // ES6 section 26.1.7 Reflect.getOwnPropertyDescriptor | 3175 // ES6 section 26.1.7 Reflect.getOwnPropertyDescriptor |
| 3212 BUILTIN(ReflectGetOwnPropertyDescriptor) { | 3176 BUILTIN(ReflectGetOwnPropertyDescriptor) { |
| 3213 HandleScope scope(isolate); | 3177 HandleScope scope(isolate); |
| 3214 DCHECK_EQ(3, args.length()); | 3178 DCHECK_EQ(3, args.length()); |
| 3215 Handle<Object> target = args.at<Object>(1); | 3179 Handle<Object> target = args.at<Object>(1); |
| 3216 Handle<Object> key = args.at<Object>(2); | 3180 Handle<Object> key = args.at<Object>(2); |
| 3217 | 3181 |
| 3218 if (!target->IsJSReceiver()) { | 3182 if (!target->IsJSReceiver()) { |
| 3219 THROW_NEW_ERROR_RETURN_FAILURE( | 3183 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3220 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3184 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3221 isolate->factory()->NewStringFromAsciiChecked( | 3185 isolate->factory()->NewStringFromAsciiChecked( |
| 3222 "Reflect.getOwnPropertyDescriptor"))); | 3186 "Reflect.getOwnPropertyDescriptor"))); |
| 3223 } | 3187 } |
| 3224 | 3188 |
| 3225 Handle<Name> name; | 3189 Handle<Name> name; |
| 3226 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 3190 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 3227 Object::ToName(isolate, key)); | 3191 Object::ToName(isolate, key)); |
| 3228 | 3192 |
| 3229 PropertyDescriptor desc; | 3193 PropertyDescriptor desc; |
| 3230 Maybe<bool> found = JSReceiver::GetOwnPropertyDescriptor( | 3194 Maybe<bool> found = JSReceiver::GetOwnPropertyDescriptor( |
| 3231 isolate, Handle<JSReceiver>::cast(target), name, &desc); | 3195 isolate, Handle<JSReceiver>::cast(target), name, &desc); |
| 3232 MAYBE_RETURN(found, isolate->heap()->exception()); | 3196 MAYBE_RETURN(found, isolate->heap()->exception()); |
| 3233 if (!found.FromJust()) return isolate->heap()->undefined_value(); | 3197 if (!found.FromJust()) return isolate->heap()->undefined_value(); |
| 3234 return *desc.ToObject(isolate); | 3198 return *desc.ToObject(isolate); |
| 3235 } | 3199 } |
| 3236 | 3200 |
| 3237 | |
| 3238 // ES6 section 26.1.8 Reflect.getPrototypeOf | 3201 // ES6 section 26.1.8 Reflect.getPrototypeOf |
| 3239 BUILTIN(ReflectGetPrototypeOf) { | 3202 BUILTIN(ReflectGetPrototypeOf) { |
| 3240 HandleScope scope(isolate); | 3203 HandleScope scope(isolate); |
| 3241 DCHECK_EQ(2, args.length()); | 3204 DCHECK_EQ(2, args.length()); |
| 3242 Handle<Object> target = args.at<Object>(1); | 3205 Handle<Object> target = args.at<Object>(1); |
| 3243 | 3206 |
| 3244 if (!target->IsJSReceiver()) { | 3207 if (!target->IsJSReceiver()) { |
| 3245 THROW_NEW_ERROR_RETURN_FAILURE( | 3208 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3246 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3209 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3247 isolate->factory()->NewStringFromAsciiChecked( | 3210 isolate->factory()->NewStringFromAsciiChecked( |
| 3248 "Reflect.getPrototypeOf"))); | 3211 "Reflect.getPrototypeOf"))); |
| 3249 } | 3212 } |
| 3250 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(target); | 3213 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(target); |
| 3251 RETURN_RESULT_OR_FAILURE(isolate, | 3214 RETURN_RESULT_OR_FAILURE(isolate, |
| 3252 JSReceiver::GetPrototype(isolate, receiver)); | 3215 JSReceiver::GetPrototype(isolate, receiver)); |
| 3253 } | 3216 } |
| 3254 | 3217 |
| 3255 | |
| 3256 // ES6 section 26.1.9 Reflect.has | 3218 // ES6 section 26.1.9 Reflect.has |
| 3257 BUILTIN(ReflectHas) { | 3219 BUILTIN(ReflectHas) { |
| 3258 HandleScope scope(isolate); | 3220 HandleScope scope(isolate); |
| 3259 DCHECK_EQ(3, args.length()); | 3221 DCHECK_EQ(3, args.length()); |
| 3260 Handle<Object> target = args.at<Object>(1); | 3222 Handle<Object> target = args.at<Object>(1); |
| 3261 Handle<Object> key = args.at<Object>(2); | 3223 Handle<Object> key = args.at<Object>(2); |
| 3262 | 3224 |
| 3263 if (!target->IsJSReceiver()) { | 3225 if (!target->IsJSReceiver()) { |
| 3264 THROW_NEW_ERROR_RETURN_FAILURE( | 3226 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3265 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3227 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3266 isolate->factory()->NewStringFromAsciiChecked( | 3228 isolate->factory()->NewStringFromAsciiChecked( |
| 3267 "Reflect.has"))); | 3229 "Reflect.has"))); |
| 3268 } | 3230 } |
| 3269 | 3231 |
| 3270 Handle<Name> name; | 3232 Handle<Name> name; |
| 3271 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 3233 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 3272 Object::ToName(isolate, key)); | 3234 Object::ToName(isolate, key)); |
| 3273 | 3235 |
| 3274 Maybe<bool> result = | 3236 Maybe<bool> result = |
| 3275 JSReceiver::HasProperty(Handle<JSReceiver>::cast(target), name); | 3237 JSReceiver::HasProperty(Handle<JSReceiver>::cast(target), name); |
| 3276 return result.IsJust() ? *isolate->factory()->ToBoolean(result.FromJust()) | 3238 return result.IsJust() ? *isolate->factory()->ToBoolean(result.FromJust()) |
| 3277 : isolate->heap()->exception(); | 3239 : isolate->heap()->exception(); |
| 3278 } | 3240 } |
| 3279 | 3241 |
| 3280 | |
| 3281 // ES6 section 26.1.10 Reflect.isExtensible | 3242 // ES6 section 26.1.10 Reflect.isExtensible |
| 3282 BUILTIN(ReflectIsExtensible) { | 3243 BUILTIN(ReflectIsExtensible) { |
| 3283 HandleScope scope(isolate); | 3244 HandleScope scope(isolate); |
| 3284 DCHECK_EQ(2, args.length()); | 3245 DCHECK_EQ(2, args.length()); |
| 3285 Handle<Object> target = args.at<Object>(1); | 3246 Handle<Object> target = args.at<Object>(1); |
| 3286 | 3247 |
| 3287 if (!target->IsJSReceiver()) { | 3248 if (!target->IsJSReceiver()) { |
| 3288 THROW_NEW_ERROR_RETURN_FAILURE( | 3249 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3289 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3250 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3290 isolate->factory()->NewStringFromAsciiChecked( | 3251 isolate->factory()->NewStringFromAsciiChecked( |
| 3291 "Reflect.isExtensible"))); | 3252 "Reflect.isExtensible"))); |
| 3292 } | 3253 } |
| 3293 | 3254 |
| 3294 Maybe<bool> result = | 3255 Maybe<bool> result = |
| 3295 JSReceiver::IsExtensible(Handle<JSReceiver>::cast(target)); | 3256 JSReceiver::IsExtensible(Handle<JSReceiver>::cast(target)); |
| 3296 MAYBE_RETURN(result, isolate->heap()->exception()); | 3257 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 3297 return *isolate->factory()->ToBoolean(result.FromJust()); | 3258 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 3298 } | 3259 } |
| 3299 | 3260 |
| 3300 | |
| 3301 // ES6 section 26.1.11 Reflect.ownKeys | 3261 // ES6 section 26.1.11 Reflect.ownKeys |
| 3302 BUILTIN(ReflectOwnKeys) { | 3262 BUILTIN(ReflectOwnKeys) { |
| 3303 HandleScope scope(isolate); | 3263 HandleScope scope(isolate); |
| 3304 DCHECK_EQ(2, args.length()); | 3264 DCHECK_EQ(2, args.length()); |
| 3305 Handle<Object> target = args.at<Object>(1); | 3265 Handle<Object> target = args.at<Object>(1); |
| 3306 | 3266 |
| 3307 if (!target->IsJSReceiver()) { | 3267 if (!target->IsJSReceiver()) { |
| 3308 THROW_NEW_ERROR_RETURN_FAILURE( | 3268 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3309 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3269 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3310 isolate->factory()->NewStringFromAsciiChecked( | 3270 isolate->factory()->NewStringFromAsciiChecked( |
| 3311 "Reflect.ownKeys"))); | 3271 "Reflect.ownKeys"))); |
| 3312 } | 3272 } |
| 3313 | 3273 |
| 3314 Handle<FixedArray> keys; | 3274 Handle<FixedArray> keys; |
| 3315 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3275 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 3316 isolate, keys, | 3276 isolate, keys, |
| 3317 KeyAccumulator::GetKeys(Handle<JSReceiver>::cast(target), | 3277 KeyAccumulator::GetKeys(Handle<JSReceiver>::cast(target), |
| 3318 KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, | 3278 KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, |
| 3319 GetKeysConversion::kConvertToString)); | 3279 GetKeysConversion::kConvertToString)); |
| 3320 return *isolate->factory()->NewJSArrayWithElements(keys); | 3280 return *isolate->factory()->NewJSArrayWithElements(keys); |
| 3321 } | 3281 } |
| 3322 | 3282 |
| 3323 | |
| 3324 // ES6 section 26.1.12 Reflect.preventExtensions | 3283 // ES6 section 26.1.12 Reflect.preventExtensions |
| 3325 BUILTIN(ReflectPreventExtensions) { | 3284 BUILTIN(ReflectPreventExtensions) { |
| 3326 HandleScope scope(isolate); | 3285 HandleScope scope(isolate); |
| 3327 DCHECK_EQ(2, args.length()); | 3286 DCHECK_EQ(2, args.length()); |
| 3328 Handle<Object> target = args.at<Object>(1); | 3287 Handle<Object> target = args.at<Object>(1); |
| 3329 | 3288 |
| 3330 if (!target->IsJSReceiver()) { | 3289 if (!target->IsJSReceiver()) { |
| 3331 THROW_NEW_ERROR_RETURN_FAILURE( | 3290 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3332 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3291 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3333 isolate->factory()->NewStringFromAsciiChecked( | 3292 isolate->factory()->NewStringFromAsciiChecked( |
| 3334 "Reflect.preventExtensions"))); | 3293 "Reflect.preventExtensions"))); |
| 3335 } | 3294 } |
| 3336 | 3295 |
| 3337 Maybe<bool> result = JSReceiver::PreventExtensions( | 3296 Maybe<bool> result = JSReceiver::PreventExtensions( |
| 3338 Handle<JSReceiver>::cast(target), Object::DONT_THROW); | 3297 Handle<JSReceiver>::cast(target), Object::DONT_THROW); |
| 3339 MAYBE_RETURN(result, isolate->heap()->exception()); | 3298 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 3340 return *isolate->factory()->ToBoolean(result.FromJust()); | 3299 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 3341 } | 3300 } |
| 3342 | 3301 |
| 3343 | |
| 3344 // ES6 section 26.1.13 Reflect.set | 3302 // ES6 section 26.1.13 Reflect.set |
| 3345 BUILTIN(ReflectSet) { | 3303 BUILTIN(ReflectSet) { |
| 3346 HandleScope scope(isolate); | 3304 HandleScope scope(isolate); |
| 3347 Handle<Object> target = args.atOrUndefined(isolate, 1); | 3305 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 3348 Handle<Object> key = args.atOrUndefined(isolate, 2); | 3306 Handle<Object> key = args.atOrUndefined(isolate, 2); |
| 3349 Handle<Object> value = args.atOrUndefined(isolate, 3); | 3307 Handle<Object> value = args.atOrUndefined(isolate, 3); |
| 3350 Handle<Object> receiver = args.length() > 4 ? args.at<Object>(4) : target; | 3308 Handle<Object> receiver = args.length() > 4 ? args.at<Object>(4) : target; |
| 3351 | 3309 |
| 3352 if (!target->IsJSReceiver()) { | 3310 if (!target->IsJSReceiver()) { |
| 3353 THROW_NEW_ERROR_RETURN_FAILURE( | 3311 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3354 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3312 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3355 isolate->factory()->NewStringFromAsciiChecked( | 3313 isolate->factory()->NewStringFromAsciiChecked( |
| 3356 "Reflect.set"))); | 3314 "Reflect.set"))); |
| 3357 } | 3315 } |
| 3358 | 3316 |
| 3359 Handle<Name> name; | 3317 Handle<Name> name; |
| 3360 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 3318 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 3361 Object::ToName(isolate, key)); | 3319 Object::ToName(isolate, key)); |
| 3362 | 3320 |
| 3363 LookupIterator it = LookupIterator::PropertyOrElement( | 3321 LookupIterator it = LookupIterator::PropertyOrElement( |
| 3364 isolate, receiver, name, Handle<JSReceiver>::cast(target)); | 3322 isolate, receiver, name, Handle<JSReceiver>::cast(target)); |
| 3365 Maybe<bool> result = Object::SetSuperProperty( | 3323 Maybe<bool> result = Object::SetSuperProperty( |
| 3366 &it, value, SLOPPY, Object::MAY_BE_STORE_FROM_KEYED); | 3324 &it, value, SLOPPY, Object::MAY_BE_STORE_FROM_KEYED); |
| 3367 MAYBE_RETURN(result, isolate->heap()->exception()); | 3325 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 3368 return *isolate->factory()->ToBoolean(result.FromJust()); | 3326 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 3369 } | 3327 } |
| 3370 | 3328 |
| 3371 | |
| 3372 // ES6 section 26.1.14 Reflect.setPrototypeOf | 3329 // ES6 section 26.1.14 Reflect.setPrototypeOf |
| 3373 BUILTIN(ReflectSetPrototypeOf) { | 3330 BUILTIN(ReflectSetPrototypeOf) { |
| 3374 HandleScope scope(isolate); | 3331 HandleScope scope(isolate); |
| 3375 DCHECK_EQ(3, args.length()); | 3332 DCHECK_EQ(3, args.length()); |
| 3376 Handle<Object> target = args.at<Object>(1); | 3333 Handle<Object> target = args.at<Object>(1); |
| 3377 Handle<Object> proto = args.at<Object>(2); | 3334 Handle<Object> proto = args.at<Object>(2); |
| 3378 | 3335 |
| 3379 if (!target->IsJSReceiver()) { | 3336 if (!target->IsJSReceiver()) { |
| 3380 THROW_NEW_ERROR_RETURN_FAILURE( | 3337 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3381 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 3338 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 3382 isolate->factory()->NewStringFromAsciiChecked( | 3339 isolate->factory()->NewStringFromAsciiChecked( |
| 3383 "Reflect.setPrototypeOf"))); | 3340 "Reflect.setPrototypeOf"))); |
| 3384 } | 3341 } |
| 3385 | 3342 |
| 3386 if (!proto->IsJSReceiver() && !proto->IsNull(isolate)) { | 3343 if (!proto->IsJSReceiver() && !proto->IsNull(isolate)) { |
| 3387 THROW_NEW_ERROR_RETURN_FAILURE( | 3344 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3388 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, proto)); | 3345 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, proto)); |
| 3389 } | 3346 } |
| 3390 | 3347 |
| 3391 Maybe<bool> result = JSReceiver::SetPrototype( | 3348 Maybe<bool> result = JSReceiver::SetPrototype( |
| 3392 Handle<JSReceiver>::cast(target), proto, true, Object::DONT_THROW); | 3349 Handle<JSReceiver>::cast(target), proto, true, Object::DONT_THROW); |
| 3393 MAYBE_RETURN(result, isolate->heap()->exception()); | 3350 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 3394 return *isolate->factory()->ToBoolean(result.FromJust()); | 3351 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 3395 } | 3352 } |
| 3396 | 3353 |
| 3397 | |
| 3398 // ----------------------------------------------------------------------------- | 3354 // ----------------------------------------------------------------------------- |
| 3399 // ES6 section 19.3 Boolean Objects | 3355 // ES6 section 19.3 Boolean Objects |
| 3400 | 3356 |
| 3401 | |
| 3402 // ES6 section 19.3.1.1 Boolean ( value ) for the [[Call]] case. | 3357 // ES6 section 19.3.1.1 Boolean ( value ) for the [[Call]] case. |
| 3403 BUILTIN(BooleanConstructor) { | 3358 BUILTIN(BooleanConstructor) { |
| 3404 HandleScope scope(isolate); | 3359 HandleScope scope(isolate); |
| 3405 Handle<Object> value = args.atOrUndefined(isolate, 1); | 3360 Handle<Object> value = args.atOrUndefined(isolate, 1); |
| 3406 return isolate->heap()->ToBoolean(value->BooleanValue()); | 3361 return isolate->heap()->ToBoolean(value->BooleanValue()); |
| 3407 } | 3362 } |
| 3408 | 3363 |
| 3409 | |
| 3410 // ES6 section 19.3.1.1 Boolean ( value ) for the [[Construct]] case. | 3364 // ES6 section 19.3.1.1 Boolean ( value ) for the [[Construct]] case. |
| 3411 BUILTIN(BooleanConstructor_ConstructStub) { | 3365 BUILTIN(BooleanConstructor_ConstructStub) { |
| 3412 HandleScope scope(isolate); | 3366 HandleScope scope(isolate); |
| 3413 Handle<Object> value = args.atOrUndefined(isolate, 1); | 3367 Handle<Object> value = args.atOrUndefined(isolate, 1); |
| 3414 Handle<JSFunction> target = args.target<JSFunction>(); | 3368 Handle<JSFunction> target = args.target<JSFunction>(); |
| 3415 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 3369 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
| 3416 DCHECK(*target == target->native_context()->boolean_function()); | 3370 DCHECK(*target == target->native_context()->boolean_function()); |
| 3417 Handle<JSObject> result; | 3371 Handle<JSObject> result; |
| 3418 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 3372 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 3419 JSObject::New(target, new_target)); | 3373 JSObject::New(target, new_target)); |
| 3420 Handle<JSValue>::cast(result)->set_value( | 3374 Handle<JSValue>::cast(result)->set_value( |
| 3421 isolate->heap()->ToBoolean(value->BooleanValue())); | 3375 isolate->heap()->ToBoolean(value->BooleanValue())); |
| 3422 return *result; | 3376 return *result; |
| 3423 } | 3377 } |
| 3424 | 3378 |
| 3425 | |
| 3426 // ES6 section 19.3.3.2 Boolean.prototype.toString ( ) | 3379 // ES6 section 19.3.3.2 Boolean.prototype.toString ( ) |
| 3427 void Builtins::Generate_BooleanPrototypeToString(CodeStubAssembler* assembler) { | 3380 void Builtins::Generate_BooleanPrototypeToString(CodeStubAssembler* assembler) { |
| 3428 typedef compiler::Node Node; | 3381 typedef compiler::Node Node; |
| 3429 | 3382 |
| 3430 Node* receiver = assembler->Parameter(0); | 3383 Node* receiver = assembler->Parameter(0); |
| 3431 Node* context = assembler->Parameter(3); | 3384 Node* context = assembler->Parameter(3); |
| 3432 | 3385 |
| 3433 Node* value = assembler->ToThisValue( | 3386 Node* value = assembler->ToThisValue( |
| 3434 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.toString"); | 3387 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.toString"); |
| 3435 Node* result = assembler->LoadObjectField(value, Oddball::kToStringOffset); | 3388 Node* result = assembler->LoadObjectField(value, Oddball::kToStringOffset); |
| 3436 assembler->Return(result); | 3389 assembler->Return(result); |
| 3437 } | 3390 } |
| 3438 | 3391 |
| 3439 // ES6 section 19.3.3.3 Boolean.prototype.valueOf ( ) | 3392 // ES6 section 19.3.3.3 Boolean.prototype.valueOf ( ) |
| 3440 void Builtins::Generate_BooleanPrototypeValueOf(CodeStubAssembler* assembler) { | 3393 void Builtins::Generate_BooleanPrototypeValueOf(CodeStubAssembler* assembler) { |
| 3441 typedef compiler::Node Node; | 3394 typedef compiler::Node Node; |
| 3442 | 3395 |
| 3443 Node* receiver = assembler->Parameter(0); | 3396 Node* receiver = assembler->Parameter(0); |
| 3444 Node* context = assembler->Parameter(3); | 3397 Node* context = assembler->Parameter(3); |
| 3445 | 3398 |
| 3446 Node* result = assembler->ToThisValue( | 3399 Node* result = assembler->ToThisValue( |
| 3447 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.valueOf"); | 3400 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.valueOf"); |
| 3448 assembler->Return(result); | 3401 assembler->Return(result); |
| 3449 } | 3402 } |
| 3450 | 3403 |
| 3451 // ----------------------------------------------------------------------------- | 3404 // ----------------------------------------------------------------------------- |
| 3452 // ES6 section 24.2 DataView Objects | 3405 // ES6 section 24.2 DataView Objects |
| 3453 | 3406 |
| 3454 | |
| 3455 // ES6 section 24.2.2 The DataView Constructor for the [[Call]] case. | 3407 // ES6 section 24.2.2 The DataView Constructor for the [[Call]] case. |
| 3456 BUILTIN(DataViewConstructor) { | 3408 BUILTIN(DataViewConstructor) { |
| 3457 HandleScope scope(isolate); | 3409 HandleScope scope(isolate); |
| 3458 THROW_NEW_ERROR_RETURN_FAILURE( | 3410 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3459 isolate, | 3411 isolate, |
| 3460 NewTypeError(MessageTemplate::kConstructorNotFunction, | 3412 NewTypeError(MessageTemplate::kConstructorNotFunction, |
| 3461 isolate->factory()->NewStringFromAsciiChecked("DataView"))); | 3413 isolate->factory()->NewStringFromAsciiChecked("DataView"))); |
| 3462 } | 3414 } |
| 3463 | 3415 |
| 3464 | |
| 3465 // ES6 section 24.2.2 The DataView Constructor for the [[Construct]] case. | 3416 // ES6 section 24.2.2 The DataView Constructor for the [[Construct]] case. |
| 3466 BUILTIN(DataViewConstructor_ConstructStub) { | 3417 BUILTIN(DataViewConstructor_ConstructStub) { |
| 3467 HandleScope scope(isolate); | 3418 HandleScope scope(isolate); |
| 3468 Handle<JSFunction> target = args.target<JSFunction>(); | 3419 Handle<JSFunction> target = args.target<JSFunction>(); |
| 3469 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 3420 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
| 3470 Handle<Object> buffer = args.atOrUndefined(isolate, 1); | 3421 Handle<Object> buffer = args.atOrUndefined(isolate, 1); |
| 3471 Handle<Object> byte_offset = args.atOrUndefined(isolate, 2); | 3422 Handle<Object> byte_offset = args.atOrUndefined(isolate, 2); |
| 3472 Handle<Object> byte_length = args.atOrUndefined(isolate, 3); | 3423 Handle<Object> byte_length = args.atOrUndefined(isolate, 3); |
| 3473 | 3424 |
| 3474 // 2. If Type(buffer) is not Object, throw a TypeError exception. | 3425 // 2. If Type(buffer) is not Object, throw a TypeError exception. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3520 if (byte_length->IsUndefined(isolate)) { | 3471 if (byte_length->IsUndefined(isolate)) { |
| 3521 // 10. If byteLength is undefined, then | 3472 // 10. If byteLength is undefined, then |
| 3522 // a. Let viewByteLength be bufferByteLength - offset. | 3473 // a. Let viewByteLength be bufferByteLength - offset. |
| 3523 view_byte_length = | 3474 view_byte_length = |
| 3524 isolate->factory()->NewNumber(buffer_byte_length - offset->Number()); | 3475 isolate->factory()->NewNumber(buffer_byte_length - offset->Number()); |
| 3525 } else { | 3476 } else { |
| 3526 // 11. Else, | 3477 // 11. Else, |
| 3527 // a. Let viewByteLength be ? ToLength(byteLength). | 3478 // a. Let viewByteLength be ? ToLength(byteLength). |
| 3528 // b. If offset+viewByteLength > bufferByteLength, throw a RangeError | 3479 // b. If offset+viewByteLength > bufferByteLength, throw a RangeError |
| 3529 // exception | 3480 // exception |
| 3530 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3481 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, view_byte_length, |
| 3531 isolate, view_byte_length, Object::ToLength(isolate, byte_length)); | 3482 Object::ToLength(isolate, byte_length)); |
| 3532 if (offset->Number() + view_byte_length->Number() > buffer_byte_length) { | 3483 if (offset->Number() + view_byte_length->Number() > buffer_byte_length) { |
| 3533 THROW_NEW_ERROR_RETURN_FAILURE( | 3484 THROW_NEW_ERROR_RETURN_FAILURE( |
| 3534 isolate, NewRangeError(MessageTemplate::kInvalidDataViewLength)); | 3485 isolate, NewRangeError(MessageTemplate::kInvalidDataViewLength)); |
| 3535 } | 3486 } |
| 3536 } | 3487 } |
| 3537 | 3488 |
| 3538 // 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, | 3489 // 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, |
| 3539 // "%DataViewPrototype%", «[[DataView]], [[ViewedArrayBuffer]], | 3490 // "%DataViewPrototype%", «[[DataView]], [[ViewedArrayBuffer]], |
| 3540 // [[ByteLength]], [[ByteOffset]]»). | 3491 // [[ByteLength]], [[ByteOffset]]»). |
| 3541 // 13. Set O's [[DataView]] internal slot to true. | 3492 // 13. Set O's [[DataView]] internal slot to true. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3669 void Builtins::Generate_TypedArrayPrototypeLength( | 3620 void Builtins::Generate_TypedArrayPrototypeLength( |
| 3670 CodeStubAssembler* assembler) { | 3621 CodeStubAssembler* assembler) { |
| 3671 Generate_TypedArrayProtoypeGetter(assembler, | 3622 Generate_TypedArrayProtoypeGetter(assembler, |
| 3672 "get TypedArray.prototype.length", | 3623 "get TypedArray.prototype.length", |
| 3673 JSTypedArray::kLengthOffset); | 3624 JSTypedArray::kLengthOffset); |
| 3674 } | 3625 } |
| 3675 | 3626 |
| 3676 // ----------------------------------------------------------------------------- | 3627 // ----------------------------------------------------------------------------- |
| 3677 // ES6 section 20.3 Date Objects | 3628 // ES6 section 20.3 Date Objects |
| 3678 | 3629 |
| 3679 | |
| 3680 namespace { | 3630 namespace { |
| 3681 | 3631 |
| 3682 // ES6 section 20.3.1.1 Time Values and Time Range | 3632 // ES6 section 20.3.1.1 Time Values and Time Range |
| 3683 const double kMinYear = -1000000.0; | 3633 const double kMinYear = -1000000.0; |
| 3684 const double kMaxYear = -kMinYear; | 3634 const double kMaxYear = -kMinYear; |
| 3685 const double kMinMonth = -10000000.0; | 3635 const double kMinMonth = -10000000.0; |
| 3686 const double kMaxMonth = -kMinMonth; | 3636 const double kMaxMonth = -kMinMonth; |
| 3687 | 3637 |
| 3688 | |
| 3689 // 20.3.1.2 Day Number and Time within Day | 3638 // 20.3.1.2 Day Number and Time within Day |
| 3690 const double kMsPerDay = 86400000.0; | 3639 const double kMsPerDay = 86400000.0; |
| 3691 | 3640 |
| 3692 | |
| 3693 // ES6 section 20.3.1.11 Hours, Minutes, Second, and Milliseconds | 3641 // ES6 section 20.3.1.11 Hours, Minutes, Second, and Milliseconds |
| 3694 const double kMsPerSecond = 1000.0; | 3642 const double kMsPerSecond = 1000.0; |
| 3695 const double kMsPerMinute = 60000.0; | 3643 const double kMsPerMinute = 60000.0; |
| 3696 const double kMsPerHour = 3600000.0; | 3644 const double kMsPerHour = 3600000.0; |
| 3697 | 3645 |
| 3698 | |
| 3699 // ES6 section 20.3.1.14 MakeDate (day, time) | 3646 // ES6 section 20.3.1.14 MakeDate (day, time) |
| 3700 double MakeDate(double day, double time) { | 3647 double MakeDate(double day, double time) { |
| 3701 if (std::isfinite(day) && std::isfinite(time)) { | 3648 if (std::isfinite(day) && std::isfinite(time)) { |
| 3702 return time + day * kMsPerDay; | 3649 return time + day * kMsPerDay; |
| 3703 } | 3650 } |
| 3704 return std::numeric_limits<double>::quiet_NaN(); | 3651 return std::numeric_limits<double>::quiet_NaN(); |
| 3705 } | 3652 } |
| 3706 | 3653 |
| 3707 | |
| 3708 // ES6 section 20.3.1.13 MakeDay (year, month, date) | 3654 // ES6 section 20.3.1.13 MakeDay (year, month, date) |
| 3709 double MakeDay(double year, double month, double date) { | 3655 double MakeDay(double year, double month, double date) { |
| 3710 if ((kMinYear <= year && year <= kMaxYear) && | 3656 if ((kMinYear <= year && year <= kMaxYear) && |
| 3711 (kMinMonth <= month && month <= kMaxMonth) && std::isfinite(date)) { | 3657 (kMinMonth <= month && month <= kMaxMonth) && std::isfinite(date)) { |
| 3712 int y = FastD2I(year); | 3658 int y = FastD2I(year); |
| 3713 int m = FastD2I(month); | 3659 int m = FastD2I(month); |
| 3714 y += m / 12; | 3660 y += m / 12; |
| 3715 m %= 12; | 3661 m %= 12; |
| 3716 if (m < 0) { | 3662 if (m < 0) { |
| 3717 m += 12; | 3663 m += 12; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3742 } else { | 3688 } else { |
| 3743 static const int kDayFromMonth[] = {0, 31, 60, 91, 121, 152, | 3689 static const int kDayFromMonth[] = {0, 31, 60, 91, 121, 152, |
| 3744 182, 213, 244, 274, 305, 335}; | 3690 182, 213, 244, 274, 305, 335}; |
| 3745 day_from_year += kDayFromMonth[m]; | 3691 day_from_year += kDayFromMonth[m]; |
| 3746 } | 3692 } |
| 3747 return static_cast<double>(day_from_year - 1) + date; | 3693 return static_cast<double>(day_from_year - 1) + date; |
| 3748 } | 3694 } |
| 3749 return std::numeric_limits<double>::quiet_NaN(); | 3695 return std::numeric_limits<double>::quiet_NaN(); |
| 3750 } | 3696 } |
| 3751 | 3697 |
| 3752 | |
| 3753 // ES6 section 20.3.1.12 MakeTime (hour, min, sec, ms) | 3698 // ES6 section 20.3.1.12 MakeTime (hour, min, sec, ms) |
| 3754 double MakeTime(double hour, double min, double sec, double ms) { | 3699 double MakeTime(double hour, double min, double sec, double ms) { |
| 3755 if (std::isfinite(hour) && std::isfinite(min) && std::isfinite(sec) && | 3700 if (std::isfinite(hour) && std::isfinite(min) && std::isfinite(sec) && |
| 3756 std::isfinite(ms)) { | 3701 std::isfinite(ms)) { |
| 3757 double const h = DoubleToInteger(hour); | 3702 double const h = DoubleToInteger(hour); |
| 3758 double const m = DoubleToInteger(min); | 3703 double const m = DoubleToInteger(min); |
| 3759 double const s = DoubleToInteger(sec); | 3704 double const s = DoubleToInteger(sec); |
| 3760 double const milli = DoubleToInteger(ms); | 3705 double const milli = DoubleToInteger(ms); |
| 3761 return h * kMsPerHour + m * kMsPerMinute + s * kMsPerSecond + milli; | 3706 return h * kMsPerHour + m * kMsPerMinute + s * kMsPerSecond + milli; |
| 3762 } | 3707 } |
| 3763 return std::numeric_limits<double>::quiet_NaN(); | 3708 return std::numeric_limits<double>::quiet_NaN(); |
| 3764 } | 3709 } |
| 3765 | 3710 |
| 3766 | |
| 3767 // ES6 section 20.3.1.15 TimeClip (time) | 3711 // ES6 section 20.3.1.15 TimeClip (time) |
| 3768 double TimeClip(double time) { | 3712 double TimeClip(double time) { |
| 3769 if (-DateCache::kMaxTimeInMs <= time && time <= DateCache::kMaxTimeInMs) { | 3713 if (-DateCache::kMaxTimeInMs <= time && time <= DateCache::kMaxTimeInMs) { |
| 3770 return DoubleToInteger(time) + 0.0; | 3714 return DoubleToInteger(time) + 0.0; |
| 3771 } | 3715 } |
| 3772 return std::numeric_limits<double>::quiet_NaN(); | 3716 return std::numeric_limits<double>::quiet_NaN(); |
| 3773 } | 3717 } |
| 3774 | 3718 |
| 3775 | |
| 3776 const char* kShortWeekDays[] = {"Sun", "Mon", "Tue", "Wed", | 3719 const char* kShortWeekDays[] = {"Sun", "Mon", "Tue", "Wed", |
| 3777 "Thu", "Fri", "Sat"}; | 3720 "Thu", "Fri", "Sat"}; |
| 3778 const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 3721 const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 3779 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | 3722 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
| 3780 | 3723 |
| 3781 | |
| 3782 // ES6 section 20.3.1.16 Date Time String Format | 3724 // ES6 section 20.3.1.16 Date Time String Format |
| 3783 double ParseDateTimeString(Handle<String> str) { | 3725 double ParseDateTimeString(Handle<String> str) { |
| 3784 Isolate* const isolate = str->GetIsolate(); | 3726 Isolate* const isolate = str->GetIsolate(); |
| 3785 str = String::Flatten(str); | 3727 str = String::Flatten(str); |
| 3786 // TODO(bmeurer): Change DateParser to not use the FixedArray. | 3728 // TODO(bmeurer): Change DateParser to not use the FixedArray. |
| 3787 Handle<FixedArray> tmp = | 3729 Handle<FixedArray> tmp = |
| 3788 isolate->factory()->NewFixedArray(DateParser::OUTPUT_SIZE); | 3730 isolate->factory()->NewFixedArray(DateParser::OUTPUT_SIZE); |
| 3789 DisallowHeapAllocation no_gc; | 3731 DisallowHeapAllocation no_gc; |
| 3790 String::FlatContent str_content = str->GetFlatContent(); | 3732 String::FlatContent str_content = str->GetFlatContent(); |
| 3791 bool result; | 3733 bool result; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3803 if (tmp->get(7)->IsNull(isolate)) { | 3745 if (tmp->get(7)->IsNull(isolate)) { |
| 3804 if (!std::isnan(date)) { | 3746 if (!std::isnan(date)) { |
| 3805 date = isolate->date_cache()->ToUTC(static_cast<int64_t>(date)); | 3747 date = isolate->date_cache()->ToUTC(static_cast<int64_t>(date)); |
| 3806 } | 3748 } |
| 3807 } else { | 3749 } else { |
| 3808 date -= tmp->get(7)->Number() * 1000.0; | 3750 date -= tmp->get(7)->Number() * 1000.0; |
| 3809 } | 3751 } |
| 3810 return date; | 3752 return date; |
| 3811 } | 3753 } |
| 3812 | 3754 |
| 3813 | |
| 3814 enum ToDateStringMode { kDateOnly, kTimeOnly, kDateAndTime }; | 3755 enum ToDateStringMode { kDateOnly, kTimeOnly, kDateAndTime }; |
| 3815 | 3756 |
| 3816 | |
| 3817 // ES6 section 20.3.4.41.1 ToDateString(tv) | 3757 // ES6 section 20.3.4.41.1 ToDateString(tv) |
| 3818 void ToDateString(double time_val, Vector<char> str, DateCache* date_cache, | 3758 void ToDateString(double time_val, Vector<char> str, DateCache* date_cache, |
| 3819 ToDateStringMode mode = kDateAndTime) { | 3759 ToDateStringMode mode = kDateAndTime) { |
| 3820 if (std::isnan(time_val)) { | 3760 if (std::isnan(time_val)) { |
| 3821 SNPrintF(str, "Invalid Date"); | 3761 SNPrintF(str, "Invalid Date"); |
| 3822 return; | 3762 return; |
| 3823 } | 3763 } |
| 3824 int64_t time_ms = static_cast<int64_t>(time_val); | 3764 int64_t time_ms = static_cast<int64_t>(time_val); |
| 3825 int64_t local_time_ms = date_cache->ToLocal(time_ms); | 3765 int64_t local_time_ms = date_cache->ToLocal(time_ms); |
| 3826 int year, month, day, weekday, hour, min, sec, ms; | 3766 int year, month, day, weekday, hour, min, sec, ms; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3843 case kDateAndTime: | 3783 case kDateAndTime: |
| 3844 SNPrintF(str, "%s %s %02d %4d %02d:%02d:%02d GMT%c%02d%02d (%s)", | 3784 SNPrintF(str, "%s %s %02d %4d %02d:%02d:%02d GMT%c%02d%02d (%s)", |
| 3845 kShortWeekDays[weekday], kShortMonths[month], day, year, hour, | 3785 kShortWeekDays[weekday], kShortMonths[month], day, year, hour, |
| 3846 min, sec, (timezone_offset < 0) ? '-' : '+', timezone_hour, | 3786 min, sec, (timezone_offset < 0) ? '-' : '+', timezone_hour, |
| 3847 timezone_min, local_timezone); | 3787 timezone_min, local_timezone); |
| 3848 return; | 3788 return; |
| 3849 } | 3789 } |
| 3850 UNREACHABLE(); | 3790 UNREACHABLE(); |
| 3851 } | 3791 } |
| 3852 | 3792 |
| 3853 | |
| 3854 Object* SetLocalDateValue(Handle<JSDate> date, double time_val) { | 3793 Object* SetLocalDateValue(Handle<JSDate> date, double time_val) { |
| 3855 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && | 3794 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && |
| 3856 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { | 3795 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { |
| 3857 Isolate* const isolate = date->GetIsolate(); | 3796 Isolate* const isolate = date->GetIsolate(); |
| 3858 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); | 3797 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); |
| 3859 } else { | 3798 } else { |
| 3860 time_val = std::numeric_limits<double>::quiet_NaN(); | 3799 time_val = std::numeric_limits<double>::quiet_NaN(); |
| 3861 } | 3800 } |
| 3862 return *JSDate::SetValue(date, TimeClip(time_val)); | 3801 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 3863 } | 3802 } |
| 3864 | 3803 |
| 3865 } // namespace | 3804 } // namespace |
| 3866 | 3805 |
| 3867 | |
| 3868 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. | 3806 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. |
| 3869 BUILTIN(DateConstructor) { | 3807 BUILTIN(DateConstructor) { |
| 3870 HandleScope scope(isolate); | 3808 HandleScope scope(isolate); |
| 3871 double const time_val = JSDate::CurrentTimeValue(isolate); | 3809 double const time_val = JSDate::CurrentTimeValue(isolate); |
| 3872 char buffer[128]; | 3810 char buffer[128]; |
| 3873 ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); | 3811 ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); |
| 3874 RETURN_RESULT_OR_FAILURE( | 3812 RETURN_RESULT_OR_FAILURE( |
| 3875 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 3813 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
| 3876 } | 3814 } |
| 3877 | 3815 |
| 3878 | |
| 3879 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. | 3816 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. |
| 3880 BUILTIN(DateConstructor_ConstructStub) { | 3817 BUILTIN(DateConstructor_ConstructStub) { |
| 3881 HandleScope scope(isolate); | 3818 HandleScope scope(isolate); |
| 3882 int const argc = args.length() - 1; | 3819 int const argc = args.length() - 1; |
| 3883 Handle<JSFunction> target = args.target<JSFunction>(); | 3820 Handle<JSFunction> target = args.target<JSFunction>(); |
| 3884 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 3821 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
| 3885 double time_val; | 3822 double time_val; |
| 3886 if (argc == 0) { | 3823 if (argc == 0) { |
| 3887 time_val = JSDate::CurrentTimeValue(isolate); | 3824 time_val = JSDate::CurrentTimeValue(isolate); |
| 3888 } else if (argc == 1) { | 3825 } else if (argc == 1) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3950 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && | 3887 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && |
| 3951 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { | 3888 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { |
| 3952 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); | 3889 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); |
| 3953 } else { | 3890 } else { |
| 3954 time_val = std::numeric_limits<double>::quiet_NaN(); | 3891 time_val = std::numeric_limits<double>::quiet_NaN(); |
| 3955 } | 3892 } |
| 3956 } | 3893 } |
| 3957 RETURN_RESULT_OR_FAILURE(isolate, JSDate::New(target, new_target, time_val)); | 3894 RETURN_RESULT_OR_FAILURE(isolate, JSDate::New(target, new_target, time_val)); |
| 3958 } | 3895 } |
| 3959 | 3896 |
| 3960 | |
| 3961 // ES6 section 20.3.3.1 Date.now ( ) | 3897 // ES6 section 20.3.3.1 Date.now ( ) |
| 3962 BUILTIN(DateNow) { | 3898 BUILTIN(DateNow) { |
| 3963 HandleScope scope(isolate); | 3899 HandleScope scope(isolate); |
| 3964 return *isolate->factory()->NewNumber(JSDate::CurrentTimeValue(isolate)); | 3900 return *isolate->factory()->NewNumber(JSDate::CurrentTimeValue(isolate)); |
| 3965 } | 3901 } |
| 3966 | 3902 |
| 3967 | |
| 3968 // ES6 section 20.3.3.2 Date.parse ( string ) | 3903 // ES6 section 20.3.3.2 Date.parse ( string ) |
| 3969 BUILTIN(DateParse) { | 3904 BUILTIN(DateParse) { |
| 3970 HandleScope scope(isolate); | 3905 HandleScope scope(isolate); |
| 3971 Handle<String> string; | 3906 Handle<String> string; |
| 3972 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3907 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 3973 isolate, string, | 3908 isolate, string, |
| 3974 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); | 3909 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 3975 return *isolate->factory()->NewNumber(ParseDateTimeString(string)); | 3910 return *isolate->factory()->NewNumber(ParseDateTimeString(string)); |
| 3976 } | 3911 } |
| 3977 | 3912 |
| 3978 | |
| 3979 // ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms) | 3913 // ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms) |
| 3980 BUILTIN(DateUTC) { | 3914 BUILTIN(DateUTC) { |
| 3981 HandleScope scope(isolate); | 3915 HandleScope scope(isolate); |
| 3982 int const argc = args.length() - 1; | 3916 int const argc = args.length() - 1; |
| 3983 double year = std::numeric_limits<double>::quiet_NaN(); | 3917 double year = std::numeric_limits<double>::quiet_NaN(); |
| 3984 double month = std::numeric_limits<double>::quiet_NaN(); | 3918 double month = std::numeric_limits<double>::quiet_NaN(); |
| 3985 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; | 3919 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; |
| 3986 if (argc >= 1) { | 3920 if (argc >= 1) { |
| 3987 Handle<Object> year_object; | 3921 Handle<Object> year_object; |
| 3988 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, | 3922 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4028 } | 3962 } |
| 4029 if (!std::isnan(year)) { | 3963 if (!std::isnan(year)) { |
| 4030 double const y = DoubleToInteger(year); | 3964 double const y = DoubleToInteger(year); |
| 4031 if (0.0 <= y && y <= 99) year = 1900 + y; | 3965 if (0.0 <= y && y <= 99) year = 1900 + y; |
| 4032 } | 3966 } |
| 4033 double const day = MakeDay(year, month, date); | 3967 double const day = MakeDay(year, month, date); |
| 4034 double const time = MakeTime(hours, minutes, seconds, ms); | 3968 double const time = MakeTime(hours, minutes, seconds, ms); |
| 4035 return *isolate->factory()->NewNumber(TimeClip(MakeDate(day, time))); | 3969 return *isolate->factory()->NewNumber(TimeClip(MakeDate(day, time))); |
| 4036 } | 3970 } |
| 4037 | 3971 |
| 4038 | |
| 4039 // ES6 section 20.3.4.20 Date.prototype.setDate ( date ) | 3972 // ES6 section 20.3.4.20 Date.prototype.setDate ( date ) |
| 4040 BUILTIN(DatePrototypeSetDate) { | 3973 BUILTIN(DatePrototypeSetDate) { |
| 4041 HandleScope scope(isolate); | 3974 HandleScope scope(isolate); |
| 4042 CHECK_RECEIVER(JSDate, date, "Date.prototype.setDate"); | 3975 CHECK_RECEIVER(JSDate, date, "Date.prototype.setDate"); |
| 4043 Handle<Object> value = args.atOrUndefined(isolate, 1); | 3976 Handle<Object> value = args.atOrUndefined(isolate, 1); |
| 4044 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value)); | 3977 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value)); |
| 4045 double time_val = date->value()->Number(); | 3978 double time_val = date->value()->Number(); |
| 4046 if (!std::isnan(time_val)) { | 3979 if (!std::isnan(time_val)) { |
| 4047 int64_t const time_ms = static_cast<int64_t>(time_val); | 3980 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4048 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 3981 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
| 4049 int const days = isolate->date_cache()->DaysFromTime(local_time_ms); | 3982 int const days = isolate->date_cache()->DaysFromTime(local_time_ms); |
| 4050 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); | 3983 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); |
| 4051 int year, month, day; | 3984 int year, month, day; |
| 4052 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); | 3985 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); |
| 4053 time_val = MakeDate(MakeDay(year, month, value->Number()), time_within_day); | 3986 time_val = MakeDate(MakeDay(year, month, value->Number()), time_within_day); |
| 4054 } | 3987 } |
| 4055 return SetLocalDateValue(date, time_val); | 3988 return SetLocalDateValue(date, time_val); |
| 4056 } | 3989 } |
| 4057 | 3990 |
| 4058 | |
| 4059 // ES6 section 20.3.4.21 Date.prototype.setFullYear (year, month, date) | 3991 // ES6 section 20.3.4.21 Date.prototype.setFullYear (year, month, date) |
| 4060 BUILTIN(DatePrototypeSetFullYear) { | 3992 BUILTIN(DatePrototypeSetFullYear) { |
| 4061 HandleScope scope(isolate); | 3993 HandleScope scope(isolate); |
| 4062 CHECK_RECEIVER(JSDate, date, "Date.prototype.setFullYear"); | 3994 CHECK_RECEIVER(JSDate, date, "Date.prototype.setFullYear"); |
| 4063 int const argc = args.length() - 1; | 3995 int const argc = args.length() - 1; |
| 4064 Handle<Object> year = args.atOrUndefined(isolate, 1); | 3996 Handle<Object> year = args.atOrUndefined(isolate, 1); |
| 4065 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year, Object::ToNumber(year)); | 3997 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year, Object::ToNumber(year)); |
| 4066 double y = year->Number(), m = 0.0, dt = 1.0; | 3998 double y = year->Number(), m = 0.0, dt = 1.0; |
| 4067 int time_within_day = 0; | 3999 int time_within_day = 0; |
| 4068 if (!std::isnan(date->value()->Number())) { | 4000 if (!std::isnan(date->value()->Number())) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4082 if (argc >= 3) { | 4014 if (argc >= 3) { |
| 4083 Handle<Object> date = args.at<Object>(3); | 4015 Handle<Object> date = args.at<Object>(3); |
| 4084 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 4016 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
| 4085 dt = date->Number(); | 4017 dt = date->Number(); |
| 4086 } | 4018 } |
| 4087 } | 4019 } |
| 4088 double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); | 4020 double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); |
| 4089 return SetLocalDateValue(date, time_val); | 4021 return SetLocalDateValue(date, time_val); |
| 4090 } | 4022 } |
| 4091 | 4023 |
| 4092 | |
| 4093 // ES6 section 20.3.4.22 Date.prototype.setHours(hour, min, sec, ms) | 4024 // ES6 section 20.3.4.22 Date.prototype.setHours(hour, min, sec, ms) |
| 4094 BUILTIN(DatePrototypeSetHours) { | 4025 BUILTIN(DatePrototypeSetHours) { |
| 4095 HandleScope scope(isolate); | 4026 HandleScope scope(isolate); |
| 4096 CHECK_RECEIVER(JSDate, date, "Date.prototype.setHours"); | 4027 CHECK_RECEIVER(JSDate, date, "Date.prototype.setHours"); |
| 4097 int const argc = args.length() - 1; | 4028 int const argc = args.length() - 1; |
| 4098 Handle<Object> hour = args.atOrUndefined(isolate, 1); | 4029 Handle<Object> hour = args.atOrUndefined(isolate, 1); |
| 4099 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); | 4030 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); |
| 4100 double h = hour->Number(); | 4031 double h = hour->Number(); |
| 4101 double time_val = date->value()->Number(); | 4032 double time_val = date->value()->Number(); |
| 4102 if (!std::isnan(time_val)) { | 4033 if (!std::isnan(time_val)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4120 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4051 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4121 milli = ms->Number(); | 4052 milli = ms->Number(); |
| 4122 } | 4053 } |
| 4123 } | 4054 } |
| 4124 } | 4055 } |
| 4125 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 4056 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
| 4126 } | 4057 } |
| 4127 return SetLocalDateValue(date, time_val); | 4058 return SetLocalDateValue(date, time_val); |
| 4128 } | 4059 } |
| 4129 | 4060 |
| 4130 | |
| 4131 // ES6 section 20.3.4.23 Date.prototype.setMilliseconds(ms) | 4061 // ES6 section 20.3.4.23 Date.prototype.setMilliseconds(ms) |
| 4132 BUILTIN(DatePrototypeSetMilliseconds) { | 4062 BUILTIN(DatePrototypeSetMilliseconds) { |
| 4133 HandleScope scope(isolate); | 4063 HandleScope scope(isolate); |
| 4134 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMilliseconds"); | 4064 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMilliseconds"); |
| 4135 Handle<Object> ms = args.atOrUndefined(isolate, 1); | 4065 Handle<Object> ms = args.atOrUndefined(isolate, 1); |
| 4136 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4066 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4137 double time_val = date->value()->Number(); | 4067 double time_val = date->value()->Number(); |
| 4138 if (!std::isnan(time_val)) { | 4068 if (!std::isnan(time_val)) { |
| 4139 int64_t const time_ms = static_cast<int64_t>(time_val); | 4069 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4140 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 4070 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
| 4141 int day = isolate->date_cache()->DaysFromTime(local_time_ms); | 4071 int day = isolate->date_cache()->DaysFromTime(local_time_ms); |
| 4142 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); | 4072 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); |
| 4143 int h = time_within_day / (60 * 60 * 1000); | 4073 int h = time_within_day / (60 * 60 * 1000); |
| 4144 int m = (time_within_day / (60 * 1000)) % 60; | 4074 int m = (time_within_day / (60 * 1000)) % 60; |
| 4145 int s = (time_within_day / 1000) % 60; | 4075 int s = (time_within_day / 1000) % 60; |
| 4146 time_val = MakeDate(day, MakeTime(h, m, s, ms->Number())); | 4076 time_val = MakeDate(day, MakeTime(h, m, s, ms->Number())); |
| 4147 } | 4077 } |
| 4148 return SetLocalDateValue(date, time_val); | 4078 return SetLocalDateValue(date, time_val); |
| 4149 } | 4079 } |
| 4150 | 4080 |
| 4151 | |
| 4152 // ES6 section 20.3.4.24 Date.prototype.setMinutes ( min, sec, ms ) | 4081 // ES6 section 20.3.4.24 Date.prototype.setMinutes ( min, sec, ms ) |
| 4153 BUILTIN(DatePrototypeSetMinutes) { | 4082 BUILTIN(DatePrototypeSetMinutes) { |
| 4154 HandleScope scope(isolate); | 4083 HandleScope scope(isolate); |
| 4155 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMinutes"); | 4084 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMinutes"); |
| 4156 int const argc = args.length() - 1; | 4085 int const argc = args.length() - 1; |
| 4157 Handle<Object> min = args.atOrUndefined(isolate, 1); | 4086 Handle<Object> min = args.atOrUndefined(isolate, 1); |
| 4158 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); | 4087 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); |
| 4159 double time_val = date->value()->Number(); | 4088 double time_val = date->value()->Number(); |
| 4160 if (!std::isnan(time_val)) { | 4089 if (!std::isnan(time_val)) { |
| 4161 int64_t const time_ms = static_cast<int64_t>(time_val); | 4090 int64_t const time_ms = static_cast<int64_t>(time_val); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4174 Handle<Object> ms = args.at<Object>(3); | 4103 Handle<Object> ms = args.at<Object>(3); |
| 4175 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4104 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4176 milli = ms->Number(); | 4105 milli = ms->Number(); |
| 4177 } | 4106 } |
| 4178 } | 4107 } |
| 4179 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 4108 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
| 4180 } | 4109 } |
| 4181 return SetLocalDateValue(date, time_val); | 4110 return SetLocalDateValue(date, time_val); |
| 4182 } | 4111 } |
| 4183 | 4112 |
| 4184 | |
| 4185 // ES6 section 20.3.4.25 Date.prototype.setMonth ( month, date ) | 4113 // ES6 section 20.3.4.25 Date.prototype.setMonth ( month, date ) |
| 4186 BUILTIN(DatePrototypeSetMonth) { | 4114 BUILTIN(DatePrototypeSetMonth) { |
| 4187 HandleScope scope(isolate); | 4115 HandleScope scope(isolate); |
| 4188 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMonth"); | 4116 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMonth"); |
| 4189 int const argc = args.length() - 1; | 4117 int const argc = args.length() - 1; |
| 4190 Handle<Object> month = args.atOrUndefined(isolate, 1); | 4118 Handle<Object> month = args.atOrUndefined(isolate, 1); |
| 4191 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); | 4119 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); |
| 4192 double time_val = date->value()->Number(); | 4120 double time_val = date->value()->Number(); |
| 4193 if (!std::isnan(time_val)) { | 4121 if (!std::isnan(time_val)) { |
| 4194 int64_t const time_ms = static_cast<int64_t>(time_val); | 4122 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4195 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 4123 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
| 4196 int days = isolate->date_cache()->DaysFromTime(local_time_ms); | 4124 int days = isolate->date_cache()->DaysFromTime(local_time_ms); |
| 4197 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); | 4125 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); |
| 4198 int year, unused, day; | 4126 int year, unused, day; |
| 4199 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); | 4127 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); |
| 4200 double m = month->Number(); | 4128 double m = month->Number(); |
| 4201 double dt = day; | 4129 double dt = day; |
| 4202 if (argc >= 2) { | 4130 if (argc >= 2) { |
| 4203 Handle<Object> date = args.at<Object>(2); | 4131 Handle<Object> date = args.at<Object>(2); |
| 4204 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 4132 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
| 4205 dt = date->Number(); | 4133 dt = date->Number(); |
| 4206 } | 4134 } |
| 4207 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); | 4135 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); |
| 4208 } | 4136 } |
| 4209 return SetLocalDateValue(date, time_val); | 4137 return SetLocalDateValue(date, time_val); |
| 4210 } | 4138 } |
| 4211 | 4139 |
| 4212 | |
| 4213 // ES6 section 20.3.4.26 Date.prototype.setSeconds ( sec, ms ) | 4140 // ES6 section 20.3.4.26 Date.prototype.setSeconds ( sec, ms ) |
| 4214 BUILTIN(DatePrototypeSetSeconds) { | 4141 BUILTIN(DatePrototypeSetSeconds) { |
| 4215 HandleScope scope(isolate); | 4142 HandleScope scope(isolate); |
| 4216 CHECK_RECEIVER(JSDate, date, "Date.prototype.setSeconds"); | 4143 CHECK_RECEIVER(JSDate, date, "Date.prototype.setSeconds"); |
| 4217 int const argc = args.length() - 1; | 4144 int const argc = args.length() - 1; |
| 4218 Handle<Object> sec = args.atOrUndefined(isolate, 1); | 4145 Handle<Object> sec = args.atOrUndefined(isolate, 1); |
| 4219 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 4146 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
| 4220 double time_val = date->value()->Number(); | 4147 double time_val = date->value()->Number(); |
| 4221 if (!std::isnan(time_val)) { | 4148 if (!std::isnan(time_val)) { |
| 4222 int64_t const time_ms = static_cast<int64_t>(time_val); | 4149 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4223 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 4150 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
| 4224 int day = isolate->date_cache()->DaysFromTime(local_time_ms); | 4151 int day = isolate->date_cache()->DaysFromTime(local_time_ms); |
| 4225 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); | 4152 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); |
| 4226 int h = time_within_day / (60 * 60 * 1000); | 4153 int h = time_within_day / (60 * 60 * 1000); |
| 4227 double m = (time_within_day / (60 * 1000)) % 60; | 4154 double m = (time_within_day / (60 * 1000)) % 60; |
| 4228 double s = sec->Number(); | 4155 double s = sec->Number(); |
| 4229 double milli = time_within_day % 1000; | 4156 double milli = time_within_day % 1000; |
| 4230 if (argc >= 2) { | 4157 if (argc >= 2) { |
| 4231 Handle<Object> ms = args.at<Object>(2); | 4158 Handle<Object> ms = args.at<Object>(2); |
| 4232 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4159 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4233 milli = ms->Number(); | 4160 milli = ms->Number(); |
| 4234 } | 4161 } |
| 4235 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 4162 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
| 4236 } | 4163 } |
| 4237 return SetLocalDateValue(date, time_val); | 4164 return SetLocalDateValue(date, time_val); |
| 4238 } | 4165 } |
| 4239 | 4166 |
| 4240 | |
| 4241 // ES6 section 20.3.4.27 Date.prototype.setTime ( time ) | 4167 // ES6 section 20.3.4.27 Date.prototype.setTime ( time ) |
| 4242 BUILTIN(DatePrototypeSetTime) { | 4168 BUILTIN(DatePrototypeSetTime) { |
| 4243 HandleScope scope(isolate); | 4169 HandleScope scope(isolate); |
| 4244 CHECK_RECEIVER(JSDate, date, "Date.prototype.setTime"); | 4170 CHECK_RECEIVER(JSDate, date, "Date.prototype.setTime"); |
| 4245 Handle<Object> value = args.atOrUndefined(isolate, 1); | 4171 Handle<Object> value = args.atOrUndefined(isolate, 1); |
| 4246 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value)); | 4172 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value)); |
| 4247 return *JSDate::SetValue(date, TimeClip(value->Number())); | 4173 return *JSDate::SetValue(date, TimeClip(value->Number())); |
| 4248 } | 4174 } |
| 4249 | 4175 |
| 4250 | |
| 4251 // ES6 section 20.3.4.28 Date.prototype.setUTCDate ( date ) | 4176 // ES6 section 20.3.4.28 Date.prototype.setUTCDate ( date ) |
| 4252 BUILTIN(DatePrototypeSetUTCDate) { | 4177 BUILTIN(DatePrototypeSetUTCDate) { |
| 4253 HandleScope scope(isolate); | 4178 HandleScope scope(isolate); |
| 4254 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCDate"); | 4179 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCDate"); |
| 4255 Handle<Object> value = args.atOrUndefined(isolate, 1); | 4180 Handle<Object> value = args.atOrUndefined(isolate, 1); |
| 4256 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value)); | 4181 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value)); |
| 4257 if (std::isnan(date->value()->Number())) return date->value(); | 4182 if (std::isnan(date->value()->Number())) return date->value(); |
| 4258 int64_t const time_ms = static_cast<int64_t>(date->value()->Number()); | 4183 int64_t const time_ms = static_cast<int64_t>(date->value()->Number()); |
| 4259 int const days = isolate->date_cache()->DaysFromTime(time_ms); | 4184 int const days = isolate->date_cache()->DaysFromTime(time_ms); |
| 4260 int const time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); | 4185 int const time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); |
| 4261 int year, month, day; | 4186 int year, month, day; |
| 4262 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); | 4187 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); |
| 4263 double const time_val = | 4188 double const time_val = |
| 4264 MakeDate(MakeDay(year, month, value->Number()), time_within_day); | 4189 MakeDate(MakeDay(year, month, value->Number()), time_within_day); |
| 4265 return *JSDate::SetValue(date, TimeClip(time_val)); | 4190 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4266 } | 4191 } |
| 4267 | 4192 |
| 4268 | |
| 4269 // ES6 section 20.3.4.29 Date.prototype.setUTCFullYear (year, month, date) | 4193 // ES6 section 20.3.4.29 Date.prototype.setUTCFullYear (year, month, date) |
| 4270 BUILTIN(DatePrototypeSetUTCFullYear) { | 4194 BUILTIN(DatePrototypeSetUTCFullYear) { |
| 4271 HandleScope scope(isolate); | 4195 HandleScope scope(isolate); |
| 4272 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCFullYear"); | 4196 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCFullYear"); |
| 4273 int const argc = args.length() - 1; | 4197 int const argc = args.length() - 1; |
| 4274 Handle<Object> year = args.atOrUndefined(isolate, 1); | 4198 Handle<Object> year = args.atOrUndefined(isolate, 1); |
| 4275 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year, Object::ToNumber(year)); | 4199 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year, Object::ToNumber(year)); |
| 4276 double y = year->Number(), m = 0.0, dt = 1.0; | 4200 double y = year->Number(), m = 0.0, dt = 1.0; |
| 4277 int time_within_day = 0; | 4201 int time_within_day = 0; |
| 4278 if (!std::isnan(date->value()->Number())) { | 4202 if (!std::isnan(date->value()->Number())) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4291 if (argc >= 3) { | 4215 if (argc >= 3) { |
| 4292 Handle<Object> date = args.at<Object>(3); | 4216 Handle<Object> date = args.at<Object>(3); |
| 4293 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 4217 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
| 4294 dt = date->Number(); | 4218 dt = date->Number(); |
| 4295 } | 4219 } |
| 4296 } | 4220 } |
| 4297 double const time_val = MakeDate(MakeDay(y, m, dt), time_within_day); | 4221 double const time_val = MakeDate(MakeDay(y, m, dt), time_within_day); |
| 4298 return *JSDate::SetValue(date, TimeClip(time_val)); | 4222 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4299 } | 4223 } |
| 4300 | 4224 |
| 4301 | |
| 4302 // ES6 section 20.3.4.30 Date.prototype.setUTCHours(hour, min, sec, ms) | 4225 // ES6 section 20.3.4.30 Date.prototype.setUTCHours(hour, min, sec, ms) |
| 4303 BUILTIN(DatePrototypeSetUTCHours) { | 4226 BUILTIN(DatePrototypeSetUTCHours) { |
| 4304 HandleScope scope(isolate); | 4227 HandleScope scope(isolate); |
| 4305 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCHours"); | 4228 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCHours"); |
| 4306 int const argc = args.length() - 1; | 4229 int const argc = args.length() - 1; |
| 4307 Handle<Object> hour = args.atOrUndefined(isolate, 1); | 4230 Handle<Object> hour = args.atOrUndefined(isolate, 1); |
| 4308 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); | 4231 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); |
| 4309 double h = hour->Number(); | 4232 double h = hour->Number(); |
| 4310 double time_val = date->value()->Number(); | 4233 double time_val = date->value()->Number(); |
| 4311 if (!std::isnan(time_val)) { | 4234 if (!std::isnan(time_val)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4328 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4251 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4329 milli = ms->Number(); | 4252 milli = ms->Number(); |
| 4330 } | 4253 } |
| 4331 } | 4254 } |
| 4332 } | 4255 } |
| 4333 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 4256 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
| 4334 } | 4257 } |
| 4335 return *JSDate::SetValue(date, TimeClip(time_val)); | 4258 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4336 } | 4259 } |
| 4337 | 4260 |
| 4338 | |
| 4339 // ES6 section 20.3.4.31 Date.prototype.setUTCMilliseconds(ms) | 4261 // ES6 section 20.3.4.31 Date.prototype.setUTCMilliseconds(ms) |
| 4340 BUILTIN(DatePrototypeSetUTCMilliseconds) { | 4262 BUILTIN(DatePrototypeSetUTCMilliseconds) { |
| 4341 HandleScope scope(isolate); | 4263 HandleScope scope(isolate); |
| 4342 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMilliseconds"); | 4264 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMilliseconds"); |
| 4343 Handle<Object> ms = args.atOrUndefined(isolate, 1); | 4265 Handle<Object> ms = args.atOrUndefined(isolate, 1); |
| 4344 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4266 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4345 double time_val = date->value()->Number(); | 4267 double time_val = date->value()->Number(); |
| 4346 if (!std::isnan(time_val)) { | 4268 if (!std::isnan(time_val)) { |
| 4347 int64_t const time_ms = static_cast<int64_t>(time_val); | 4269 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4348 int day = isolate->date_cache()->DaysFromTime(time_ms); | 4270 int day = isolate->date_cache()->DaysFromTime(time_ms); |
| 4349 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); | 4271 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); |
| 4350 int h = time_within_day / (60 * 60 * 1000); | 4272 int h = time_within_day / (60 * 60 * 1000); |
| 4351 int m = (time_within_day / (60 * 1000)) % 60; | 4273 int m = (time_within_day / (60 * 1000)) % 60; |
| 4352 int s = (time_within_day / 1000) % 60; | 4274 int s = (time_within_day / 1000) % 60; |
| 4353 time_val = MakeDate(day, MakeTime(h, m, s, ms->Number())); | 4275 time_val = MakeDate(day, MakeTime(h, m, s, ms->Number())); |
| 4354 } | 4276 } |
| 4355 return *JSDate::SetValue(date, TimeClip(time_val)); | 4277 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4356 } | 4278 } |
| 4357 | 4279 |
| 4358 | |
| 4359 // ES6 section 20.3.4.32 Date.prototype.setUTCMinutes ( min, sec, ms ) | 4280 // ES6 section 20.3.4.32 Date.prototype.setUTCMinutes ( min, sec, ms ) |
| 4360 BUILTIN(DatePrototypeSetUTCMinutes) { | 4281 BUILTIN(DatePrototypeSetUTCMinutes) { |
| 4361 HandleScope scope(isolate); | 4282 HandleScope scope(isolate); |
| 4362 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMinutes"); | 4283 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMinutes"); |
| 4363 int const argc = args.length() - 1; | 4284 int const argc = args.length() - 1; |
| 4364 Handle<Object> min = args.atOrUndefined(isolate, 1); | 4285 Handle<Object> min = args.atOrUndefined(isolate, 1); |
| 4365 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); | 4286 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); |
| 4366 double time_val = date->value()->Number(); | 4287 double time_val = date->value()->Number(); |
| 4367 if (!std::isnan(time_val)) { | 4288 if (!std::isnan(time_val)) { |
| 4368 int64_t const time_ms = static_cast<int64_t>(time_val); | 4289 int64_t const time_ms = static_cast<int64_t>(time_val); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4380 Handle<Object> ms = args.at<Object>(3); | 4301 Handle<Object> ms = args.at<Object>(3); |
| 4381 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4302 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4382 milli = ms->Number(); | 4303 milli = ms->Number(); |
| 4383 } | 4304 } |
| 4384 } | 4305 } |
| 4385 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 4306 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
| 4386 } | 4307 } |
| 4387 return *JSDate::SetValue(date, TimeClip(time_val)); | 4308 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4388 } | 4309 } |
| 4389 | 4310 |
| 4390 | |
| 4391 // ES6 section 20.3.4.31 Date.prototype.setUTCMonth ( month, date ) | 4311 // ES6 section 20.3.4.31 Date.prototype.setUTCMonth ( month, date ) |
| 4392 BUILTIN(DatePrototypeSetUTCMonth) { | 4312 BUILTIN(DatePrototypeSetUTCMonth) { |
| 4393 HandleScope scope(isolate); | 4313 HandleScope scope(isolate); |
| 4394 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMonth"); | 4314 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMonth"); |
| 4395 int const argc = args.length() - 1; | 4315 int const argc = args.length() - 1; |
| 4396 Handle<Object> month = args.atOrUndefined(isolate, 1); | 4316 Handle<Object> month = args.atOrUndefined(isolate, 1); |
| 4397 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); | 4317 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); |
| 4398 double time_val = date->value()->Number(); | 4318 double time_val = date->value()->Number(); |
| 4399 if (!std::isnan(time_val)) { | 4319 if (!std::isnan(time_val)) { |
| 4400 int64_t const time_ms = static_cast<int64_t>(time_val); | 4320 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4401 int days = isolate->date_cache()->DaysFromTime(time_ms); | 4321 int days = isolate->date_cache()->DaysFromTime(time_ms); |
| 4402 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); | 4322 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); |
| 4403 int year, unused, day; | 4323 int year, unused, day; |
| 4404 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); | 4324 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); |
| 4405 double m = month->Number(); | 4325 double m = month->Number(); |
| 4406 double dt = day; | 4326 double dt = day; |
| 4407 if (argc >= 2) { | 4327 if (argc >= 2) { |
| 4408 Handle<Object> date = args.at<Object>(2); | 4328 Handle<Object> date = args.at<Object>(2); |
| 4409 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 4329 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
| 4410 dt = date->Number(); | 4330 dt = date->Number(); |
| 4411 } | 4331 } |
| 4412 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); | 4332 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); |
| 4413 } | 4333 } |
| 4414 return *JSDate::SetValue(date, TimeClip(time_val)); | 4334 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4415 } | 4335 } |
| 4416 | 4336 |
| 4417 | |
| 4418 // ES6 section 20.3.4.34 Date.prototype.setUTCSeconds ( sec, ms ) | 4337 // ES6 section 20.3.4.34 Date.prototype.setUTCSeconds ( sec, ms ) |
| 4419 BUILTIN(DatePrototypeSetUTCSeconds) { | 4338 BUILTIN(DatePrototypeSetUTCSeconds) { |
| 4420 HandleScope scope(isolate); | 4339 HandleScope scope(isolate); |
| 4421 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCSeconds"); | 4340 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCSeconds"); |
| 4422 int const argc = args.length() - 1; | 4341 int const argc = args.length() - 1; |
| 4423 Handle<Object> sec = args.atOrUndefined(isolate, 1); | 4342 Handle<Object> sec = args.atOrUndefined(isolate, 1); |
| 4424 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 4343 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
| 4425 double time_val = date->value()->Number(); | 4344 double time_val = date->value()->Number(); |
| 4426 if (!std::isnan(time_val)) { | 4345 if (!std::isnan(time_val)) { |
| 4427 int64_t const time_ms = static_cast<int64_t>(time_val); | 4346 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4428 int day = isolate->date_cache()->DaysFromTime(time_ms); | 4347 int day = isolate->date_cache()->DaysFromTime(time_ms); |
| 4429 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); | 4348 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); |
| 4430 int h = time_within_day / (60 * 60 * 1000); | 4349 int h = time_within_day / (60 * 60 * 1000); |
| 4431 double m = (time_within_day / (60 * 1000)) % 60; | 4350 double m = (time_within_day / (60 * 1000)) % 60; |
| 4432 double s = sec->Number(); | 4351 double s = sec->Number(); |
| 4433 double milli = time_within_day % 1000; | 4352 double milli = time_within_day % 1000; |
| 4434 if (argc >= 2) { | 4353 if (argc >= 2) { |
| 4435 Handle<Object> ms = args.at<Object>(2); | 4354 Handle<Object> ms = args.at<Object>(2); |
| 4436 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 4355 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
| 4437 milli = ms->Number(); | 4356 milli = ms->Number(); |
| 4438 } | 4357 } |
| 4439 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 4358 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
| 4440 } | 4359 } |
| 4441 return *JSDate::SetValue(date, TimeClip(time_val)); | 4360 return *JSDate::SetValue(date, TimeClip(time_val)); |
| 4442 } | 4361 } |
| 4443 | 4362 |
| 4444 | |
| 4445 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) | 4363 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) |
| 4446 BUILTIN(DatePrototypeToDateString) { | 4364 BUILTIN(DatePrototypeToDateString) { |
| 4447 HandleScope scope(isolate); | 4365 HandleScope scope(isolate); |
| 4448 CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString"); | 4366 CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString"); |
| 4449 char buffer[128]; | 4367 char buffer[128]; |
| 4450 ToDateString(date->value()->Number(), ArrayVector(buffer), | 4368 ToDateString(date->value()->Number(), ArrayVector(buffer), |
| 4451 isolate->date_cache(), kDateOnly); | 4369 isolate->date_cache(), kDateOnly); |
| 4452 RETURN_RESULT_OR_FAILURE( | 4370 RETURN_RESULT_OR_FAILURE( |
| 4453 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 4371 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
| 4454 } | 4372 } |
| 4455 | 4373 |
| 4456 | |
| 4457 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) | 4374 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) |
| 4458 BUILTIN(DatePrototypeToISOString) { | 4375 BUILTIN(DatePrototypeToISOString) { |
| 4459 HandleScope scope(isolate); | 4376 HandleScope scope(isolate); |
| 4460 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); | 4377 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); |
| 4461 double const time_val = date->value()->Number(); | 4378 double const time_val = date->value()->Number(); |
| 4462 if (std::isnan(time_val)) { | 4379 if (std::isnan(time_val)) { |
| 4463 THROW_NEW_ERROR_RETURN_FAILURE( | 4380 THROW_NEW_ERROR_RETURN_FAILURE( |
| 4464 isolate, NewRangeError(MessageTemplate::kInvalidTimeValue)); | 4381 isolate, NewRangeError(MessageTemplate::kInvalidTimeValue)); |
| 4465 } | 4382 } |
| 4466 int64_t const time_ms = static_cast<int64_t>(time_val); | 4383 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 4467 int year, month, day, weekday, hour, min, sec, ms; | 4384 int year, month, day, weekday, hour, min, sec, ms; |
| 4468 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, | 4385 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, |
| 4469 &hour, &min, &sec, &ms); | 4386 &hour, &min, &sec, &ms); |
| 4470 char buffer[128]; | 4387 char buffer[128]; |
| 4471 if (year >= 0 && year <= 9999) { | 4388 if (year >= 0 && year <= 9999) { |
| 4472 SNPrintF(ArrayVector(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, | 4389 SNPrintF(ArrayVector(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, |
| 4473 month + 1, day, hour, min, sec, ms); | 4390 month + 1, day, hour, min, sec, ms); |
| 4474 } else if (year < 0) { | 4391 } else if (year < 0) { |
| 4475 SNPrintF(ArrayVector(buffer), "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year, | 4392 SNPrintF(ArrayVector(buffer), "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year, |
| 4476 month + 1, day, hour, min, sec, ms); | 4393 month + 1, day, hour, min, sec, ms); |
| 4477 } else { | 4394 } else { |
| 4478 SNPrintF(ArrayVector(buffer), "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, | 4395 SNPrintF(ArrayVector(buffer), "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, |
| 4479 month + 1, day, hour, min, sec, ms); | 4396 month + 1, day, hour, min, sec, ms); |
| 4480 } | 4397 } |
| 4481 return *isolate->factory()->NewStringFromAsciiChecked(buffer); | 4398 return *isolate->factory()->NewStringFromAsciiChecked(buffer); |
| 4482 } | 4399 } |
| 4483 | 4400 |
| 4484 | |
| 4485 // ES6 section 20.3.4.41 Date.prototype.toString ( ) | 4401 // ES6 section 20.3.4.41 Date.prototype.toString ( ) |
| 4486 BUILTIN(DatePrototypeToString) { | 4402 BUILTIN(DatePrototypeToString) { |
| 4487 HandleScope scope(isolate); | 4403 HandleScope scope(isolate); |
| 4488 CHECK_RECEIVER(JSDate, date, "Date.prototype.toString"); | 4404 CHECK_RECEIVER(JSDate, date, "Date.prototype.toString"); |
| 4489 char buffer[128]; | 4405 char buffer[128]; |
| 4490 ToDateString(date->value()->Number(), ArrayVector(buffer), | 4406 ToDateString(date->value()->Number(), ArrayVector(buffer), |
| 4491 isolate->date_cache()); | 4407 isolate->date_cache()); |
| 4492 RETURN_RESULT_OR_FAILURE( | 4408 RETURN_RESULT_OR_FAILURE( |
| 4493 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 4409 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
| 4494 } | 4410 } |
| 4495 | 4411 |
| 4496 | |
| 4497 // ES6 section 20.3.4.42 Date.prototype.toTimeString ( ) | 4412 // ES6 section 20.3.4.42 Date.prototype.toTimeString ( ) |
| 4498 BUILTIN(DatePrototypeToTimeString) { | 4413 BUILTIN(DatePrototypeToTimeString) { |
| 4499 HandleScope scope(isolate); | 4414 HandleScope scope(isolate); |
| 4500 CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString"); | 4415 CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString"); |
| 4501 char buffer[128]; | 4416 char buffer[128]; |
| 4502 ToDateString(date->value()->Number(), ArrayVector(buffer), | 4417 ToDateString(date->value()->Number(), ArrayVector(buffer), |
| 4503 isolate->date_cache(), kTimeOnly); | 4418 isolate->date_cache(), kTimeOnly); |
| 4504 RETURN_RESULT_OR_FAILURE( | 4419 RETURN_RESULT_OR_FAILURE( |
| 4505 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 4420 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
| 4506 } | 4421 } |
| 4507 | 4422 |
| 4508 | |
| 4509 // ES6 section 20.3.4.43 Date.prototype.toUTCString ( ) | 4423 // ES6 section 20.3.4.43 Date.prototype.toUTCString ( ) |
| 4510 BUILTIN(DatePrototypeToUTCString) { | 4424 BUILTIN(DatePrototypeToUTCString) { |
| 4511 HandleScope scope(isolate); | 4425 HandleScope scope(isolate); |
| 4512 CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString"); | 4426 CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString"); |
| 4513 double const time_val = date->value()->Number(); | 4427 double const time_val = date->value()->Number(); |
| 4514 if (std::isnan(time_val)) { | 4428 if (std::isnan(time_val)) { |
| 4515 return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date"); | 4429 return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date"); |
| 4516 } | 4430 } |
| 4517 char buffer[128]; | 4431 char buffer[128]; |
| 4518 int64_t time_ms = static_cast<int64_t>(time_val); | 4432 int64_t time_ms = static_cast<int64_t>(time_val); |
| 4519 int year, month, day, weekday, hour, min, sec, ms; | 4433 int year, month, day, weekday, hour, min, sec, ms; |
| 4520 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, | 4434 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, |
| 4521 &hour, &min, &sec, &ms); | 4435 &hour, &min, &sec, &ms); |
| 4522 SNPrintF(ArrayVector(buffer), "%s, %02d %s %4d %02d:%02d:%02d GMT", | 4436 SNPrintF(ArrayVector(buffer), "%s, %02d %s %4d %02d:%02d:%02d GMT", |
| 4523 kShortWeekDays[weekday], day, kShortMonths[month], year, hour, min, | 4437 kShortWeekDays[weekday], day, kShortMonths[month], year, hour, min, |
| 4524 sec); | 4438 sec); |
| 4525 return *isolate->factory()->NewStringFromAsciiChecked(buffer); | 4439 return *isolate->factory()->NewStringFromAsciiChecked(buffer); |
| 4526 } | 4440 } |
| 4527 | 4441 |
| 4528 | |
| 4529 // ES6 section 20.3.4.44 Date.prototype.valueOf ( ) | 4442 // ES6 section 20.3.4.44 Date.prototype.valueOf ( ) |
| 4530 BUILTIN(DatePrototypeValueOf) { | 4443 BUILTIN(DatePrototypeValueOf) { |
| 4531 HandleScope scope(isolate); | 4444 HandleScope scope(isolate); |
| 4532 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); | 4445 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); |
| 4533 return date->value(); | 4446 return date->value(); |
| 4534 } | 4447 } |
| 4535 | 4448 |
| 4536 | |
| 4537 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) | 4449 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) |
| 4538 BUILTIN(DatePrototypeToPrimitive) { | 4450 BUILTIN(DatePrototypeToPrimitive) { |
| 4539 HandleScope scope(isolate); | 4451 HandleScope scope(isolate); |
| 4540 DCHECK_EQ(2, args.length()); | 4452 DCHECK_EQ(2, args.length()); |
| 4541 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); | 4453 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); |
| 4542 Handle<Object> hint = args.at<Object>(1); | 4454 Handle<Object> hint = args.at<Object>(1); |
| 4543 RETURN_RESULT_OR_FAILURE(isolate, JSDate::ToPrimitive(receiver, hint)); | 4455 RETURN_RESULT_OR_FAILURE(isolate, JSDate::ToPrimitive(receiver, hint)); |
| 4544 } | 4456 } |
| 4545 | 4457 |
| 4546 | |
| 4547 // ES6 section B.2.4.1 Date.prototype.getYear ( ) | 4458 // ES6 section B.2.4.1 Date.prototype.getYear ( ) |
| 4548 BUILTIN(DatePrototypeGetYear) { | 4459 BUILTIN(DatePrototypeGetYear) { |
| 4549 HandleScope scope(isolate); | 4460 HandleScope scope(isolate); |
| 4550 CHECK_RECEIVER(JSDate, date, "Date.prototype.getYear"); | 4461 CHECK_RECEIVER(JSDate, date, "Date.prototype.getYear"); |
| 4551 double time_val = date->value()->Number(); | 4462 double time_val = date->value()->Number(); |
| 4552 if (std::isnan(time_val)) return date->value(); | 4463 if (std::isnan(time_val)) return date->value(); |
| 4553 int64_t time_ms = static_cast<int64_t>(time_val); | 4464 int64_t time_ms = static_cast<int64_t>(time_val); |
| 4554 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 4465 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
| 4555 int days = isolate->date_cache()->DaysFromTime(local_time_ms); | 4466 int days = isolate->date_cache()->DaysFromTime(local_time_ms); |
| 4556 int year, month, day; | 4467 int year, month, day; |
| 4557 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); | 4468 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); |
| 4558 return Smi::FromInt(year - 1900); | 4469 return Smi::FromInt(year - 1900); |
| 4559 } | 4470 } |
| 4560 | 4471 |
| 4561 | |
| 4562 // ES6 section B.2.4.2 Date.prototype.setYear ( year ) | 4472 // ES6 section B.2.4.2 Date.prototype.setYear ( year ) |
| 4563 BUILTIN(DatePrototypeSetYear) { | 4473 BUILTIN(DatePrototypeSetYear) { |
| 4564 HandleScope scope(isolate); | 4474 HandleScope scope(isolate); |
| 4565 CHECK_RECEIVER(JSDate, date, "Date.prototype.setYear"); | 4475 CHECK_RECEIVER(JSDate, date, "Date.prototype.setYear"); |
| 4566 Handle<Object> year = args.atOrUndefined(isolate, 1); | 4476 Handle<Object> year = args.atOrUndefined(isolate, 1); |
| 4567 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year, Object::ToNumber(year)); | 4477 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year, Object::ToNumber(year)); |
| 4568 double m = 0.0, dt = 1.0, y = year->Number(); | 4478 double m = 0.0, dt = 1.0, y = year->Number(); |
| 4569 if (0.0 <= y && y <= 99.0) { | 4479 if (0.0 <= y && y <= 99.0) { |
| 4570 y = 1900.0 + DoubleToInteger(y); | 4480 y = 1900.0 + DoubleToInteger(y); |
| 4571 } | 4481 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4610 RETURN_RESULT_OR_FAILURE( | 4520 RETURN_RESULT_OR_FAILURE( |
| 4611 isolate, Execution::Call(isolate, function, receiver_obj, 0, NULL)); | 4521 isolate, Execution::Call(isolate, function, receiver_obj, 0, NULL)); |
| 4612 } | 4522 } |
| 4613 } | 4523 } |
| 4614 | 4524 |
| 4615 // static | 4525 // static |
| 4616 void Builtins::Generate_DatePrototypeGetDate(MacroAssembler* masm) { | 4526 void Builtins::Generate_DatePrototypeGetDate(MacroAssembler* masm) { |
| 4617 Generate_DatePrototype_GetField(masm, JSDate::kDay); | 4527 Generate_DatePrototype_GetField(masm, JSDate::kDay); |
| 4618 } | 4528 } |
| 4619 | 4529 |
| 4620 | |
| 4621 // static | 4530 // static |
| 4622 void Builtins::Generate_DatePrototypeGetDay(MacroAssembler* masm) { | 4531 void Builtins::Generate_DatePrototypeGetDay(MacroAssembler* masm) { |
| 4623 Generate_DatePrototype_GetField(masm, JSDate::kWeekday); | 4532 Generate_DatePrototype_GetField(masm, JSDate::kWeekday); |
| 4624 } | 4533 } |
| 4625 | 4534 |
| 4626 | |
| 4627 // static | 4535 // static |
| 4628 void Builtins::Generate_DatePrototypeGetFullYear(MacroAssembler* masm) { | 4536 void Builtins::Generate_DatePrototypeGetFullYear(MacroAssembler* masm) { |
| 4629 Generate_DatePrototype_GetField(masm, JSDate::kYear); | 4537 Generate_DatePrototype_GetField(masm, JSDate::kYear); |
| 4630 } | 4538 } |
| 4631 | 4539 |
| 4632 | |
| 4633 // static | 4540 // static |
| 4634 void Builtins::Generate_DatePrototypeGetHours(MacroAssembler* masm) { | 4541 void Builtins::Generate_DatePrototypeGetHours(MacroAssembler* masm) { |
| 4635 Generate_DatePrototype_GetField(masm, JSDate::kHour); | 4542 Generate_DatePrototype_GetField(masm, JSDate::kHour); |
| 4636 } | 4543 } |
| 4637 | 4544 |
| 4638 | |
| 4639 // static | 4545 // static |
| 4640 void Builtins::Generate_DatePrototypeGetMilliseconds(MacroAssembler* masm) { | 4546 void Builtins::Generate_DatePrototypeGetMilliseconds(MacroAssembler* masm) { |
| 4641 Generate_DatePrototype_GetField(masm, JSDate::kMillisecond); | 4547 Generate_DatePrototype_GetField(masm, JSDate::kMillisecond); |
| 4642 } | 4548 } |
| 4643 | 4549 |
| 4644 | |
| 4645 // static | 4550 // static |
| 4646 void Builtins::Generate_DatePrototypeGetMinutes(MacroAssembler* masm) { | 4551 void Builtins::Generate_DatePrototypeGetMinutes(MacroAssembler* masm) { |
| 4647 Generate_DatePrototype_GetField(masm, JSDate::kMinute); | 4552 Generate_DatePrototype_GetField(masm, JSDate::kMinute); |
| 4648 } | 4553 } |
| 4649 | 4554 |
| 4650 | |
| 4651 // static | 4555 // static |
| 4652 void Builtins::Generate_DatePrototypeGetMonth(MacroAssembler* masm) { | 4556 void Builtins::Generate_DatePrototypeGetMonth(MacroAssembler* masm) { |
| 4653 Generate_DatePrototype_GetField(masm, JSDate::kMonth); | 4557 Generate_DatePrototype_GetField(masm, JSDate::kMonth); |
| 4654 } | 4558 } |
| 4655 | 4559 |
| 4656 | |
| 4657 // static | 4560 // static |
| 4658 void Builtins::Generate_DatePrototypeGetSeconds(MacroAssembler* masm) { | 4561 void Builtins::Generate_DatePrototypeGetSeconds(MacroAssembler* masm) { |
| 4659 Generate_DatePrototype_GetField(masm, JSDate::kSecond); | 4562 Generate_DatePrototype_GetField(masm, JSDate::kSecond); |
| 4660 } | 4563 } |
| 4661 | 4564 |
| 4662 | |
| 4663 // static | 4565 // static |
| 4664 void Builtins::Generate_DatePrototypeGetTime(MacroAssembler* masm) { | 4566 void Builtins::Generate_DatePrototypeGetTime(MacroAssembler* masm) { |
| 4665 Generate_DatePrototype_GetField(masm, JSDate::kDateValue); | 4567 Generate_DatePrototype_GetField(masm, JSDate::kDateValue); |
| 4666 } | 4568 } |
| 4667 | 4569 |
| 4668 | |
| 4669 // static | 4570 // static |
| 4670 void Builtins::Generate_DatePrototypeGetTimezoneOffset(MacroAssembler* masm) { | 4571 void Builtins::Generate_DatePrototypeGetTimezoneOffset(MacroAssembler* masm) { |
| 4671 Generate_DatePrototype_GetField(masm, JSDate::kTimezoneOffset); | 4572 Generate_DatePrototype_GetField(masm, JSDate::kTimezoneOffset); |
| 4672 } | 4573 } |
| 4673 | 4574 |
| 4674 | |
| 4675 // static | 4575 // static |
| 4676 void Builtins::Generate_DatePrototypeGetUTCDate(MacroAssembler* masm) { | 4576 void Builtins::Generate_DatePrototypeGetUTCDate(MacroAssembler* masm) { |
| 4677 Generate_DatePrototype_GetField(masm, JSDate::kDayUTC); | 4577 Generate_DatePrototype_GetField(masm, JSDate::kDayUTC); |
| 4678 } | 4578 } |
| 4679 | 4579 |
| 4680 | |
| 4681 // static | 4580 // static |
| 4682 void Builtins::Generate_DatePrototypeGetUTCDay(MacroAssembler* masm) { | 4581 void Builtins::Generate_DatePrototypeGetUTCDay(MacroAssembler* masm) { |
| 4683 Generate_DatePrototype_GetField(masm, JSDate::kWeekdayUTC); | 4582 Generate_DatePrototype_GetField(masm, JSDate::kWeekdayUTC); |
| 4684 } | 4583 } |
| 4685 | 4584 |
| 4686 | |
| 4687 // static | 4585 // static |
| 4688 void Builtins::Generate_DatePrototypeGetUTCFullYear(MacroAssembler* masm) { | 4586 void Builtins::Generate_DatePrototypeGetUTCFullYear(MacroAssembler* masm) { |
| 4689 Generate_DatePrototype_GetField(masm, JSDate::kYearUTC); | 4587 Generate_DatePrototype_GetField(masm, JSDate::kYearUTC); |
| 4690 } | 4588 } |
| 4691 | 4589 |
| 4692 | |
| 4693 // static | 4590 // static |
| 4694 void Builtins::Generate_DatePrototypeGetUTCHours(MacroAssembler* masm) { | 4591 void Builtins::Generate_DatePrototypeGetUTCHours(MacroAssembler* masm) { |
| 4695 Generate_DatePrototype_GetField(masm, JSDate::kHourUTC); | 4592 Generate_DatePrototype_GetField(masm, JSDate::kHourUTC); |
| 4696 } | 4593 } |
| 4697 | 4594 |
| 4698 | |
| 4699 // static | 4595 // static |
| 4700 void Builtins::Generate_DatePrototypeGetUTCMilliseconds(MacroAssembler* masm) { | 4596 void Builtins::Generate_DatePrototypeGetUTCMilliseconds(MacroAssembler* masm) { |
| 4701 Generate_DatePrototype_GetField(masm, JSDate::kMillisecondUTC); | 4597 Generate_DatePrototype_GetField(masm, JSDate::kMillisecondUTC); |
| 4702 } | 4598 } |
| 4703 | 4599 |
| 4704 | |
| 4705 // static | 4600 // static |
| 4706 void Builtins::Generate_DatePrototypeGetUTCMinutes(MacroAssembler* masm) { | 4601 void Builtins::Generate_DatePrototypeGetUTCMinutes(MacroAssembler* masm) { |
| 4707 Generate_DatePrototype_GetField(masm, JSDate::kMinuteUTC); | 4602 Generate_DatePrototype_GetField(masm, JSDate::kMinuteUTC); |
| 4708 } | 4603 } |
| 4709 | 4604 |
| 4710 | |
| 4711 // static | 4605 // static |
| 4712 void Builtins::Generate_DatePrototypeGetUTCMonth(MacroAssembler* masm) { | 4606 void Builtins::Generate_DatePrototypeGetUTCMonth(MacroAssembler* masm) { |
| 4713 Generate_DatePrototype_GetField(masm, JSDate::kMonthUTC); | 4607 Generate_DatePrototype_GetField(masm, JSDate::kMonthUTC); |
| 4714 } | 4608 } |
| 4715 | 4609 |
| 4716 | |
| 4717 // static | 4610 // static |
| 4718 void Builtins::Generate_DatePrototypeGetUTCSeconds(MacroAssembler* masm) { | 4611 void Builtins::Generate_DatePrototypeGetUTCSeconds(MacroAssembler* masm) { |
| 4719 Generate_DatePrototype_GetField(masm, JSDate::kSecondUTC); | 4612 Generate_DatePrototype_GetField(masm, JSDate::kSecondUTC); |
| 4720 } | 4613 } |
| 4721 | 4614 |
| 4722 | |
| 4723 namespace { | 4615 namespace { |
| 4724 | 4616 |
| 4725 // ES6 section 19.2.1.1.1 CreateDynamicFunction | 4617 // ES6 section 19.2.1.1.1 CreateDynamicFunction |
| 4726 MaybeHandle<JSFunction> CreateDynamicFunction(Isolate* isolate, | 4618 MaybeHandle<JSFunction> CreateDynamicFunction(Isolate* isolate, |
| 4727 BuiltinArguments args, | 4619 BuiltinArguments args, |
| 4728 const char* token) { | 4620 const char* token) { |
| 4729 // Compute number of arguments, ignoring the receiver. | 4621 // Compute number of arguments, ignoring the receiver. |
| 4730 DCHECK_LE(1, args.length()); | 4622 DCHECK_LE(1, args.length()); |
| 4731 int const argc = args.length() - 1; | 4623 int const argc = args.length() - 1; |
| 4732 | 4624 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4826 | 4718 |
| 4827 Handle<Context> context(function->context(), isolate); | 4719 Handle<Context> context(function->context(), isolate); |
| 4828 function = isolate->factory()->NewFunctionFromSharedFunctionInfo( | 4720 function = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 4829 map, shared_info, context, NOT_TENURED); | 4721 map, shared_info, context, NOT_TENURED); |
| 4830 } | 4722 } |
| 4831 return function; | 4723 return function; |
| 4832 } | 4724 } |
| 4833 | 4725 |
| 4834 } // namespace | 4726 } // namespace |
| 4835 | 4727 |
| 4836 | |
| 4837 // ES6 section 19.2.1.1 Function ( p1, p2, ... , pn, body ) | 4728 // ES6 section 19.2.1.1 Function ( p1, p2, ... , pn, body ) |
| 4838 BUILTIN(FunctionConstructor) { | 4729 BUILTIN(FunctionConstructor) { |
| 4839 HandleScope scope(isolate); | 4730 HandleScope scope(isolate); |
| 4840 Handle<JSFunction> result; | 4731 Handle<JSFunction> result; |
| 4841 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4732 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 4842 isolate, result, CreateDynamicFunction(isolate, args, "function")); | 4733 isolate, result, CreateDynamicFunction(isolate, args, "function")); |
| 4843 return *result; | 4734 return *result; |
| 4844 } | 4735 } |
| 4845 | 4736 |
| 4846 namespace { | 4737 namespace { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4953 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); | 4844 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); |
| 4954 } else if (receiver->IsJSFunction()) { | 4845 } else if (receiver->IsJSFunction()) { |
| 4955 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); | 4846 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); |
| 4956 } | 4847 } |
| 4957 THROW_NEW_ERROR_RETURN_FAILURE( | 4848 THROW_NEW_ERROR_RETURN_FAILURE( |
| 4958 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 4849 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 4959 isolate->factory()->NewStringFromAsciiChecked( | 4850 isolate->factory()->NewStringFromAsciiChecked( |
| 4960 "Function.prototype.toString"))); | 4851 "Function.prototype.toString"))); |
| 4961 } | 4852 } |
| 4962 | 4853 |
| 4963 | |
| 4964 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) | 4854 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) |
| 4965 BUILTIN(GeneratorFunctionConstructor) { | 4855 BUILTIN(GeneratorFunctionConstructor) { |
| 4966 HandleScope scope(isolate); | 4856 HandleScope scope(isolate); |
| 4967 RETURN_RESULT_OR_FAILURE(isolate, | 4857 RETURN_RESULT_OR_FAILURE(isolate, |
| 4968 CreateDynamicFunction(isolate, args, "function*")); | 4858 CreateDynamicFunction(isolate, args, "function*")); |
| 4969 } | 4859 } |
| 4970 | 4860 |
| 4971 BUILTIN(AsyncFunctionConstructor) { | 4861 BUILTIN(AsyncFunctionConstructor) { |
| 4972 HandleScope scope(isolate); | 4862 HandleScope scope(isolate); |
| 4973 Handle<JSFunction> func; | 4863 Handle<JSFunction> func; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5019 Handle<Symbol> result = isolate->factory()->NewSymbol(); | 4909 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
| 5020 Handle<Object> description = args.atOrUndefined(isolate, 1); | 4910 Handle<Object> description = args.atOrUndefined(isolate, 1); |
| 5021 if (!description->IsUndefined(isolate)) { | 4911 if (!description->IsUndefined(isolate)) { |
| 5022 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, | 4912 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
| 5023 Object::ToString(isolate, description)); | 4913 Object::ToString(isolate, description)); |
| 5024 result->set_name(*description); | 4914 result->set_name(*description); |
| 5025 } | 4915 } |
| 5026 return *result; | 4916 return *result; |
| 5027 } | 4917 } |
| 5028 | 4918 |
| 5029 | |
| 5030 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. | 4919 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. |
| 5031 BUILTIN(SymbolConstructor_ConstructStub) { | 4920 BUILTIN(SymbolConstructor_ConstructStub) { |
| 5032 HandleScope scope(isolate); | 4921 HandleScope scope(isolate); |
| 5033 THROW_NEW_ERROR_RETURN_FAILURE( | 4922 THROW_NEW_ERROR_RETURN_FAILURE( |
| 5034 isolate, NewTypeError(MessageTemplate::kNotConstructor, | 4923 isolate, NewTypeError(MessageTemplate::kNotConstructor, |
| 5035 isolate->factory()->Symbol_string())); | 4924 isolate->factory()->Symbol_string())); |
| 5036 } | 4925 } |
| 5037 | 4926 |
| 5038 // ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) | 4927 // ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) |
| 5039 void Builtins::Generate_SymbolPrototypeToPrimitive( | 4928 void Builtins::Generate_SymbolPrototypeToPrimitive( |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5597 BUILTIN(ArrayBufferConstructor) { | 5486 BUILTIN(ArrayBufferConstructor) { |
| 5598 HandleScope scope(isolate); | 5487 HandleScope scope(isolate); |
| 5599 Handle<JSFunction> target = args.target<JSFunction>(); | 5488 Handle<JSFunction> target = args.target<JSFunction>(); |
| 5600 DCHECK(*target == target->native_context()->array_buffer_fun() || | 5489 DCHECK(*target == target->native_context()->array_buffer_fun() || |
| 5601 *target == target->native_context()->shared_array_buffer_fun()); | 5490 *target == target->native_context()->shared_array_buffer_fun()); |
| 5602 THROW_NEW_ERROR_RETURN_FAILURE( | 5491 THROW_NEW_ERROR_RETURN_FAILURE( |
| 5603 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction, | 5492 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction, |
| 5604 handle(target->shared()->name(), isolate))); | 5493 handle(target->shared()->name(), isolate))); |
| 5605 } | 5494 } |
| 5606 | 5495 |
| 5607 | |
| 5608 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case. | 5496 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case. |
| 5609 BUILTIN(ArrayBufferConstructor_ConstructStub) { | 5497 BUILTIN(ArrayBufferConstructor_ConstructStub) { |
| 5610 HandleScope scope(isolate); | 5498 HandleScope scope(isolate); |
| 5611 Handle<JSFunction> target = args.target<JSFunction>(); | 5499 Handle<JSFunction> target = args.target<JSFunction>(); |
| 5612 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 5500 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
| 5613 Handle<Object> length = args.atOrUndefined(isolate, 1); | 5501 Handle<Object> length = args.atOrUndefined(isolate, 1); |
| 5614 DCHECK(*target == target->native_context()->array_buffer_fun() || | 5502 DCHECK(*target == target->native_context()->array_buffer_fun() || |
| 5615 *target == target->native_context()->shared_array_buffer_fun()); | 5503 *target == target->native_context()->shared_array_buffer_fun()); |
| 5616 Handle<Object> number_length; | 5504 Handle<Object> number_length; |
| 5617 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length, | 5505 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5684 | 5572 |
| 5685 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case. | 5573 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case. |
| 5686 BUILTIN(ProxyConstructor) { | 5574 BUILTIN(ProxyConstructor) { |
| 5687 HandleScope scope(isolate); | 5575 HandleScope scope(isolate); |
| 5688 THROW_NEW_ERROR_RETURN_FAILURE( | 5576 THROW_NEW_ERROR_RETURN_FAILURE( |
| 5689 isolate, | 5577 isolate, |
| 5690 NewTypeError(MessageTemplate::kConstructorNotFunction, | 5578 NewTypeError(MessageTemplate::kConstructorNotFunction, |
| 5691 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); | 5579 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); |
| 5692 } | 5580 } |
| 5693 | 5581 |
| 5694 | |
| 5695 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. | 5582 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. |
| 5696 BUILTIN(ProxyConstructor_ConstructStub) { | 5583 BUILTIN(ProxyConstructor_ConstructStub) { |
| 5697 HandleScope scope(isolate); | 5584 HandleScope scope(isolate); |
| 5698 DCHECK(isolate->proxy_function()->IsConstructor()); | 5585 DCHECK(isolate->proxy_function()->IsConstructor()); |
| 5699 Handle<Object> target = args.atOrUndefined(isolate, 1); | 5586 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 5700 Handle<Object> handler = args.atOrUndefined(isolate, 2); | 5587 Handle<Object> handler = args.atOrUndefined(isolate, 2); |
| 5701 RETURN_RESULT_OR_FAILURE(isolate, JSProxy::New(isolate, target, handler)); | 5588 RETURN_RESULT_OR_FAILURE(isolate, JSProxy::New(isolate, target, handler)); |
| 5702 } | 5589 } |
| 5703 | 5590 |
| 5704 | |
| 5705 // ----------------------------------------------------------------------------- | 5591 // ----------------------------------------------------------------------------- |
| 5706 // Throwers for restricted function properties and strict arguments object | 5592 // Throwers for restricted function properties and strict arguments object |
| 5707 // properties | 5593 // properties |
| 5708 | 5594 |
| 5709 | |
| 5710 BUILTIN(RestrictedFunctionPropertiesThrower) { | 5595 BUILTIN(RestrictedFunctionPropertiesThrower) { |
| 5711 HandleScope scope(isolate); | 5596 HandleScope scope(isolate); |
| 5712 THROW_NEW_ERROR_RETURN_FAILURE( | 5597 THROW_NEW_ERROR_RETURN_FAILURE( |
| 5713 isolate, NewTypeError(MessageTemplate::kRestrictedFunctionProperties)); | 5598 isolate, NewTypeError(MessageTemplate::kRestrictedFunctionProperties)); |
| 5714 } | 5599 } |
| 5715 | 5600 |
| 5716 | |
| 5717 BUILTIN(RestrictedStrictArgumentsPropertiesThrower) { | 5601 BUILTIN(RestrictedStrictArgumentsPropertiesThrower) { |
| 5718 HandleScope scope(isolate); | 5602 HandleScope scope(isolate); |
| 5719 THROW_NEW_ERROR_RETURN_FAILURE( | 5603 THROW_NEW_ERROR_RETURN_FAILURE( |
| 5720 isolate, NewTypeError(MessageTemplate::kStrictPoisonPill)); | 5604 isolate, NewTypeError(MessageTemplate::kStrictPoisonPill)); |
| 5721 } | 5605 } |
| 5722 | 5606 |
| 5723 | |
| 5724 // ----------------------------------------------------------------------------- | 5607 // ----------------------------------------------------------------------------- |
| 5725 // | 5608 // |
| 5726 | 5609 |
| 5727 | |
| 5728 namespace { | 5610 namespace { |
| 5729 | 5611 |
| 5730 // Returns the holder JSObject if the function can legally be called with this | 5612 // Returns the holder JSObject if the function can legally be called with this |
| 5731 // receiver. Returns nullptr if the call is illegal. | 5613 // receiver. Returns nullptr if the call is illegal. |
| 5732 // TODO(dcarney): CallOptimization duplicates this logic, merge. | 5614 // TODO(dcarney): CallOptimization duplicates this logic, merge. |
| 5733 JSObject* GetCompatibleReceiver(Isolate* isolate, FunctionTemplateInfo* info, | 5615 JSObject* GetCompatibleReceiver(Isolate* isolate, FunctionTemplateInfo* info, |
| 5734 JSObject* receiver) { | 5616 JSObject* receiver) { |
| 5735 Object* recv_type = info->signature(); | 5617 Object* recv_type = info->signature(); |
| 5736 // No signature, return holder. | 5618 // No signature, return holder. |
| 5737 if (!recv_type->IsFunctionTemplateInfo()) return receiver; | 5619 if (!recv_type->IsFunctionTemplateInfo()) return receiver; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5827 // Rebox the result. | 5709 // Rebox the result. |
| 5828 result->VerifyApiCallResultType(); | 5710 result->VerifyApiCallResultType(); |
| 5829 if (!is_construct || result->IsJSObject()) return handle(*result, isolate); | 5711 if (!is_construct || result->IsJSObject()) return handle(*result, isolate); |
| 5830 } | 5712 } |
| 5831 | 5713 |
| 5832 return js_receiver; | 5714 return js_receiver; |
| 5833 } | 5715 } |
| 5834 | 5716 |
| 5835 } // namespace | 5717 } // namespace |
| 5836 | 5718 |
| 5837 | |
| 5838 BUILTIN(HandleApiCall) { | 5719 BUILTIN(HandleApiCall) { |
| 5839 HandleScope scope(isolate); | 5720 HandleScope scope(isolate); |
| 5840 Handle<JSFunction> function = args.target<JSFunction>(); | 5721 Handle<JSFunction> function = args.target<JSFunction>(); |
| 5841 Handle<Object> receiver = args.receiver(); | 5722 Handle<Object> receiver = args.receiver(); |
| 5842 Handle<HeapObject> new_target = args.new_target(); | 5723 Handle<HeapObject> new_target = args.new_target(); |
| 5843 Handle<FunctionTemplateInfo> fun_data(function->shared()->get_api_func_data(), | 5724 Handle<FunctionTemplateInfo> fun_data(function->shared()->get_api_func_data(), |
| 5844 isolate); | 5725 isolate); |
| 5845 if (new_target->IsJSReceiver()) { | 5726 if (new_target->IsJSReceiver()) { |
| 5846 RETURN_RESULT_OR_FAILURE( | 5727 RETURN_RESULT_OR_FAILURE( |
| 5847 isolate, HandleApiCallHelper<true>(isolate, function, new_target, | 5728 isolate, HandleApiCallHelper<true>(isolate, function, new_target, |
| 5848 fun_data, receiver, args)); | 5729 fun_data, receiver, args)); |
| 5849 } else { | 5730 } else { |
| 5850 RETURN_RESULT_OR_FAILURE( | 5731 RETURN_RESULT_OR_FAILURE( |
| 5851 isolate, HandleApiCallHelper<false>(isolate, function, new_target, | 5732 isolate, HandleApiCallHelper<false>(isolate, function, new_target, |
| 5852 fun_data, receiver, args)); | 5733 fun_data, receiver, args)); |
| 5853 } | 5734 } |
| 5854 } | 5735 } |
| 5855 | 5736 |
| 5856 | |
| 5857 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode, | 5737 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode, |
| 5858 TailCallMode tail_call_mode) { | 5738 TailCallMode tail_call_mode) { |
| 5859 switch (tail_call_mode) { | 5739 switch (tail_call_mode) { |
| 5860 case TailCallMode::kDisallow: | 5740 case TailCallMode::kDisallow: |
| 5861 switch (mode) { | 5741 switch (mode) { |
| 5862 case ConvertReceiverMode::kNullOrUndefined: | 5742 case ConvertReceiverMode::kNullOrUndefined: |
| 5863 return CallFunction_ReceiverIsNullOrUndefined(); | 5743 return CallFunction_ReceiverIsNullOrUndefined(); |
| 5864 case ConvertReceiverMode::kNotNullOrUndefined: | 5744 case ConvertReceiverMode::kNotNullOrUndefined: |
| 5865 return CallFunction_ReceiverIsNotNullOrUndefined(); | 5745 return CallFunction_ReceiverIsNotNullOrUndefined(); |
| 5866 case ConvertReceiverMode::kAny: | 5746 case ConvertReceiverMode::kAny: |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6007 MaybeHandle<Object> result; | 5887 MaybeHandle<Object> result; |
| 6008 { | 5888 { |
| 6009 RelocatableArguments arguments(isolate, frame_argc, &argv[frame_argc - 1]); | 5889 RelocatableArguments arguments(isolate, frame_argc, &argv[frame_argc - 1]); |
| 6010 result = HandleApiCallHelper<false>(isolate, function, new_target, fun_data, | 5890 result = HandleApiCallHelper<false>(isolate, function, new_target, fun_data, |
| 6011 receiver, arguments); | 5891 receiver, arguments); |
| 6012 } | 5892 } |
| 6013 if (argv != small_argv) delete[] argv; | 5893 if (argv != small_argv) delete[] argv; |
| 6014 return result; | 5894 return result; |
| 6015 } | 5895 } |
| 6016 | 5896 |
| 6017 | |
| 6018 // Helper function to handle calls to non-function objects created through the | 5897 // Helper function to handle calls to non-function objects created through the |
| 6019 // API. The object can be called as either a constructor (using new) or just as | 5898 // API. The object can be called as either a constructor (using new) or just as |
| 6020 // a function (without new). | 5899 // a function (without new). |
| 6021 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor( | 5900 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor( |
| 6022 Isolate* isolate, bool is_construct_call, BuiltinArguments args) { | 5901 Isolate* isolate, bool is_construct_call, BuiltinArguments args) { |
| 6023 Handle<Object> receiver = args.receiver(); | 5902 Handle<Object> receiver = args.receiver(); |
| 6024 | 5903 |
| 6025 // Get the object called. | 5904 // Get the object called. |
| 6026 JSObject* obj = JSObject::cast(*receiver); | 5905 JSObject* obj = JSObject::cast(*receiver); |
| 6027 | 5906 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6067 result = isolate->heap()->undefined_value(); | 5946 result = isolate->heap()->undefined_value(); |
| 6068 } else { | 5947 } else { |
| 6069 result = *result_handle; | 5948 result = *result_handle; |
| 6070 } | 5949 } |
| 6071 } | 5950 } |
| 6072 // Check for exceptions and return result. | 5951 // Check for exceptions and return result. |
| 6073 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); | 5952 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); |
| 6074 return result; | 5953 return result; |
| 6075 } | 5954 } |
| 6076 | 5955 |
| 6077 | |
| 6078 // Handle calls to non-function objects created through the API. This delegate | 5956 // Handle calls to non-function objects created through the API. This delegate |
| 6079 // function is used when the call is a normal function call. | 5957 // function is used when the call is a normal function call. |
| 6080 BUILTIN(HandleApiCallAsFunction) { | 5958 BUILTIN(HandleApiCallAsFunction) { |
| 6081 return HandleApiCallAsFunctionOrConstructor(isolate, false, args); | 5959 return HandleApiCallAsFunctionOrConstructor(isolate, false, args); |
| 6082 } | 5960 } |
| 6083 | 5961 |
| 6084 | |
| 6085 // Handle calls to non-function objects created through the API. This delegate | 5962 // Handle calls to non-function objects created through the API. This delegate |
| 6086 // function is used when the call is a construct call. | 5963 // function is used when the call is a construct call. |
| 6087 BUILTIN(HandleApiCallAsConstructor) { | 5964 BUILTIN(HandleApiCallAsConstructor) { |
| 6088 return HandleApiCallAsFunctionOrConstructor(isolate, true, args); | 5965 return HandleApiCallAsFunctionOrConstructor(isolate, true, args); |
| 6089 } | 5966 } |
| 6090 | 5967 |
| 6091 namespace { | 5968 namespace { |
| 6092 | 5969 |
| 6093 void Generate_LoadIC_Miss(CodeStubAssembler* assembler) { | 5970 void Generate_LoadIC_Miss(CodeStubAssembler* assembler) { |
| 6094 typedef compiler::Node Node; | 5971 typedef compiler::Node Node; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6244 DebugCodegen::GenerateFrameDropperLiveEdit(masm); | 6121 DebugCodegen::GenerateFrameDropperLiveEdit(masm); |
| 6245 } | 6122 } |
| 6246 | 6123 |
| 6247 } // namespace | 6124 } // namespace |
| 6248 | 6125 |
| 6249 Builtins::Builtins() : initialized_(false) { | 6126 Builtins::Builtins() : initialized_(false) { |
| 6250 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); | 6127 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); |
| 6251 memset(names_, 0, sizeof(names_[0]) * builtin_count); | 6128 memset(names_, 0, sizeof(names_[0]) * builtin_count); |
| 6252 } | 6129 } |
| 6253 | 6130 |
| 6254 | 6131 Builtins::~Builtins() {} |
| 6255 Builtins::~Builtins() { | |
| 6256 } | |
| 6257 | 6132 |
| 6258 #define DEF_ENUM_C(name, ignore) FUNCTION_ADDR(Builtin_##name), | 6133 #define DEF_ENUM_C(name, ignore) FUNCTION_ADDR(Builtin_##name), |
| 6259 Address const Builtins::c_functions_[cfunction_count] = { | 6134 Address const Builtins::c_functions_[cfunction_count] = { |
| 6260 BUILTIN_LIST_C(DEF_ENUM_C) | 6135 BUILTIN_LIST_C(DEF_ENUM_C)}; |
| 6261 }; | |
| 6262 #undef DEF_ENUM_C | 6136 #undef DEF_ENUM_C |
| 6263 | 6137 |
| 6264 | |
| 6265 struct BuiltinDesc { | 6138 struct BuiltinDesc { |
| 6266 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); | 6139 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); |
| 6267 byte* generator; | 6140 byte* generator; |
| 6268 byte* c_code; | 6141 byte* c_code; |
| 6269 const char* s_name; // name is only used for generating log information. | 6142 const char* s_name; // name is only used for generating log information. |
| 6270 int name; | 6143 int name; |
| 6271 Code::Flags flags; | 6144 Code::Flags flags; |
| 6272 Builtins::ExitFrameType exit_frame_type; | 6145 Builtins::ExitFrameType exit_frame_type; |
| 6273 int argc; | 6146 int argc; |
| 6274 }; | 6147 }; |
| 6275 | 6148 |
| 6276 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } | 6149 #define BUILTIN_FUNCTION_TABLE_INIT \ |
| 6150 { \ |
| 6151 V8_ONCE_INIT, {} \ |
| 6152 } |
| 6277 | 6153 |
| 6278 class BuiltinFunctionTable { | 6154 class BuiltinFunctionTable { |
| 6279 public: | 6155 public: |
| 6280 BuiltinDesc* functions() { | 6156 BuiltinDesc* functions() { |
| 6281 base::CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); | 6157 base::CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); |
| 6282 return functions_; | 6158 return functions_; |
| 6283 } | 6159 } |
| 6284 | 6160 |
| 6285 base::OnceType once_; | 6161 base::OnceType once_; |
| 6286 BuiltinDesc functions_[Builtins::builtin_count + 1]; | 6162 BuiltinDesc functions_[Builtins::builtin_count + 1]; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6439 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) | 6315 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) |
| 6440 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) | 6316 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) |
| 6441 | 6317 |
| 6442 #undef DEF_FUNCTION_PTR_C | 6318 #undef DEF_FUNCTION_PTR_C |
| 6443 #undef DEF_FUNCTION_PTR_A | 6319 #undef DEF_FUNCTION_PTR_A |
| 6444 #undef DEF_FUNCTION_PTR_T | 6320 #undef DEF_FUNCTION_PTR_T |
| 6445 #undef DEF_FUNCTION_PTR_S | 6321 #undef DEF_FUNCTION_PTR_S |
| 6446 #undef DEF_FUNCTION_PTR_H | 6322 #undef DEF_FUNCTION_PTR_H |
| 6447 } | 6323 } |
| 6448 | 6324 |
| 6449 | |
| 6450 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { | 6325 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
| 6451 DCHECK(!initialized_); | 6326 DCHECK(!initialized_); |
| 6452 | 6327 |
| 6453 // Create a scope for the handles in the builtins. | 6328 // Create a scope for the handles in the builtins. |
| 6454 HandleScope scope(isolate); | 6329 HandleScope scope(isolate); |
| 6455 | 6330 |
| 6456 #define INITIALIZE_CALL_DESCRIPTOR(name, kind, extra, interface_descriptor) \ | 6331 #define INITIALIZE_CALL_DESCRIPTOR(name, kind, extra, interface_descriptor) \ |
| 6457 { interface_descriptor##Descriptor descriptor(isolate); } | 6332 { interface_descriptor##Descriptor descriptor(isolate); } |
| 6458 BUILTIN_LIST_S(INITIALIZE_CALL_DESCRIPTOR) | 6333 BUILTIN_LIST_S(INITIALIZE_CALL_DESCRIPTOR) |
| 6459 #undef INITIALIZE_CALL_DESCRIPTOR | 6334 #undef INITIALIZE_CALL_DESCRIPTOR |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6484 // Deserializing. The values will be filled in during IterateBuiltins. | 6359 // Deserializing. The values will be filled in during IterateBuiltins. |
| 6485 builtins_[i] = NULL; | 6360 builtins_[i] = NULL; |
| 6486 } | 6361 } |
| 6487 names_[i] = functions[i].s_name; | 6362 names_[i] = functions[i].s_name; |
| 6488 } | 6363 } |
| 6489 | 6364 |
| 6490 // Mark as initialized. | 6365 // Mark as initialized. |
| 6491 initialized_ = true; | 6366 initialized_ = true; |
| 6492 } | 6367 } |
| 6493 | 6368 |
| 6494 | 6369 void Builtins::TearDown() { initialized_ = false; } |
| 6495 void Builtins::TearDown() { | |
| 6496 initialized_ = false; | |
| 6497 } | |
| 6498 | |
| 6499 | 6370 |
| 6500 void Builtins::IterateBuiltins(ObjectVisitor* v) { | 6371 void Builtins::IterateBuiltins(ObjectVisitor* v) { |
| 6501 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); | 6372 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count); |
| 6502 } | 6373 } |
| 6503 | 6374 |
| 6504 | |
| 6505 const char* Builtins::Lookup(byte* pc) { | 6375 const char* Builtins::Lookup(byte* pc) { |
| 6506 // may be called during initialization (disassembler!) | 6376 // may be called during initialization (disassembler!) |
| 6507 if (initialized_) { | 6377 if (initialized_) { |
| 6508 for (int i = 0; i < builtin_count; i++) { | 6378 for (int i = 0; i < builtin_count; i++) { |
| 6509 Code* entry = Code::cast(builtins_[i]); | 6379 Code* entry = Code::cast(builtins_[i]); |
| 6510 if (entry->contains(pc)) { | 6380 if (entry->contains(pc)) { |
| 6511 return names_[i]; | 6381 return names_[i]; |
| 6512 } | 6382 } |
| 6513 } | 6383 } |
| 6514 } | 6384 } |
| 6515 return NULL; | 6385 return NULL; |
| 6516 } | 6386 } |
| 6517 | 6387 |
| 6518 | |
| 6519 void Builtins::Generate_InterruptCheck(MacroAssembler* masm) { | 6388 void Builtins::Generate_InterruptCheck(MacroAssembler* masm) { |
| 6520 masm->TailCallRuntime(Runtime::kInterrupt); | 6389 masm->TailCallRuntime(Runtime::kInterrupt); |
| 6521 } | 6390 } |
| 6522 | 6391 |
| 6523 | |
| 6524 void Builtins::Generate_StackCheck(MacroAssembler* masm) { | 6392 void Builtins::Generate_StackCheck(MacroAssembler* masm) { |
| 6525 masm->TailCallRuntime(Runtime::kStackGuard); | 6393 masm->TailCallRuntime(Runtime::kStackGuard); |
| 6526 } | 6394 } |
| 6527 | 6395 |
| 6528 namespace { | 6396 namespace { |
| 6529 | 6397 |
| 6530 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, | 6398 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, |
| 6531 compiler::Node* context, | 6399 compiler::Node* context, |
| 6532 compiler::Node** out_instance_type, | 6400 compiler::Node** out_instance_type, |
| 6533 compiler::Node** out_backing_store) { | 6401 compiler::Node** out_backing_store) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6775 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ | 6643 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ |
| 6776 Handle<Code> Builtins::name() { \ | 6644 Handle<Code> Builtins::name() { \ |
| 6777 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6645 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
| 6778 return Handle<Code>(code_address); \ | 6646 return Handle<Code>(code_address); \ |
| 6779 } | 6647 } |
| 6780 #define DEFINE_BUILTIN_ACCESSOR_S(name, kind, extra, interface_descriptor) \ | 6648 #define DEFINE_BUILTIN_ACCESSOR_S(name, kind, extra, interface_descriptor) \ |
| 6781 Handle<Code> Builtins::name() { \ | 6649 Handle<Code> Builtins::name() { \ |
| 6782 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6650 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
| 6783 return Handle<Code>(code_address); \ | 6651 return Handle<Code>(code_address); \ |
| 6784 } | 6652 } |
| 6785 #define DEFINE_BUILTIN_ACCESSOR_H(name, kind) \ | 6653 #define DEFINE_BUILTIN_ACCESSOR_H(name, kind) \ |
| 6786 Handle<Code> Builtins::name() { \ | 6654 Handle<Code> Builtins::name() { \ |
| 6787 Code** code_address = \ | 6655 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ |
| 6788 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6656 return Handle<Code>(code_address); \ |
| 6789 return Handle<Code>(code_address); \ | 6657 } |
| 6790 } | |
| 6791 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 6658 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 6792 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 6659 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 6793 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 6660 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
| 6794 BUILTIN_LIST_S(DEFINE_BUILTIN_ACCESSOR_S) | 6661 BUILTIN_LIST_S(DEFINE_BUILTIN_ACCESSOR_S) |
| 6795 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 6662 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 6796 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 6663 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 6797 #undef DEFINE_BUILTIN_ACCESSOR_C | 6664 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 6798 #undef DEFINE_BUILTIN_ACCESSOR_A | 6665 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 6799 #undef DEFINE_BUILTIN_ACCESSOR_T | 6666 #undef DEFINE_BUILTIN_ACCESSOR_T |
| 6800 #undef DEFINE_BUILTIN_ACCESSOR_S | 6667 #undef DEFINE_BUILTIN_ACCESSOR_S |
| 6801 #undef DEFINE_BUILTIN_ACCESSOR_H | 6668 #undef DEFINE_BUILTIN_ACCESSOR_H |
| 6802 | 6669 |
| 6803 } // namespace internal | 6670 } // namespace internal |
| 6804 } // namespace v8 | 6671 } // namespace v8 |
| OLD | NEW |