OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 } | 864 } |
865 array_buffer->Neuter(); | 865 array_buffer->Neuter(); |
866 } | 866 } |
867 | 867 |
868 | 868 |
869 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { | 869 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { |
870 HandleScope scope(isolate); | 870 HandleScope scope(isolate); |
871 ASSERT(args.length() == 2); | 871 ASSERT(args.length() == 2); |
872 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | 872 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); |
873 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); | 873 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); |
874 if (!holder->byte_length()->IsUndefined()) { | |
875 // ArrayBuffer is already initialized; probably a fuzz test. | |
876 return *holder; | |
877 } | |
874 size_t allocated_length = 0; | 878 size_t allocated_length = 0; |
875 if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) { | 879 if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) { |
876 return isolate->Throw( | 880 return isolate->Throw( |
877 *isolate->factory()->NewRangeError("invalid_array_buffer_length", | 881 *isolate->factory()->NewRangeError("invalid_array_buffer_length", |
878 HandleVector<Object>(NULL, 0))); | 882 HandleVector<Object>(NULL, 0))); |
879 } | 883 } |
880 if (!Runtime::SetupArrayBufferAllocatingData(isolate, | 884 if (!Runtime::SetupArrayBufferAllocatingData(isolate, |
881 holder, allocated_length)) { | 885 holder, allocated_length)) { |
882 return isolate->Throw( | 886 return isolate->Throw( |
883 *isolate->factory()->NewRangeError("invalid_array_buffer_length", | 887 *isolate->factory()->NewRangeError("invalid_array_buffer_length", |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1048 // If an array-like object happens to be a typed array of the same type, | 1052 // If an array-like object happens to be a typed array of the same type, |
1049 // initializes backing store using memove. | 1053 // initializes backing store using memove. |
1050 // | 1054 // |
1051 // Returns true if backing store was initialized or false otherwise. | 1055 // Returns true if backing store was initialized or false otherwise. |
1052 RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { | 1056 RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { |
1053 HandleScope scope(isolate); | 1057 HandleScope scope(isolate); |
1054 ASSERT(args.length() == 4); | 1058 ASSERT(args.length() == 4); |
1055 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 1059 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); |
1056 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 1060 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
1057 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); | 1061 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); |
1058 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3); | 1062 CONVERT_NUMBER_ARG_HANDLE_CHECKED(length_obj, 3); |
1059 | 1063 |
1060 ASSERT(holder->GetInternalFieldCount() == | 1064 ASSERT(holder->GetInternalFieldCount() == |
1061 v8::ArrayBufferView::kInternalFieldCount); | 1065 v8::ArrayBufferView::kInternalFieldCount); |
1062 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 1066 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
1063 holder->SetInternalField(i, Smi::FromInt(0)); | 1067 holder->SetInternalField(i, Smi::FromInt(0)); |
1064 } | 1068 } |
1065 | 1069 |
1066 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. | 1070 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. |
1067 size_t element_size = 1; // Bogus initialization. | 1071 size_t element_size = 1; // Bogus initialization. |
1068 ElementsKind external_elements_kind = | 1072 ElementsKind external_elements_kind = |
1069 EXTERNAL_INT8_ELEMENTS; // Bogus intialization. | 1073 EXTERNAL_INT8_ELEMENTS; // Bogus intialization. |
1070 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. | 1074 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. |
1071 Runtime::ArrayIdToTypeAndSize(arrayId, | 1075 Runtime::ArrayIdToTypeAndSize(arrayId, |
1072 &array_type, | 1076 &array_type, |
1073 &external_elements_kind, | 1077 &external_elements_kind, |
1074 &fixed_elements_kind, | 1078 &fixed_elements_kind, |
1075 &element_size); | 1079 &element_size); |
1076 | 1080 |
1077 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 1081 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
1078 if (source->IsJSTypedArray() && | 1082 if (source->IsJSTypedArray() && |
1079 JSTypedArray::cast(*source)->type() == array_type) { | 1083 JSTypedArray::cast(*source)->type() == array_type) { |
1080 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate); | 1084 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate); |
1081 } | 1085 } |
1082 size_t length = NumberToSize(isolate, *length_obj); | 1086 size_t length = 0; |
1087 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length)); | |
1083 | 1088 |
1084 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || | 1089 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || |
1085 (length > (kMaxInt / element_size))) { | 1090 (length > (kMaxInt / element_size))) { |
1086 return isolate->Throw(*isolate->factory()-> | 1091 return isolate->Throw(*isolate->factory()-> |
1087 NewRangeError("invalid_typed_array_length", | 1092 NewRangeError("invalid_typed_array_length", |
1088 HandleVector<Object>(NULL, 0))); | 1093 HandleVector<Object>(NULL, 0))); |
1089 } | 1094 } |
1090 size_t byte_length = length * element_size; | 1095 size_t byte_length = length * element_size; |
1091 | 1096 |
1092 // NOTE: not initializing backing store. | 1097 // NOTE: not initializing backing store. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 // Set from typed array of the different type, non-overlapping. | 1189 // Set from typed array of the different type, non-overlapping. |
1185 TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING = 2, | 1190 TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING = 2, |
1186 // Set from non-typed array. | 1191 // Set from non-typed array. |
1187 TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3 | 1192 TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3 |
1188 }; | 1193 }; |
1189 | 1194 |
1190 | 1195 |
1191 RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { | 1196 RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { |
1192 HandleScope scope(isolate); | 1197 HandleScope scope(isolate); |
1193 ASSERT(args.length() == 3); | 1198 ASSERT(args.length() == 3); |
1194 CONVERT_ARG_HANDLE_CHECKED(Object, target_obj, 0); | 1199 if (!args[0]->IsJSTypedArray()) |
1195 CONVERT_ARG_HANDLE_CHECKED(Object, source_obj, 1); | |
1196 CONVERT_ARG_HANDLE_CHECKED(Object, offset_obj, 2); | |
1197 | |
1198 if (!target_obj->IsJSTypedArray()) | |
1199 return isolate->Throw(*isolate->factory()->NewTypeError( | 1200 return isolate->Throw(*isolate->factory()->NewTypeError( |
1200 "not_typed_array", HandleVector<Object>(NULL, 0))); | 1201 "not_typed_array", HandleVector<Object>(NULL, 0))); |
1201 | 1202 |
1202 if (!source_obj->IsJSTypedArray()) | 1203 if (!args[1]->IsJSTypedArray()) |
1203 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); | 1204 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); |
1204 | 1205 |
1206 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); | |
1207 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); | |
1208 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2); | |
1209 | |
1205 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); | 1210 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); |
1206 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); | 1211 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); |
1207 size_t offset = NumberToSize(isolate, *offset_obj); | 1212 size_t offset = NumberToSize(isolate, *offset_obj); |
1208 size_t target_length = NumberToSize(isolate, target->length()); | 1213 size_t target_length = NumberToSize(isolate, target->length()); |
1209 size_t source_length = NumberToSize(isolate, source->length()); | 1214 size_t source_length = NumberToSize(isolate, source->length()); |
1210 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); | 1215 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); |
1211 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); | 1216 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); |
1212 if (offset > target_length || | 1217 if (offset > target_length || |
1213 offset + source_length > target_length || | 1218 offset + source_length > target_length || |
1214 offset + source_length < offset) // overflow | 1219 offset + source_length < offset) // overflow |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 FLAG_typed_array_max_size_in_heap + FixedTypedArrayBase::kDataOffset); | 1258 FLAG_typed_array_max_size_in_heap + FixedTypedArrayBase::kDataOffset); |
1254 return Smi::FromInt(FLAG_typed_array_max_size_in_heap); | 1259 return Smi::FromInt(FLAG_typed_array_max_size_in_heap); |
1255 } | 1260 } |
1256 | 1261 |
1257 | 1262 |
1258 RUNTIME_FUNCTION(Runtime_DataViewInitialize) { | 1263 RUNTIME_FUNCTION(Runtime_DataViewInitialize) { |
1259 HandleScope scope(isolate); | 1264 HandleScope scope(isolate); |
1260 ASSERT(args.length() == 4); | 1265 ASSERT(args.length() == 4); |
1261 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); | 1266 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); |
1262 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); | 1267 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); |
1263 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2); | 1268 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset, 2); |
1264 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3); | 1269 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length, 3); |
1265 | 1270 |
1266 ASSERT(holder->GetInternalFieldCount() == | 1271 ASSERT(holder->GetInternalFieldCount() == |
1267 v8::ArrayBufferView::kInternalFieldCount); | 1272 v8::ArrayBufferView::kInternalFieldCount); |
1268 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 1273 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
1269 holder->SetInternalField(i, Smi::FromInt(0)); | 1274 holder->SetInternalField(i, Smi::FromInt(0)); |
1270 } | 1275 } |
1276 size_t buffer_length = 0; | |
1277 size_t offset = 0; | |
1278 size_t length = 0; | |
1279 RUNTIME_ASSERT( | |
1280 TryNumberToSize(isolate, buffer->byte_length(), &buffer_length)); | |
1281 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_offset, &offset)); | |
1282 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_length, &length)); | |
1283 RUNTIME_ASSERT(buffer_length - length >= offset); | |
Dmitry Lomov (no reviews)
2014/04/24 09:24:59
Add buffer_length >= length here
Jakob Kummerow
2014/04/24 10:58:27
Done.
| |
1271 | 1284 |
1272 holder->set_buffer(*buffer); | 1285 holder->set_buffer(*buffer); |
1273 ASSERT(byte_offset->IsNumber()); | |
1274 ASSERT( | |
1275 NumberToSize(isolate, buffer->byte_length()) >= | |
1276 NumberToSize(isolate, *byte_offset) | |
1277 + NumberToSize(isolate, *byte_length)); | |
1278 holder->set_byte_offset(*byte_offset); | 1286 holder->set_byte_offset(*byte_offset); |
1279 ASSERT(byte_length->IsNumber()); | |
1280 holder->set_byte_length(*byte_length); | 1287 holder->set_byte_length(*byte_length); |
1281 | 1288 |
1282 holder->set_weak_next(buffer->weak_first_view()); | 1289 holder->set_weak_next(buffer->weak_first_view()); |
1283 buffer->set_weak_first_view(*holder); | 1290 buffer->set_weak_first_view(*holder); |
1284 | 1291 |
1285 return isolate->heap()->undefined_value(); | 1292 return isolate->heap()->undefined_value(); |
1286 } | 1293 } |
1287 | 1294 |
1288 | 1295 |
1289 inline static bool NeedToFlipBytes(bool is_little_endian) { | 1296 inline static bool NeedToFlipBytes(bool is_little_endian) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1575 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); | 1582 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); |
1576 return Smi::FromInt(table->NumberOfElements()); | 1583 return Smi::FromInt(table->NumberOfElements()); |
1577 } | 1584 } |
1578 | 1585 |
1579 | 1586 |
1580 RUNTIME_FUNCTION(Runtime_SetCreateIterator) { | 1587 RUNTIME_FUNCTION(Runtime_SetCreateIterator) { |
1581 HandleScope scope(isolate); | 1588 HandleScope scope(isolate); |
1582 ASSERT(args.length() == 2); | 1589 ASSERT(args.length() == 2); |
1583 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 1590 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
1584 CONVERT_SMI_ARG_CHECKED(kind, 1) | 1591 CONVERT_SMI_ARG_CHECKED(kind, 1) |
1585 ASSERT(kind == JSSetIterator::kKindValues | 1592 RUNTIME_ASSERT(kind == JSSetIterator::kKindValues || |
1586 || kind == JSSetIterator::kKindEntries); | 1593 kind == JSSetIterator::kKindEntries); |
1587 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); | 1594 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); |
1588 return *JSSetIterator::Create(table, kind); | 1595 return *JSSetIterator::Create(table, kind); |
1589 } | 1596 } |
1590 | 1597 |
1591 | 1598 |
1592 RUNTIME_FUNCTION(Runtime_SetIteratorNext) { | 1599 RUNTIME_FUNCTION(Runtime_SetIteratorNext) { |
1593 HandleScope scope(isolate); | 1600 HandleScope scope(isolate); |
1594 ASSERT(args.length() == 1); | 1601 ASSERT(args.length() == 1); |
1595 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); | 1602 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); |
1596 return *JSSetIterator::Next(holder); | 1603 return *JSSetIterator::Next(holder); |
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3090 CONVERT_ARG_CHECKED(JSFunction, f, 0); | 3097 CONVERT_ARG_CHECKED(JSFunction, f, 0); |
3091 return isolate->heap()->ToBoolean(f->IsBuiltin()); | 3098 return isolate->heap()->ToBoolean(f->IsBuiltin()); |
3092 } | 3099 } |
3093 | 3100 |
3094 | 3101 |
3095 RUNTIME_FUNCTION(Runtime_SetCode) { | 3102 RUNTIME_FUNCTION(Runtime_SetCode) { |
3096 HandleScope scope(isolate); | 3103 HandleScope scope(isolate); |
3097 ASSERT(args.length() == 2); | 3104 ASSERT(args.length() == 2); |
3098 | 3105 |
3099 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0); | 3106 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0); |
3100 CONVERT_ARG_HANDLE_CHECKED(Object, code, 1); | 3107 CONVERT_ARG_HANDLE_CHECKED(JSFunction, source, 1); |
3101 | 3108 |
3102 if (code->IsNull()) return *target; | |
3103 RUNTIME_ASSERT(code->IsJSFunction()); | |
3104 Handle<JSFunction> source = Handle<JSFunction>::cast(code); | |
3105 Handle<SharedFunctionInfo> target_shared(target->shared()); | 3109 Handle<SharedFunctionInfo> target_shared(target->shared()); |
3106 Handle<SharedFunctionInfo> source_shared(source->shared()); | 3110 Handle<SharedFunctionInfo> source_shared(source->shared()); |
3107 | 3111 |
3108 if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) { | 3112 if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) { |
3109 return isolate->heap()->exception(); | 3113 return isolate->heap()->exception(); |
3110 } | 3114 } |
3111 | 3115 |
3112 // Mark both, the source and the target, as un-flushable because the | 3116 // Mark both, the source and the target, as un-flushable because the |
3113 // shared unoptimized code makes them impossible to enqueue in a list. | 3117 // shared unoptimized code makes them impossible to enqueue in a list. |
3114 ASSERT(target_shared->code()->gc_metadata() == NULL); | 3118 ASSERT(target_shared->code()->gc_metadata() == NULL); |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4289 | 4293 |
4290 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { | 4294 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { |
4291 HandleScope scope(isolate); | 4295 HandleScope scope(isolate); |
4292 ASSERT(args.length() == 4); | 4296 ASSERT(args.length() == 4); |
4293 | 4297 |
4294 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 4298 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
4295 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); | 4299 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
4296 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 4300 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
4297 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); | 4301 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); |
4298 | 4302 |
4299 ASSERT(regexp->GetFlags().is_global()); | 4303 RUNTIME_ASSERT(regexp->GetFlags().is_global()); |
4300 | 4304 |
4301 subject = String::Flatten(subject); | 4305 subject = String::Flatten(subject); |
4302 | 4306 |
4303 if (replacement->length() == 0) { | 4307 if (replacement->length() == 0) { |
4304 if (subject->HasOnlyOneByteChars()) { | 4308 if (subject->HasOnlyOneByteChars()) { |
4305 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( | 4309 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( |
4306 isolate, subject, regexp, last_match_info); | 4310 isolate, subject, regexp, last_match_info); |
4307 } else { | 4311 } else { |
4308 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( | 4312 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( |
4309 isolate, subject, regexp, last_match_info); | 4313 isolate, subject, regexp, last_match_info); |
(...skipping 2914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7224 | 7228 |
7225 | 7229 |
7226 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { | 7230 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { |
7227 HandleScope scope(isolate); | 7231 HandleScope scope(isolate); |
7228 ASSERT(args.length() == 3); | 7232 ASSERT(args.length() == 3); |
7229 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); | 7233 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); |
7230 if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength(); | 7234 if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength(); |
7231 CONVERT_SMI_ARG_CHECKED(array_length, 1); | 7235 CONVERT_SMI_ARG_CHECKED(array_length, 1); |
7232 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); | 7236 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); |
7233 | 7237 |
7238 size_t actual_array_length = 0; | |
7239 RUNTIME_ASSERT( | |
7240 TryNumberToSize(isolate, array->length(), &actual_array_length)); | |
7241 RUNTIME_ASSERT(array_length >= 0); | |
7242 RUNTIME_ASSERT(static_cast<size_t>(array_length) <= actual_array_length); | |
7243 | |
7234 // This assumption is used by the slice encoding in one or two smis. | 7244 // This assumption is used by the slice encoding in one or two smis. |
7235 ASSERT(Smi::kMaxValue >= String::kMaxLength); | 7245 ASSERT(Smi::kMaxValue >= String::kMaxLength); |
7236 | 7246 |
7237 JSObject::EnsureCanContainHeapObjectElements(array); | 7247 JSObject::EnsureCanContainHeapObjectElements(array); |
7238 | 7248 |
7239 int special_length = special->length(); | 7249 int special_length = special->length(); |
7240 if (!array->HasFastObjectElements()) { | 7250 if (!array->HasFastObjectElements()) { |
7241 return isolate->Throw(isolate->heap()->illegal_argument_string()); | 7251 return isolate->Throw(isolate->heap()->illegal_argument_string()); |
7242 } | 7252 } |
7243 | 7253 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7592 return Smi::FromInt(not_equal); | 7602 return Smi::FromInt(not_equal); |
7593 } | 7603 } |
7594 | 7604 |
7595 | 7605 |
7596 RUNTIME_FUNCTION(Runtime_NumberCompare) { | 7606 RUNTIME_FUNCTION(Runtime_NumberCompare) { |
7597 SealHandleScope shs(isolate); | 7607 SealHandleScope shs(isolate); |
7598 ASSERT(args.length() == 3); | 7608 ASSERT(args.length() == 3); |
7599 | 7609 |
7600 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7610 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
7601 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7611 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
7602 if (std::isnan(x) || std::isnan(y)) return args[2]; | 7612 CONVERT_ARG_HANDLE_CHECKED(Object, uncomparable_result, 2) |
7613 if (std::isnan(x) || std::isnan(y)) return *uncomparable_result; | |
7603 if (x == y) return Smi::FromInt(EQUAL); | 7614 if (x == y) return Smi::FromInt(EQUAL); |
7604 if (isless(x, y)) return Smi::FromInt(LESS); | 7615 if (isless(x, y)) return Smi::FromInt(LESS); |
7605 return Smi::FromInt(GREATER); | 7616 return Smi::FromInt(GREATER); |
7606 } | 7617 } |
7607 | 7618 |
7608 | 7619 |
7609 // Compare two Smis as if they were converted to strings and then | 7620 // Compare two Smis as if they were converted to strings and then |
7610 // compared lexicographically. | 7621 // compared lexicographically. |
7611 RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) { | 7622 RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) { |
7612 SealHandleScope shs(isolate); | 7623 SealHandleScope shs(isolate); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7880 double result = power_double_double(x, y); | 7891 double result = power_double_double(x, y); |
7881 if (std::isnan(result)) return isolate->heap()->nan_value(); | 7892 if (std::isnan(result)) return isolate->heap()->nan_value(); |
7882 return *isolate->factory()->NewNumber(result); | 7893 return *isolate->factory()->NewNumber(result); |
7883 } | 7894 } |
7884 } | 7895 } |
7885 | 7896 |
7886 | 7897 |
7887 RUNTIME_FUNCTION(Runtime_RoundNumber) { | 7898 RUNTIME_FUNCTION(Runtime_RoundNumber) { |
7888 HandleScope scope(isolate); | 7899 HandleScope scope(isolate); |
7889 ASSERT(args.length() == 1); | 7900 ASSERT(args.length() == 1); |
7901 CONVERT_NUMBER_ARG_HANDLE_CHECKED(input, 0); | |
7890 isolate->counters()->math_round()->Increment(); | 7902 isolate->counters()->math_round()->Increment(); |
7891 | 7903 |
7892 if (!args[0]->IsHeapNumber()) { | 7904 if (!input->IsHeapNumber()) { |
7893 // Must be smi. Return the argument unchanged for all the other types | 7905 ASSERT(input->IsSmi()); |
7894 // to make fuzz-natives test happy. | 7906 return *input; |
7895 return args[0]; | |
7896 } | 7907 } |
7897 | 7908 |
7898 HeapNumber* number = reinterpret_cast<HeapNumber*>(args[0]); | 7909 Handle<HeapNumber> number = Handle<HeapNumber>::cast(input); |
7899 | 7910 |
7900 double value = number->value(); | 7911 double value = number->value(); |
7901 int exponent = number->get_exponent(); | 7912 int exponent = number->get_exponent(); |
7902 int sign = number->get_sign(); | 7913 int sign = number->get_sign(); |
7903 | 7914 |
7904 if (exponent < -1) { | 7915 if (exponent < -1) { |
7905 // Number in range ]-0.5..0.5[. These always round to +/-zero. | 7916 // Number in range ]-0.5..0.5[. These always round to +/-zero. |
7906 if (sign) return isolate->heap()->minus_zero_value(); | 7917 if (sign) return isolate->heap()->minus_zero_value(); |
7907 return Smi::FromInt(0); | 7918 return Smi::FromInt(0); |
7908 } | 7919 } |
7909 | 7920 |
7910 // We compare with kSmiValueSize - 2 because (2^30 - 0.1) has exponent 29 and | 7921 // We compare with kSmiValueSize - 2 because (2^30 - 0.1) has exponent 29 and |
7911 // should be rounded to 2^30, which is not smi (for 31-bit smis, similar | 7922 // should be rounded to 2^30, which is not smi (for 31-bit smis, similar |
7912 // argument holds for 32-bit smis). | 7923 // argument holds for 32-bit smis). |
7913 if (!sign && exponent < kSmiValueSize - 2) { | 7924 if (!sign && exponent < kSmiValueSize - 2) { |
7914 return Smi::FromInt(static_cast<int>(value + 0.5)); | 7925 return Smi::FromInt(static_cast<int>(value + 0.5)); |
7915 } | 7926 } |
7916 | 7927 |
7917 // If the magnitude is big enough, there's no place for fraction part. If we | 7928 // If the magnitude is big enough, there's no place for fraction part. If we |
7918 // try to add 0.5 to this number, 1.0 will be added instead. | 7929 // try to add 0.5 to this number, 1.0 will be added instead. |
7919 if (exponent >= 52) { | 7930 if (exponent >= 52) { |
7920 return number; | 7931 return *number; |
7921 } | 7932 } |
7922 | 7933 |
7923 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); | 7934 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); |
7924 | 7935 |
7925 // Do not call NumberFromDouble() to avoid extra checks. | 7936 // Do not call NumberFromDouble() to avoid extra checks. |
7926 return *isolate->factory()->NewNumber(std::floor(value + 0.5)); | 7937 return *isolate->factory()->NewNumber(std::floor(value + 0.5)); |
7927 } | 7938 } |
7928 | 7939 |
7929 | 7940 |
7930 RUNTIME_FUNCTION(Runtime_MathSqrt) { | 7941 RUNTIME_FUNCTION(Runtime_MathSqrt) { |
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9659 | 9670 |
9660 | 9671 |
9661 RUNTIME_FUNCTION(Runtime_DateParseString) { | 9672 RUNTIME_FUNCTION(Runtime_DateParseString) { |
9662 HandleScope scope(isolate); | 9673 HandleScope scope(isolate); |
9663 ASSERT(args.length() == 2); | 9674 ASSERT(args.length() == 2); |
9664 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); | 9675 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); |
9665 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); | 9676 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); |
9666 | 9677 |
9667 JSObject::EnsureCanContainHeapObjectElements(output); | 9678 JSObject::EnsureCanContainHeapObjectElements(output); |
9668 RUNTIME_ASSERT(output->HasFastObjectElements()); | 9679 RUNTIME_ASSERT(output->HasFastObjectElements()); |
9680 FixedArray* output_array = FixedArray::cast(output->elements()); | |
Dmitry Lomov (no reviews)
2014/04/24 09:24:59
nit: use handle here since this is now out of Disa
Jakob Kummerow
2014/04/24 10:58:27
Done.
| |
9681 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); | |
9669 | 9682 |
9670 str = String::Flatten(str); | 9683 str = String::Flatten(str); |
9671 DisallowHeapAllocation no_gc; | 9684 DisallowHeapAllocation no_gc; |
9672 | 9685 |
9673 FixedArray* output_array = FixedArray::cast(output->elements()); | |
9674 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); | |
9675 bool result; | 9686 bool result; |
9676 String::FlatContent str_content = str->GetFlatContent(); | 9687 String::FlatContent str_content = str->GetFlatContent(); |
9677 if (str_content.IsAscii()) { | 9688 if (str_content.IsAscii()) { |
9678 result = DateParser::Parse(str_content.ToOneByteVector(), | 9689 result = DateParser::Parse(str_content.ToOneByteVector(), |
9679 output_array, | 9690 output_array, |
9680 isolate->unicode_cache()); | 9691 isolate->unicode_cache()); |
9681 } else { | 9692 } else { |
9682 ASSERT(str_content.IsTwoByte()); | 9693 ASSERT(str_content.IsTwoByte()); |
9683 result = DateParser::Parse(str_content.ToUC16Vector(), | 9694 result = DateParser::Parse(str_content.ToUC16Vector(), |
9684 output_array, | 9695 output_array, |
(...skipping 3781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13466 // In a code of a parent function replaces original function as embedded object | 13477 // In a code of a parent function replaces original function as embedded object |
13467 // with a substitution one. | 13478 // with a substitution one. |
13468 RUNTIME_FUNCTION(Runtime_LiveEditReplaceRefToNestedFunction) { | 13479 RUNTIME_FUNCTION(Runtime_LiveEditReplaceRefToNestedFunction) { |
13469 HandleScope scope(isolate); | 13480 HandleScope scope(isolate); |
13470 CHECK(isolate->debugger()->live_edit_enabled()); | 13481 CHECK(isolate->debugger()->live_edit_enabled()); |
13471 ASSERT(args.length() == 3); | 13482 ASSERT(args.length() == 3); |
13472 | 13483 |
13473 CONVERT_ARG_HANDLE_CHECKED(JSValue, parent_wrapper, 0); | 13484 CONVERT_ARG_HANDLE_CHECKED(JSValue, parent_wrapper, 0); |
13474 CONVERT_ARG_HANDLE_CHECKED(JSValue, orig_wrapper, 1); | 13485 CONVERT_ARG_HANDLE_CHECKED(JSValue, orig_wrapper, 1); |
13475 CONVERT_ARG_HANDLE_CHECKED(JSValue, subst_wrapper, 2); | 13486 CONVERT_ARG_HANDLE_CHECKED(JSValue, subst_wrapper, 2); |
13487 RUNTIME_ASSERT(parent_wrapper->value()->IsSharedFunctionInfo()); | |
13488 RUNTIME_ASSERT(orig_wrapper->value()->IsSharedFunctionInfo()); | |
13489 RUNTIME_ASSERT(subst_wrapper->value()->IsSharedFunctionInfo()); | |
13476 | 13490 |
13477 LiveEdit::ReplaceRefToNestedFunction( | 13491 LiveEdit::ReplaceRefToNestedFunction( |
13478 parent_wrapper, orig_wrapper, subst_wrapper); | 13492 parent_wrapper, orig_wrapper, subst_wrapper); |
13479 return isolate->heap()->undefined_value(); | 13493 return isolate->heap()->undefined_value(); |
13480 } | 13494 } |
13481 | 13495 |
13482 | 13496 |
13483 // Updates positions of a shared function info (first parameter) according | 13497 // Updates positions of a shared function info (first parameter) according |
13484 // to script source change. Text change is described in second parameter as | 13498 // to script source change. Text change is described in second parameter as |
13485 // array of groups of 3 numbers: | 13499 // array of groups of 3 numbers: |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14540 | 14554 |
14541 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { | 14555 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { |
14542 HandleScope scope(isolate); | 14556 HandleScope scope(isolate); |
14543 ASSERT(args.length() == 2); | 14557 ASSERT(args.length() == 2); |
14544 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 14558 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
14545 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); | 14559 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); |
14546 int idx = index->value() >> 1; | 14560 int idx = index->value() >> 1; |
14547 if (idx < 0) { | 14561 if (idx < 0) { |
14548 idx = -idx + object->map()->inobject_properties() - 1; | 14562 idx = -idx + object->map()->inobject_properties() - 1; |
14549 } | 14563 } |
14564 Handle<Object> raw_value(object->RawFastPropertyAt(idx), isolate); | |
14565 RUNTIME_ASSERT(raw_value->IsNumber() || raw_value->IsUninitialized()); | |
14550 return *JSObject::FastPropertyAt(object, Representation::Double(), idx); | 14566 return *JSObject::FastPropertyAt(object, Representation::Double(), idx); |
14551 } | 14567 } |
14552 | 14568 |
14553 | 14569 |
14554 RUNTIME_FUNCTION(Runtime_TryMigrateInstance) { | 14570 RUNTIME_FUNCTION(Runtime_TryMigrateInstance) { |
14555 HandleScope scope(isolate); | 14571 HandleScope scope(isolate); |
14556 ASSERT(args.length() == 1); | 14572 ASSERT(args.length() == 1); |
14557 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 14573 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
14558 if (!object->IsJSObject()) return Smi::FromInt(0); | 14574 if (!object->IsJSObject()) return Smi::FromInt(0); |
14559 Handle<JSObject> js_object = Handle<JSObject>::cast(object); | 14575 Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14885 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); | 14901 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); |
14886 return *WeakCollectionInitialize(isolate, weakmap); | 14902 return *WeakCollectionInitialize(isolate, weakmap); |
14887 } | 14903 } |
14888 | 14904 |
14889 | 14905 |
14890 RUNTIME_FUNCTION(Runtime_IsAccessAllowedForObserver) { | 14906 RUNTIME_FUNCTION(Runtime_IsAccessAllowedForObserver) { |
14891 HandleScope scope(isolate); | 14907 HandleScope scope(isolate); |
14892 ASSERT(args.length() == 3); | 14908 ASSERT(args.length() == 3); |
14893 CONVERT_ARG_HANDLE_CHECKED(JSFunction, observer, 0); | 14909 CONVERT_ARG_HANDLE_CHECKED(JSFunction, observer, 0); |
14894 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 1); | 14910 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 1); |
14895 ASSERT(object->map()->is_access_check_needed()); | 14911 RUNTIME_ASSERT(object->map()->is_access_check_needed()); |
14896 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); | 14912 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); |
14897 SaveContext save(isolate); | 14913 SaveContext save(isolate); |
14898 isolate->set_context(observer->context()); | 14914 isolate->set_context(observer->context()); |
14899 if (!isolate->MayNamedAccess( | 14915 if (!isolate->MayNamedAccess( |
14900 object, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) { | 14916 object, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) { |
14901 return isolate->heap()->false_value(); | 14917 return isolate->heap()->false_value(); |
14902 } | 14918 } |
14903 bool access_allowed = false; | 14919 bool access_allowed = false; |
14904 uint32_t index = 0; | 14920 uint32_t index = 0; |
14905 if (key->ToArrayIndex(&index) || | 14921 if (key->ToArrayIndex(&index) || |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15124 } | 15140 } |
15125 return NULL; | 15141 return NULL; |
15126 } | 15142 } |
15127 | 15143 |
15128 | 15144 |
15129 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15145 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15130 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15146 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15131 } | 15147 } |
15132 | 15148 |
15133 } } // namespace v8::internal | 15149 } } // namespace v8::internal |
OLD | NEW |