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.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/once.h" | 10 #include "src/base/once.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ | 177 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ |
178 isolate->factory()->NewStringFromAsciiChecked(method), \ | 178 isolate->factory()->NewStringFromAsciiChecked(method), \ |
179 args.receiver())); \ | 179 args.receiver())); \ |
180 } \ | 180 } \ |
181 Handle<Type> name = Handle<Type>::cast(args.receiver()) | 181 Handle<Type> name = Handle<Type>::cast(args.receiver()) |
182 | 182 |
183 // Throws a TypeError for {method} if the receiver is not coercible to Object, | 183 // Throws a TypeError for {method} if the receiver is not coercible to Object, |
184 // or converts the receiver to a String otherwise and assigns it to a new var | 184 // or converts the receiver to a String otherwise and assigns it to a new var |
185 // with the given {name}. | 185 // with the given {name}. |
186 #define TO_THIS_STRING(name, method) \ | 186 #define TO_THIS_STRING(name, method) \ |
187 if (args.receiver()->IsNull() || args.receiver()->IsUndefined()) { \ | 187 if (args.receiver()->IsNull() || args.receiver()->IsUndefined(isolate)) { \ |
188 THROW_NEW_ERROR_RETURN_FAILURE( \ | 188 THROW_NEW_ERROR_RETURN_FAILURE( \ |
189 isolate, \ | 189 isolate, \ |
190 NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \ | 190 NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \ |
191 isolate->factory()->NewStringFromAsciiChecked(method))); \ | 191 isolate->factory()->NewStringFromAsciiChecked(method))); \ |
192 } \ | 192 } \ |
193 Handle<String> name; \ | 193 Handle<String> name; \ |
194 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 194 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ |
195 isolate, name, Object::ToString(isolate, args.receiver())) | 195 isolate, name, Object::ToString(isolate, args.receiver())) |
196 | 196 |
197 inline bool ClampedToInteger(Object* object, int* out) { | 197 inline bool ClampedToInteger(Object* object, int* out) { |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 relative_end = len; | 597 relative_end = len; |
598 if (argument_count > 0) { | 598 if (argument_count > 0) { |
599 DisallowHeapAllocation no_gc; | 599 DisallowHeapAllocation no_gc; |
600 if (!ClampedToInteger(args[1], &relative_start)) { | 600 if (!ClampedToInteger(args[1], &relative_start)) { |
601 AllowHeapAllocation allow_allocation; | 601 AllowHeapAllocation allow_allocation; |
602 return CallJsIntrinsic(isolate, isolate->array_slice(), args); | 602 return CallJsIntrinsic(isolate, isolate->array_slice(), args); |
603 } | 603 } |
604 if (argument_count > 1) { | 604 if (argument_count > 1) { |
605 Object* end_arg = args[2]; | 605 Object* end_arg = args[2]; |
606 // slice handles the end_arg specially | 606 // slice handles the end_arg specially |
607 if (end_arg->IsUndefined()) { | 607 if (end_arg->IsUndefined(isolate)) { |
608 relative_end = len; | 608 relative_end = len; |
609 } else if (!ClampedToInteger(end_arg, &relative_end)) { | 609 } else if (!ClampedToInteger(end_arg, &relative_end)) { |
610 AllowHeapAllocation allow_allocation; | 610 AllowHeapAllocation allow_allocation; |
611 return CallJsIntrinsic(isolate, isolate->array_slice(), args); | 611 return CallJsIntrinsic(isolate, isolate->array_slice(), args); |
612 } | 612 } |
613 } | 613 } |
614 } | 614 } |
615 | 615 |
616 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6. | 616 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6. |
617 uint32_t actual_start = (relative_start < 0) ? Max(len + relative_start, 0) | 617 uint32_t actual_start = (relative_start < 0) ? Max(len + relative_start, 0) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 // Convert storage to dictionary mode. | 812 // Convert storage to dictionary mode. |
813 void SetDictionaryMode() { | 813 void SetDictionaryMode() { |
814 DCHECK(fast_elements() && is_fixed_array()); | 814 DCHECK(fast_elements() && is_fixed_array()); |
815 Handle<FixedArray> current_storage = storage_fixed_array(); | 815 Handle<FixedArray> current_storage = storage_fixed_array(); |
816 Handle<SeededNumberDictionary> slow_storage( | 816 Handle<SeededNumberDictionary> slow_storage( |
817 SeededNumberDictionary::New(isolate_, current_storage->length())); | 817 SeededNumberDictionary::New(isolate_, current_storage->length())); |
818 uint32_t current_length = static_cast<uint32_t>(current_storage->length()); | 818 uint32_t current_length = static_cast<uint32_t>(current_storage->length()); |
819 FOR_WITH_HANDLE_SCOPE( | 819 FOR_WITH_HANDLE_SCOPE( |
820 isolate_, uint32_t, i = 0, i, i < current_length, i++, { | 820 isolate_, uint32_t, i = 0, i, i < current_length, i++, { |
821 Handle<Object> element(current_storage->get(i), isolate_); | 821 Handle<Object> element(current_storage->get(i), isolate_); |
822 if (!element->IsTheHole()) { | 822 if (!element->IsTheHole(isolate_)) { |
823 // The object holding this backing store has just been allocated, so | 823 // The object holding this backing store has just been allocated, so |
824 // it cannot yet be used as a prototype. | 824 // it cannot yet be used as a prototype. |
825 Handle<SeededNumberDictionary> new_storage = | 825 Handle<SeededNumberDictionary> new_storage = |
826 SeededNumberDictionary::AtNumberPut(slow_storage, i, element, | 826 SeededNumberDictionary::AtNumberPut(slow_storage, i, element, |
827 false); | 827 false); |
828 if (!new_storage.is_identical_to(slow_storage)) { | 828 if (!new_storage.is_identical_to(slow_storage)) { |
829 slow_storage = loop_scope.CloseAndEscape(new_storage); | 829 slow_storage = loop_scope.CloseAndEscape(new_storage); |
830 } | 830 } |
831 } | 831 } |
832 }); | 832 }); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 int element_count = 0; | 869 int element_count = 0; |
870 switch (array->GetElementsKind()) { | 870 switch (array->GetElementsKind()) { |
871 case FAST_SMI_ELEMENTS: | 871 case FAST_SMI_ELEMENTS: |
872 case FAST_HOLEY_SMI_ELEMENTS: | 872 case FAST_HOLEY_SMI_ELEMENTS: |
873 case FAST_ELEMENTS: | 873 case FAST_ELEMENTS: |
874 case FAST_HOLEY_ELEMENTS: { | 874 case FAST_HOLEY_ELEMENTS: { |
875 // Fast elements can't have lengths that are not representable by | 875 // Fast elements can't have lengths that are not representable by |
876 // a 32-bit signed integer. | 876 // a 32-bit signed integer. |
877 DCHECK(static_cast<int32_t>(FixedArray::kMaxLength) >= 0); | 877 DCHECK(static_cast<int32_t>(FixedArray::kMaxLength) >= 0); |
878 int fast_length = static_cast<int>(length); | 878 int fast_length = static_cast<int>(length); |
879 Handle<FixedArray> elements(FixedArray::cast(array->elements())); | 879 Isolate* isolate = array->GetIsolate(); |
| 880 Handle<FixedArray> elements(FixedArray::cast(array->elements()), isolate); |
880 for (int i = 0; i < fast_length; i++) { | 881 for (int i = 0; i < fast_length; i++) { |
881 if (!elements->get(i)->IsTheHole()) element_count++; | 882 if (!elements->get(i)->IsTheHole(isolate)) element_count++; |
882 } | 883 } |
883 break; | 884 break; |
884 } | 885 } |
885 case FAST_DOUBLE_ELEMENTS: | 886 case FAST_DOUBLE_ELEMENTS: |
886 case FAST_HOLEY_DOUBLE_ELEMENTS: { | 887 case FAST_HOLEY_DOUBLE_ELEMENTS: { |
887 // Fast elements can't have lengths that are not representable by | 888 // Fast elements can't have lengths that are not representable by |
888 // a 32-bit signed integer. | 889 // a 32-bit signed integer. |
889 DCHECK(static_cast<int32_t>(FixedDoubleArray::kMaxLength) >= 0); | 890 DCHECK(static_cast<int32_t>(FixedDoubleArray::kMaxLength) >= 0); |
890 int fast_length = static_cast<int>(length); | 891 int fast_length = static_cast<int>(length); |
891 if (array->elements()->IsFixedArray()) { | 892 if (array->elements()->IsFixedArray()) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 switch (kind) { | 948 switch (kind) { |
948 case FAST_SMI_ELEMENTS: | 949 case FAST_SMI_ELEMENTS: |
949 case FAST_ELEMENTS: | 950 case FAST_ELEMENTS: |
950 case FAST_HOLEY_SMI_ELEMENTS: | 951 case FAST_HOLEY_SMI_ELEMENTS: |
951 case FAST_HOLEY_ELEMENTS: { | 952 case FAST_HOLEY_ELEMENTS: { |
952 DisallowHeapAllocation no_gc; | 953 DisallowHeapAllocation no_gc; |
953 FixedArray* elements = FixedArray::cast(object->elements()); | 954 FixedArray* elements = FixedArray::cast(object->elements()); |
954 uint32_t length = static_cast<uint32_t>(elements->length()); | 955 uint32_t length = static_cast<uint32_t>(elements->length()); |
955 if (range < length) length = range; | 956 if (range < length) length = range; |
956 for (uint32_t i = 0; i < length; i++) { | 957 for (uint32_t i = 0; i < length; i++) { |
957 if (!elements->get(i)->IsTheHole()) { | 958 if (!elements->get(i)->IsTheHole(isolate)) { |
958 indices->Add(i); | 959 indices->Add(i); |
959 } | 960 } |
960 } | 961 } |
961 break; | 962 break; |
962 } | 963 } |
963 case FAST_HOLEY_DOUBLE_ELEMENTS: | 964 case FAST_HOLEY_DOUBLE_ELEMENTS: |
964 case FAST_DOUBLE_ELEMENTS: { | 965 case FAST_DOUBLE_ELEMENTS: { |
965 if (object->elements()->IsFixedArray()) { | 966 if (object->elements()->IsFixedArray()) { |
966 DCHECK(object->elements()->length() == 0); | 967 DCHECK(object->elements()->length() == 0); |
967 break; | 968 break; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 case FAST_ELEMENTS: | 1118 case FAST_ELEMENTS: |
1118 case FAST_HOLEY_SMI_ELEMENTS: | 1119 case FAST_HOLEY_SMI_ELEMENTS: |
1119 case FAST_HOLEY_ELEMENTS: { | 1120 case FAST_HOLEY_ELEMENTS: { |
1120 // Run through the elements FixedArray and use HasElement and GetElement | 1121 // Run through the elements FixedArray and use HasElement and GetElement |
1121 // to check the prototype for missing elements. | 1122 // to check the prototype for missing elements. |
1122 Handle<FixedArray> elements(FixedArray::cast(array->elements())); | 1123 Handle<FixedArray> elements(FixedArray::cast(array->elements())); |
1123 int fast_length = static_cast<int>(length); | 1124 int fast_length = static_cast<int>(length); |
1124 DCHECK(fast_length <= elements->length()); | 1125 DCHECK(fast_length <= elements->length()); |
1125 FOR_WITH_HANDLE_SCOPE(isolate, int, j = 0, j, j < fast_length, j++, { | 1126 FOR_WITH_HANDLE_SCOPE(isolate, int, j = 0, j, j < fast_length, j++, { |
1126 Handle<Object> element_value(elements->get(j), isolate); | 1127 Handle<Object> element_value(elements->get(j), isolate); |
1127 if (!element_value->IsTheHole()) { | 1128 if (!element_value->IsTheHole(isolate)) { |
1128 if (!visitor->visit(j, element_value)) return false; | 1129 if (!visitor->visit(j, element_value)) return false; |
1129 } else { | 1130 } else { |
1130 Maybe<bool> maybe = JSReceiver::HasElement(array, j); | 1131 Maybe<bool> maybe = JSReceiver::HasElement(array, j); |
1131 if (!maybe.IsJust()) return false; | 1132 if (!maybe.IsJust()) return false; |
1132 if (maybe.FromJust()) { | 1133 if (maybe.FromJust()) { |
1133 // Call GetElement on array, not its prototype, or getters won't | 1134 // Call GetElement on array, not its prototype, or getters won't |
1134 // have the correct receiver. | 1135 // have the correct receiver. |
1135 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 1136 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
1136 isolate, element_value, | 1137 isolate, element_value, |
1137 JSReceiver::GetElement(isolate, array, j), false); | 1138 JSReceiver::GetElement(isolate, array, j), false); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 static Maybe<bool> IsConcatSpreadable(Isolate* isolate, Handle<Object> obj) { | 1232 static Maybe<bool> IsConcatSpreadable(Isolate* isolate, Handle<Object> obj) { |
1232 HandleScope handle_scope(isolate); | 1233 HandleScope handle_scope(isolate); |
1233 if (!obj->IsJSReceiver()) return Just(false); | 1234 if (!obj->IsJSReceiver()) return Just(false); |
1234 if (!isolate->IsIsConcatSpreadableLookupChainIntact()) { | 1235 if (!isolate->IsIsConcatSpreadableLookupChainIntact()) { |
1235 // Slow path if @@isConcatSpreadable has been used. | 1236 // Slow path if @@isConcatSpreadable has been used. |
1236 Handle<Symbol> key(isolate->factory()->is_concat_spreadable_symbol()); | 1237 Handle<Symbol> key(isolate->factory()->is_concat_spreadable_symbol()); |
1237 Handle<Object> value; | 1238 Handle<Object> value; |
1238 MaybeHandle<Object> maybeValue = | 1239 MaybeHandle<Object> maybeValue = |
1239 i::Runtime::GetObjectProperty(isolate, obj, key); | 1240 i::Runtime::GetObjectProperty(isolate, obj, key); |
1240 if (!maybeValue.ToHandle(&value)) return Nothing<bool>(); | 1241 if (!maybeValue.ToHandle(&value)) return Nothing<bool>(); |
1241 if (!value->IsUndefined()) return Just(value->BooleanValue()); | 1242 if (!value->IsUndefined(isolate)) return Just(value->BooleanValue()); |
1242 } | 1243 } |
1243 return Object::IsArray(obj); | 1244 return Object::IsArray(obj); |
1244 } | 1245 } |
1245 | 1246 |
1246 | 1247 |
1247 Object* Slow_ArrayConcat(Arguments* args, Handle<Object> species, | 1248 Object* Slow_ArrayConcat(Arguments* args, Handle<Object> species, |
1248 Isolate* isolate) { | 1249 Isolate* isolate) { |
1249 int argument_count = args->length(); | 1250 int argument_count = args->length(); |
1250 | 1251 |
1251 bool is_array_species = *species == isolate->context()->array_function(); | 1252 bool is_array_species = *species == isolate->context()->array_function(); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 | 1491 |
1491 } // namespace | 1492 } // namespace |
1492 | 1493 |
1493 | 1494 |
1494 // ES6 22.1.3.1 Array.prototype.concat | 1495 // ES6 22.1.3.1 Array.prototype.concat |
1495 BUILTIN(ArrayConcat) { | 1496 BUILTIN(ArrayConcat) { |
1496 HandleScope scope(isolate); | 1497 HandleScope scope(isolate); |
1497 | 1498 |
1498 Handle<Object> receiver = args.receiver(); | 1499 Handle<Object> receiver = args.receiver(); |
1499 // TODO(bmeurer): Do we really care about the exact exception message here? | 1500 // TODO(bmeurer): Do we really care about the exact exception message here? |
1500 if (receiver->IsNull() || receiver->IsUndefined()) { | 1501 if (receiver->IsNull() || receiver->IsUndefined(isolate)) { |
1501 THROW_NEW_ERROR_RETURN_FAILURE( | 1502 THROW_NEW_ERROR_RETURN_FAILURE( |
1502 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, | 1503 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, |
1503 isolate->factory()->NewStringFromAsciiChecked( | 1504 isolate->factory()->NewStringFromAsciiChecked( |
1504 "Array.prototype.concat"))); | 1505 "Array.prototype.concat"))); |
1505 } | 1506 } |
1506 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1507 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1507 isolate, receiver, Object::ToObject(isolate, args.receiver())); | 1508 isolate, receiver, Object::ToObject(isolate, args.receiver())); |
1508 args[0] = *receiver; | 1509 args[0] = *receiver; |
1509 | 1510 |
1510 Handle<JSArray> result_array; | 1511 Handle<JSArray> result_array; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 isolate); | 1691 isolate); |
1691 if (map->prototype() != *prototype) { | 1692 if (map->prototype() != *prototype) { |
1692 map = Map::TransitionToPrototype(map, prototype, FAST_PROTOTYPE); | 1693 map = Map::TransitionToPrototype(map, prototype, FAST_PROTOTYPE); |
1693 } | 1694 } |
1694 | 1695 |
1695 // Actually allocate the object. | 1696 // Actually allocate the object. |
1696 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); | 1697 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); |
1697 | 1698 |
1698 // Define the properties if properties was specified and is not undefined. | 1699 // Define the properties if properties was specified and is not undefined. |
1699 Handle<Object> properties = args.atOrUndefined(isolate, 2); | 1700 Handle<Object> properties = args.atOrUndefined(isolate, 2); |
1700 if (!properties->IsUndefined()) { | 1701 if (!properties->IsUndefined(isolate)) { |
1701 RETURN_FAILURE_ON_EXCEPTION( | 1702 RETURN_FAILURE_ON_EXCEPTION( |
1702 isolate, JSReceiver::DefineProperties(isolate, object, properties)); | 1703 isolate, JSReceiver::DefineProperties(isolate, object, properties)); |
1703 } | 1704 } |
1704 | 1705 |
1705 return *object; | 1706 return *object; |
1706 } | 1707 } |
1707 | 1708 |
1708 // ES6 section 19.1.2.3 Object.defineProperties | 1709 // ES6 section 19.1.2.3 Object.defineProperties |
1709 BUILTIN(ObjectDefineProperties) { | 1710 BUILTIN(ObjectDefineProperties) { |
1710 HandleScope scope(isolate); | 1711 HandleScope scope(isolate); |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2944 // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a | 2945 // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a |
2945 // TypeError exception. | 2946 // TypeError exception. |
2946 if (!buffer->IsJSArrayBuffer()) { | 2947 if (!buffer->IsJSArrayBuffer()) { |
2947 THROW_NEW_ERROR_RETURN_FAILURE( | 2948 THROW_NEW_ERROR_RETURN_FAILURE( |
2948 isolate, NewTypeError(MessageTemplate::kDataViewNotArrayBuffer)); | 2949 isolate, NewTypeError(MessageTemplate::kDataViewNotArrayBuffer)); |
2949 } | 2950 } |
2950 Handle<JSArrayBuffer> array_buffer = Handle<JSArrayBuffer>::cast(buffer); | 2951 Handle<JSArrayBuffer> array_buffer = Handle<JSArrayBuffer>::cast(buffer); |
2951 | 2952 |
2952 // 4. Let numberOffset be ? ToNumber(byteOffset). | 2953 // 4. Let numberOffset be ? ToNumber(byteOffset). |
2953 Handle<Object> number_offset; | 2954 Handle<Object> number_offset; |
2954 if (byte_offset->IsUndefined()) { | 2955 if (byte_offset->IsUndefined(isolate)) { |
2955 // We intentionally violate the specification at this point to allow | 2956 // We intentionally violate the specification at this point to allow |
2956 // for new DataView(buffer) invocations to be equivalent to the full | 2957 // for new DataView(buffer) invocations to be equivalent to the full |
2957 // new DataView(buffer, 0) invocation. | 2958 // new DataView(buffer, 0) invocation. |
2958 number_offset = handle(Smi::FromInt(0), isolate); | 2959 number_offset = handle(Smi::FromInt(0), isolate); |
2959 } else { | 2960 } else { |
2960 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_offset, | 2961 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_offset, |
2961 Object::ToNumber(byte_offset)); | 2962 Object::ToNumber(byte_offset)); |
2962 } | 2963 } |
2963 | 2964 |
2964 // 5. Let offset be ToInteger(numberOffset). | 2965 // 5. Let offset be ToInteger(numberOffset). |
(...skipping 14 matching lines...) Expand all Loading... |
2979 // internal slot. | 2980 // internal slot. |
2980 double const buffer_byte_length = array_buffer->byte_length()->Number(); | 2981 double const buffer_byte_length = array_buffer->byte_length()->Number(); |
2981 | 2982 |
2982 // 9. If offset > bufferByteLength, throw a RangeError exception | 2983 // 9. If offset > bufferByteLength, throw a RangeError exception |
2983 if (offset->Number() > buffer_byte_length) { | 2984 if (offset->Number() > buffer_byte_length) { |
2984 THROW_NEW_ERROR_RETURN_FAILURE( | 2985 THROW_NEW_ERROR_RETURN_FAILURE( |
2985 isolate, NewRangeError(MessageTemplate::kInvalidDataViewOffset)); | 2986 isolate, NewRangeError(MessageTemplate::kInvalidDataViewOffset)); |
2986 } | 2987 } |
2987 | 2988 |
2988 Handle<Object> view_byte_length; | 2989 Handle<Object> view_byte_length; |
2989 if (byte_length->IsUndefined()) { | 2990 if (byte_length->IsUndefined(isolate)) { |
2990 // 10. If byteLength is undefined, then | 2991 // 10. If byteLength is undefined, then |
2991 // a. Let viewByteLength be bufferByteLength - offset. | 2992 // a. Let viewByteLength be bufferByteLength - offset. |
2992 view_byte_length = | 2993 view_byte_length = |
2993 isolate->factory()->NewNumber(buffer_byte_length - offset->Number()); | 2994 isolate->factory()->NewNumber(buffer_byte_length - offset->Number()); |
2994 } else { | 2995 } else { |
2995 // 11. Else, | 2996 // 11. Else, |
2996 // a. Let viewByteLength be ? ToLength(byteLength). | 2997 // a. Let viewByteLength be ? ToLength(byteLength). |
2997 // b. If offset+viewByteLength > bufferByteLength, throw a RangeError | 2998 // b. If offset+viewByteLength > bufferByteLength, throw a RangeError |
2998 // exception | 2999 // exception |
2999 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3000 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4163 function->shared()->set_name_should_print_as_anonymous(true); | 4164 function->shared()->set_name_should_print_as_anonymous(true); |
4164 } | 4165 } |
4165 | 4166 |
4166 // If new.target is equal to target then the function created | 4167 // If new.target is equal to target then the function created |
4167 // is already correctly setup and nothing else should be done | 4168 // is already correctly setup and nothing else should be done |
4168 // here. But if new.target is not equal to target then we are | 4169 // here. But if new.target is not equal to target then we are |
4169 // have a Function builtin subclassing case and therefore the | 4170 // have a Function builtin subclassing case and therefore the |
4170 // function has wrong initial map. To fix that we create a new | 4171 // function has wrong initial map. To fix that we create a new |
4171 // function object with correct initial map. | 4172 // function object with correct initial map. |
4172 Handle<Object> unchecked_new_target = args.new_target(); | 4173 Handle<Object> unchecked_new_target = args.new_target(); |
4173 if (!unchecked_new_target->IsUndefined() && | 4174 if (!unchecked_new_target->IsUndefined(isolate) && |
4174 !unchecked_new_target.is_identical_to(target)) { | 4175 !unchecked_new_target.is_identical_to(target)) { |
4175 Handle<JSReceiver> new_target = | 4176 Handle<JSReceiver> new_target = |
4176 Handle<JSReceiver>::cast(unchecked_new_target); | 4177 Handle<JSReceiver>::cast(unchecked_new_target); |
4177 Handle<Map> initial_map; | 4178 Handle<Map> initial_map; |
4178 ASSIGN_RETURN_ON_EXCEPTION( | 4179 ASSIGN_RETURN_ON_EXCEPTION( |
4179 isolate, initial_map, | 4180 isolate, initial_map, |
4180 JSFunction::GetDerivedMap(isolate, target, new_target), JSFunction); | 4181 JSFunction::GetDerivedMap(isolate, target, new_target), JSFunction); |
4181 | 4182 |
4182 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate); | 4183 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate); |
4183 Handle<Map> map = Map::AsLanguageMode( | 4184 Handle<Map> map = Map::AsLanguageMode( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4315 HandleScope scope(isolate); | 4316 HandleScope scope(isolate); |
4316 RETURN_RESULT_OR_FAILURE( | 4317 RETURN_RESULT_OR_FAILURE( |
4317 isolate, CreateDynamicFunction(isolate, args, "async function")); | 4318 isolate, CreateDynamicFunction(isolate, args, "async function")); |
4318 } | 4319 } |
4319 | 4320 |
4320 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. | 4321 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. |
4321 BUILTIN(SymbolConstructor) { | 4322 BUILTIN(SymbolConstructor) { |
4322 HandleScope scope(isolate); | 4323 HandleScope scope(isolate); |
4323 Handle<Symbol> result = isolate->factory()->NewSymbol(); | 4324 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
4324 Handle<Object> description = args.atOrUndefined(isolate, 1); | 4325 Handle<Object> description = args.atOrUndefined(isolate, 1); |
4325 if (!description->IsUndefined()) { | 4326 if (!description->IsUndefined(isolate)) { |
4326 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, | 4327 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
4327 Object::ToString(isolate, description)); | 4328 Object::ToString(isolate, description)); |
4328 result->set_name(*description); | 4329 result->set_name(*description); |
4329 } | 4330 } |
4330 return *result; | 4331 return *result; |
4331 } | 4332 } |
4332 | 4333 |
4333 | 4334 |
4334 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. | 4335 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. |
4335 BUILTIN(SymbolConstructor_ConstructStub) { | 4336 BUILTIN(SymbolConstructor_ConstructStub) { |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4851 | 4852 |
4852 | 4853 |
4853 namespace { | 4854 namespace { |
4854 | 4855 |
4855 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( | 4856 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
4856 Isolate* isolate, | 4857 Isolate* isolate, |
4857 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget> args) { | 4858 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget> args) { |
4858 HandleScope scope(isolate); | 4859 HandleScope scope(isolate); |
4859 Handle<HeapObject> function = args.target<HeapObject>(); | 4860 Handle<HeapObject> function = args.target<HeapObject>(); |
4860 Handle<HeapObject> new_target = args.new_target(); | 4861 Handle<HeapObject> new_target = args.new_target(); |
4861 bool is_construct = !new_target->IsUndefined(); | 4862 bool is_construct = !new_target->IsUndefined(isolate); |
4862 Handle<JSReceiver> receiver; | 4863 Handle<JSReceiver> receiver; |
4863 | 4864 |
4864 DCHECK(function->IsFunctionTemplateInfo() || | 4865 DCHECK(function->IsFunctionTemplateInfo() || |
4865 Handle<JSFunction>::cast(function)->shared()->IsApiFunction()); | 4866 Handle<JSFunction>::cast(function)->shared()->IsApiFunction()); |
4866 | 4867 |
4867 Handle<FunctionTemplateInfo> fun_data = | 4868 Handle<FunctionTemplateInfo> fun_data = |
4868 function->IsFunctionTemplateInfo() | 4869 function->IsFunctionTemplateInfo() |
4869 ? Handle<FunctionTemplateInfo>::cast(function) | 4870 ? Handle<FunctionTemplateInfo>::cast(function) |
4870 : handle(JSFunction::cast(*function)->shared()->get_api_func_data()); | 4871 : handle(JSFunction::cast(*function)->shared()->get_api_func_data()); |
4871 if (is_construct) { | 4872 if (is_construct) { |
4872 DCHECK(args.receiver()->IsTheHole()); | 4873 DCHECK(args.receiver()->IsTheHole(isolate)); |
4873 if (fun_data->instance_template()->IsUndefined()) { | 4874 if (fun_data->instance_template()->IsUndefined(isolate)) { |
4874 v8::Local<ObjectTemplate> templ = | 4875 v8::Local<ObjectTemplate> templ = |
4875 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), | 4876 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), |
4876 ToApiHandle<v8::FunctionTemplate>(fun_data)); | 4877 ToApiHandle<v8::FunctionTemplate>(fun_data)); |
4877 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); | 4878 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); |
4878 } | 4879 } |
4879 Handle<ObjectTemplateInfo> instance_template( | 4880 Handle<ObjectTemplateInfo> instance_template( |
4880 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); | 4881 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); |
4881 ASSIGN_RETURN_ON_EXCEPTION( | 4882 ASSIGN_RETURN_ON_EXCEPTION( |
4882 isolate, receiver, | 4883 isolate, receiver, |
4883 ApiNatives::InstantiateObject(instance_template, | 4884 ApiNatives::InstantiateObject(instance_template, |
(...skipping 18 matching lines...) Expand all Loading... |
4902 | 4903 |
4903 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, *receiver); | 4904 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, *receiver); |
4904 | 4905 |
4905 if (raw_holder->IsNull()) { | 4906 if (raw_holder->IsNull()) { |
4906 // This function cannot be called with the given receiver. Abort! | 4907 // This function cannot be called with the given receiver. Abort! |
4907 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), | 4908 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), |
4908 Object); | 4909 Object); |
4909 } | 4910 } |
4910 | 4911 |
4911 Object* raw_call_data = fun_data->call_code(); | 4912 Object* raw_call_data = fun_data->call_code(); |
4912 if (!raw_call_data->IsUndefined()) { | 4913 if (!raw_call_data->IsUndefined(isolate)) { |
4913 DCHECK(raw_call_data->IsCallHandlerInfo()); | 4914 DCHECK(raw_call_data->IsCallHandlerInfo()); |
4914 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); | 4915 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); |
4915 Object* callback_obj = call_data->callback(); | 4916 Object* callback_obj = call_data->callback(); |
4916 v8::FunctionCallback callback = | 4917 v8::FunctionCallback callback = |
4917 v8::ToCData<v8::FunctionCallback>(callback_obj); | 4918 v8::ToCData<v8::FunctionCallback>(callback_obj); |
4918 Object* data_obj = call_data->data(); | 4919 Object* data_obj = call_data->data(); |
4919 | 4920 |
4920 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver()))); | 4921 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver()))); |
4921 DCHECK(raw_holder->IsJSObject()); | 4922 DCHECK(raw_holder->IsJSObject()); |
4922 | 4923 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5112 } | 5113 } |
5113 | 5114 |
5114 // Get the invocation callback from the function descriptor that was | 5115 // Get the invocation callback from the function descriptor that was |
5115 // used to create the called object. | 5116 // used to create the called object. |
5116 DCHECK(obj->map()->is_callable()); | 5117 DCHECK(obj->map()->is_callable()); |
5117 JSFunction* constructor = JSFunction::cast(obj->map()->GetConstructor()); | 5118 JSFunction* constructor = JSFunction::cast(obj->map()->GetConstructor()); |
5118 // TODO(ishell): turn this back to a DCHECK. | 5119 // TODO(ishell): turn this back to a DCHECK. |
5119 CHECK(constructor->shared()->IsApiFunction()); | 5120 CHECK(constructor->shared()->IsApiFunction()); |
5120 Object* handler = | 5121 Object* handler = |
5121 constructor->shared()->get_api_func_data()->instance_call_handler(); | 5122 constructor->shared()->get_api_func_data()->instance_call_handler(); |
5122 DCHECK(!handler->IsUndefined()); | 5123 DCHECK(!handler->IsUndefined(isolate)); |
5123 // TODO(ishell): remove this debugging code. | 5124 // TODO(ishell): remove this debugging code. |
5124 CHECK(handler->IsCallHandlerInfo()); | 5125 CHECK(handler->IsCallHandlerInfo()); |
5125 CallHandlerInfo* call_data = CallHandlerInfo::cast(handler); | 5126 CallHandlerInfo* call_data = CallHandlerInfo::cast(handler); |
5126 Object* callback_obj = call_data->callback(); | 5127 Object* callback_obj = call_data->callback(); |
5127 v8::FunctionCallback callback = | 5128 v8::FunctionCallback callback = |
5128 v8::ToCData<v8::FunctionCallback>(callback_obj); | 5129 v8::ToCData<v8::FunctionCallback>(callback_obj); |
5129 | 5130 |
5130 // Get the data for the call and perform the callback. | 5131 // Get the data for the call and perform the callback. |
5131 Object* result; | 5132 Object* result; |
5132 { | 5133 { |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5771 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5772 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5772 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5773 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5773 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5774 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5774 #undef DEFINE_BUILTIN_ACCESSOR_C | 5775 #undef DEFINE_BUILTIN_ACCESSOR_C |
5775 #undef DEFINE_BUILTIN_ACCESSOR_A | 5776 #undef DEFINE_BUILTIN_ACCESSOR_A |
5776 #undef DEFINE_BUILTIN_ACCESSOR_T | 5777 #undef DEFINE_BUILTIN_ACCESSOR_T |
5777 #undef DEFINE_BUILTIN_ACCESSOR_H | 5778 #undef DEFINE_BUILTIN_ACCESSOR_H |
5778 | 5779 |
5779 } // namespace internal | 5780 } // namespace internal |
5780 } // namespace v8 | 5781 } // namespace v8 |
OLD | NEW |