Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: src/runtime.cc

Issue 258473004: Harden more runtime functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arraybuffer.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
1284 // TODO(jkummerow): When we have a "safe numerics" helper class, use it here.
1285 // Entire range [offset, offset + length] must be in bounds.
1286 RUNTIME_ASSERT(offset <= buffer_length);
1287 RUNTIME_ASSERT(offset + length <= buffer_length);
1288 // No overflow.
1289 RUNTIME_ASSERT(offset + length >= offset);
1271 1290
1272 holder->set_buffer(*buffer); 1291 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); 1292 holder->set_byte_offset(*byte_offset);
1279 ASSERT(byte_length->IsNumber());
1280 holder->set_byte_length(*byte_length); 1293 holder->set_byte_length(*byte_length);
1281 1294
1282 holder->set_weak_next(buffer->weak_first_view()); 1295 holder->set_weak_next(buffer->weak_first_view());
1283 buffer->set_weak_first_view(*holder); 1296 buffer->set_weak_first_view(*holder);
1284 1297
1285 return isolate->heap()->undefined_value(); 1298 return isolate->heap()->undefined_value();
1286 } 1299 }
1287 1300
1288 1301
1289 inline static bool NeedToFlipBytes(bool is_little_endian) { 1302 inline static bool NeedToFlipBytes(bool is_little_endian) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); 1588 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
1576 return Smi::FromInt(table->NumberOfElements()); 1589 return Smi::FromInt(table->NumberOfElements());
1577 } 1590 }
1578 1591
1579 1592
1580 RUNTIME_FUNCTION(Runtime_SetCreateIterator) { 1593 RUNTIME_FUNCTION(Runtime_SetCreateIterator) {
1581 HandleScope scope(isolate); 1594 HandleScope scope(isolate);
1582 ASSERT(args.length() == 2); 1595 ASSERT(args.length() == 2);
1583 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); 1596 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
1584 CONVERT_SMI_ARG_CHECKED(kind, 1) 1597 CONVERT_SMI_ARG_CHECKED(kind, 1)
1585 ASSERT(kind == JSSetIterator::kKindValues 1598 RUNTIME_ASSERT(kind == JSSetIterator::kKindValues ||
1586 || kind == JSSetIterator::kKindEntries); 1599 kind == JSSetIterator::kKindEntries);
1587 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); 1600 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
1588 return *JSSetIterator::Create(table, kind); 1601 return *JSSetIterator::Create(table, kind);
1589 } 1602 }
1590 1603
1591 1604
1592 RUNTIME_FUNCTION(Runtime_SetIteratorNext) { 1605 RUNTIME_FUNCTION(Runtime_SetIteratorNext) {
1593 HandleScope scope(isolate); 1606 HandleScope scope(isolate);
1594 ASSERT(args.length() == 1); 1607 ASSERT(args.length() == 1);
1595 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); 1608 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0);
1596 return *JSSetIterator::Next(holder); 1609 return *JSSetIterator::Next(holder);
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
3090 CONVERT_ARG_CHECKED(JSFunction, f, 0); 3103 CONVERT_ARG_CHECKED(JSFunction, f, 0);
3091 return isolate->heap()->ToBoolean(f->IsBuiltin()); 3104 return isolate->heap()->ToBoolean(f->IsBuiltin());
3092 } 3105 }
3093 3106
3094 3107
3095 RUNTIME_FUNCTION(Runtime_SetCode) { 3108 RUNTIME_FUNCTION(Runtime_SetCode) {
3096 HandleScope scope(isolate); 3109 HandleScope scope(isolate);
3097 ASSERT(args.length() == 2); 3110 ASSERT(args.length() == 2);
3098 3111
3099 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0); 3112 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
3100 CONVERT_ARG_HANDLE_CHECKED(Object, code, 1); 3113 CONVERT_ARG_HANDLE_CHECKED(JSFunction, source, 1);
3101 3114
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()); 3115 Handle<SharedFunctionInfo> target_shared(target->shared());
3106 Handle<SharedFunctionInfo> source_shared(source->shared()); 3116 Handle<SharedFunctionInfo> source_shared(source->shared());
3107 3117
3108 if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) { 3118 if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) {
3109 return isolate->heap()->exception(); 3119 return isolate->heap()->exception();
3110 } 3120 }
3111 3121
3112 // Mark both, the source and the target, as un-flushable because the 3122 // Mark both, the source and the target, as un-flushable because the
3113 // shared unoptimized code makes them impossible to enqueue in a list. 3123 // shared unoptimized code makes them impossible to enqueue in a list.
3114 ASSERT(target_shared->code()->gc_metadata() == NULL); 3124 ASSERT(target_shared->code()->gc_metadata() == NULL);
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
4289 4299
4290 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { 4300 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) {
4291 HandleScope scope(isolate); 4301 HandleScope scope(isolate);
4292 ASSERT(args.length() == 4); 4302 ASSERT(args.length() == 4);
4293 4303
4294 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 4304 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
4295 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); 4305 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2);
4296 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 4306 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
4297 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); 4307 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3);
4298 4308
4299 ASSERT(regexp->GetFlags().is_global()); 4309 RUNTIME_ASSERT(regexp->GetFlags().is_global());
4300 4310
4301 subject = String::Flatten(subject); 4311 subject = String::Flatten(subject);
4302 4312
4303 if (replacement->length() == 0) { 4313 if (replacement->length() == 0) {
4304 if (subject->HasOnlyOneByteChars()) { 4314 if (subject->HasOnlyOneByteChars()) {
4305 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( 4315 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>(
4306 isolate, subject, regexp, last_match_info); 4316 isolate, subject, regexp, last_match_info);
4307 } else { 4317 } else {
4308 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( 4318 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>(
4309 isolate, subject, regexp, last_match_info); 4319 isolate, subject, regexp, last_match_info);
(...skipping 2914 matching lines...) Expand 10 before | Expand all | Expand 10 after
7224 7234
7225 7235
7226 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { 7236 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) {
7227 HandleScope scope(isolate); 7237 HandleScope scope(isolate);
7228 ASSERT(args.length() == 3); 7238 ASSERT(args.length() == 3);
7229 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); 7239 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
7230 if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength(); 7240 if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength();
7231 CONVERT_SMI_ARG_CHECKED(array_length, 1); 7241 CONVERT_SMI_ARG_CHECKED(array_length, 1);
7232 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); 7242 CONVERT_ARG_HANDLE_CHECKED(String, special, 2);
7233 7243
7244 size_t actual_array_length = 0;
7245 RUNTIME_ASSERT(
7246 TryNumberToSize(isolate, array->length(), &actual_array_length));
7247 RUNTIME_ASSERT(array_length >= 0);
7248 RUNTIME_ASSERT(static_cast<size_t>(array_length) <= actual_array_length);
7249
7234 // This assumption is used by the slice encoding in one or two smis. 7250 // This assumption is used by the slice encoding in one or two smis.
7235 ASSERT(Smi::kMaxValue >= String::kMaxLength); 7251 ASSERT(Smi::kMaxValue >= String::kMaxLength);
7236 7252
7237 JSObject::EnsureCanContainHeapObjectElements(array); 7253 JSObject::EnsureCanContainHeapObjectElements(array);
7238 7254
7239 int special_length = special->length(); 7255 int special_length = special->length();
7240 if (!array->HasFastObjectElements()) { 7256 if (!array->HasFastObjectElements()) {
7241 return isolate->Throw(isolate->heap()->illegal_argument_string()); 7257 return isolate->Throw(isolate->heap()->illegal_argument_string());
7242 } 7258 }
7243 7259
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
7592 return Smi::FromInt(not_equal); 7608 return Smi::FromInt(not_equal);
7593 } 7609 }
7594 7610
7595 7611
7596 RUNTIME_FUNCTION(Runtime_NumberCompare) { 7612 RUNTIME_FUNCTION(Runtime_NumberCompare) {
7597 SealHandleScope shs(isolate); 7613 SealHandleScope shs(isolate);
7598 ASSERT(args.length() == 3); 7614 ASSERT(args.length() == 3);
7599 7615
7600 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7616 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7601 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7617 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7602 if (std::isnan(x) || std::isnan(y)) return args[2]; 7618 CONVERT_ARG_HANDLE_CHECKED(Object, uncomparable_result, 2)
7619 if (std::isnan(x) || std::isnan(y)) return *uncomparable_result;
7603 if (x == y) return Smi::FromInt(EQUAL); 7620 if (x == y) return Smi::FromInt(EQUAL);
7604 if (isless(x, y)) return Smi::FromInt(LESS); 7621 if (isless(x, y)) return Smi::FromInt(LESS);
7605 return Smi::FromInt(GREATER); 7622 return Smi::FromInt(GREATER);
7606 } 7623 }
7607 7624
7608 7625
7609 // Compare two Smis as if they were converted to strings and then 7626 // Compare two Smis as if they were converted to strings and then
7610 // compared lexicographically. 7627 // compared lexicographically.
7611 RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) { 7628 RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) {
7612 SealHandleScope shs(isolate); 7629 SealHandleScope shs(isolate);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
7880 double result = power_double_double(x, y); 7897 double result = power_double_double(x, y);
7881 if (std::isnan(result)) return isolate->heap()->nan_value(); 7898 if (std::isnan(result)) return isolate->heap()->nan_value();
7882 return *isolate->factory()->NewNumber(result); 7899 return *isolate->factory()->NewNumber(result);
7883 } 7900 }
7884 } 7901 }
7885 7902
7886 7903
7887 RUNTIME_FUNCTION(Runtime_RoundNumber) { 7904 RUNTIME_FUNCTION(Runtime_RoundNumber) {
7888 HandleScope scope(isolate); 7905 HandleScope scope(isolate);
7889 ASSERT(args.length() == 1); 7906 ASSERT(args.length() == 1);
7907 CONVERT_NUMBER_ARG_HANDLE_CHECKED(input, 0);
7890 isolate->counters()->math_round()->Increment(); 7908 isolate->counters()->math_round()->Increment();
7891 7909
7892 if (!args[0]->IsHeapNumber()) { 7910 if (!input->IsHeapNumber()) {
7893 // Must be smi. Return the argument unchanged for all the other types 7911 ASSERT(input->IsSmi());
7894 // to make fuzz-natives test happy. 7912 return *input;
7895 return args[0];
7896 } 7913 }
7897 7914
7898 HeapNumber* number = reinterpret_cast<HeapNumber*>(args[0]); 7915 Handle<HeapNumber> number = Handle<HeapNumber>::cast(input);
7899 7916
7900 double value = number->value(); 7917 double value = number->value();
7901 int exponent = number->get_exponent(); 7918 int exponent = number->get_exponent();
7902 int sign = number->get_sign(); 7919 int sign = number->get_sign();
7903 7920
7904 if (exponent < -1) { 7921 if (exponent < -1) {
7905 // Number in range ]-0.5..0.5[. These always round to +/-zero. 7922 // Number in range ]-0.5..0.5[. These always round to +/-zero.
7906 if (sign) return isolate->heap()->minus_zero_value(); 7923 if (sign) return isolate->heap()->minus_zero_value();
7907 return Smi::FromInt(0); 7924 return Smi::FromInt(0);
7908 } 7925 }
7909 7926
7910 // We compare with kSmiValueSize - 2 because (2^30 - 0.1) has exponent 29 and 7927 // 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 7928 // should be rounded to 2^30, which is not smi (for 31-bit smis, similar
7912 // argument holds for 32-bit smis). 7929 // argument holds for 32-bit smis).
7913 if (!sign && exponent < kSmiValueSize - 2) { 7930 if (!sign && exponent < kSmiValueSize - 2) {
7914 return Smi::FromInt(static_cast<int>(value + 0.5)); 7931 return Smi::FromInt(static_cast<int>(value + 0.5));
7915 } 7932 }
7916 7933
7917 // If the magnitude is big enough, there's no place for fraction part. If we 7934 // 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. 7935 // try to add 0.5 to this number, 1.0 will be added instead.
7919 if (exponent >= 52) { 7936 if (exponent >= 52) {
7920 return number; 7937 return *number;
7921 } 7938 }
7922 7939
7923 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); 7940 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value();
7924 7941
7925 // Do not call NumberFromDouble() to avoid extra checks. 7942 // Do not call NumberFromDouble() to avoid extra checks.
7926 return *isolate->factory()->NewNumber(std::floor(value + 0.5)); 7943 return *isolate->factory()->NewNumber(std::floor(value + 0.5));
7927 } 7944 }
7928 7945
7929 7946
7930 RUNTIME_FUNCTION(Runtime_MathSqrt) { 7947 RUNTIME_FUNCTION(Runtime_MathSqrt) {
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
9659 9676
9660 9677
9661 RUNTIME_FUNCTION(Runtime_DateParseString) { 9678 RUNTIME_FUNCTION(Runtime_DateParseString) {
9662 HandleScope scope(isolate); 9679 HandleScope scope(isolate);
9663 ASSERT(args.length() == 2); 9680 ASSERT(args.length() == 2);
9664 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); 9681 CONVERT_ARG_HANDLE_CHECKED(String, str, 0);
9665 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); 9682 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1);
9666 9683
9667 JSObject::EnsureCanContainHeapObjectElements(output); 9684 JSObject::EnsureCanContainHeapObjectElements(output);
9668 RUNTIME_ASSERT(output->HasFastObjectElements()); 9685 RUNTIME_ASSERT(output->HasFastObjectElements());
9686 Handle<FixedArray> output_array(FixedArray::cast(output->elements()));
9687 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
9669 9688
9670 str = String::Flatten(str); 9689 str = String::Flatten(str);
9671 DisallowHeapAllocation no_gc; 9690 DisallowHeapAllocation no_gc;
9672 9691
9673 FixedArray* output_array = FixedArray::cast(output->elements());
9674 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
9675 bool result; 9692 bool result;
9676 String::FlatContent str_content = str->GetFlatContent(); 9693 String::FlatContent str_content = str->GetFlatContent();
9677 if (str_content.IsAscii()) { 9694 if (str_content.IsAscii()) {
9678 result = DateParser::Parse(str_content.ToOneByteVector(), 9695 result = DateParser::Parse(str_content.ToOneByteVector(),
9679 output_array, 9696 *output_array,
9680 isolate->unicode_cache()); 9697 isolate->unicode_cache());
9681 } else { 9698 } else {
9682 ASSERT(str_content.IsTwoByte()); 9699 ASSERT(str_content.IsTwoByte());
9683 result = DateParser::Parse(str_content.ToUC16Vector(), 9700 result = DateParser::Parse(str_content.ToUC16Vector(),
9684 output_array, 9701 *output_array,
9685 isolate->unicode_cache()); 9702 isolate->unicode_cache());
9686 } 9703 }
9687 9704
9688 if (result) { 9705 if (result) {
9689 return *output; 9706 return *output;
9690 } else { 9707 } else {
9691 return isolate->heap()->null_value(); 9708 return isolate->heap()->null_value();
9692 } 9709 }
9693 } 9710 }
9694 9711
(...skipping 3771 matching lines...) Expand 10 before | Expand all | Expand 10 after
13466 // In a code of a parent function replaces original function as embedded object 13483 // In a code of a parent function replaces original function as embedded object
13467 // with a substitution one. 13484 // with a substitution one.
13468 RUNTIME_FUNCTION(Runtime_LiveEditReplaceRefToNestedFunction) { 13485 RUNTIME_FUNCTION(Runtime_LiveEditReplaceRefToNestedFunction) {
13469 HandleScope scope(isolate); 13486 HandleScope scope(isolate);
13470 CHECK(isolate->debugger()->live_edit_enabled()); 13487 CHECK(isolate->debugger()->live_edit_enabled());
13471 ASSERT(args.length() == 3); 13488 ASSERT(args.length() == 3);
13472 13489
13473 CONVERT_ARG_HANDLE_CHECKED(JSValue, parent_wrapper, 0); 13490 CONVERT_ARG_HANDLE_CHECKED(JSValue, parent_wrapper, 0);
13474 CONVERT_ARG_HANDLE_CHECKED(JSValue, orig_wrapper, 1); 13491 CONVERT_ARG_HANDLE_CHECKED(JSValue, orig_wrapper, 1);
13475 CONVERT_ARG_HANDLE_CHECKED(JSValue, subst_wrapper, 2); 13492 CONVERT_ARG_HANDLE_CHECKED(JSValue, subst_wrapper, 2);
13493 RUNTIME_ASSERT(parent_wrapper->value()->IsSharedFunctionInfo());
13494 RUNTIME_ASSERT(orig_wrapper->value()->IsSharedFunctionInfo());
13495 RUNTIME_ASSERT(subst_wrapper->value()->IsSharedFunctionInfo());
13476 13496
13477 LiveEdit::ReplaceRefToNestedFunction( 13497 LiveEdit::ReplaceRefToNestedFunction(
13478 parent_wrapper, orig_wrapper, subst_wrapper); 13498 parent_wrapper, orig_wrapper, subst_wrapper);
13479 return isolate->heap()->undefined_value(); 13499 return isolate->heap()->undefined_value();
13480 } 13500 }
13481 13501
13482 13502
13483 // Updates positions of a shared function info (first parameter) according 13503 // Updates positions of a shared function info (first parameter) according
13484 // to script source change. Text change is described in second parameter as 13504 // to script source change. Text change is described in second parameter as
13485 // array of groups of 3 numbers: 13505 // array of groups of 3 numbers:
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
14540 14560
14541 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { 14561 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) {
14542 HandleScope scope(isolate); 14562 HandleScope scope(isolate);
14543 ASSERT(args.length() == 2); 14563 ASSERT(args.length() == 2);
14544 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 14564 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
14545 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); 14565 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1);
14546 int idx = index->value() >> 1; 14566 int idx = index->value() >> 1;
14547 if (idx < 0) { 14567 if (idx < 0) {
14548 idx = -idx + object->map()->inobject_properties() - 1; 14568 idx = -idx + object->map()->inobject_properties() - 1;
14549 } 14569 }
14570 Handle<Object> raw_value(object->RawFastPropertyAt(idx), isolate);
14571 RUNTIME_ASSERT(raw_value->IsNumber() || raw_value->IsUninitialized());
14550 return *JSObject::FastPropertyAt(object, Representation::Double(), idx); 14572 return *JSObject::FastPropertyAt(object, Representation::Double(), idx);
14551 } 14573 }
14552 14574
14553 14575
14554 RUNTIME_FUNCTION(Runtime_TryMigrateInstance) { 14576 RUNTIME_FUNCTION(Runtime_TryMigrateInstance) {
14555 HandleScope scope(isolate); 14577 HandleScope scope(isolate);
14556 ASSERT(args.length() == 1); 14578 ASSERT(args.length() == 1);
14557 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 14579 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
14558 if (!object->IsJSObject()) return Smi::FromInt(0); 14580 if (!object->IsJSObject()) return Smi::FromInt(0);
14559 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 14581 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
14885 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); 14907 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map));
14886 return *WeakCollectionInitialize(isolate, weakmap); 14908 return *WeakCollectionInitialize(isolate, weakmap);
14887 } 14909 }
14888 14910
14889 14911
14890 RUNTIME_FUNCTION(Runtime_IsAccessAllowedForObserver) { 14912 RUNTIME_FUNCTION(Runtime_IsAccessAllowedForObserver) {
14891 HandleScope scope(isolate); 14913 HandleScope scope(isolate);
14892 ASSERT(args.length() == 3); 14914 ASSERT(args.length() == 3);
14893 CONVERT_ARG_HANDLE_CHECKED(JSFunction, observer, 0); 14915 CONVERT_ARG_HANDLE_CHECKED(JSFunction, observer, 0);
14894 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 1); 14916 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 1);
14895 ASSERT(object->map()->is_access_check_needed()); 14917 RUNTIME_ASSERT(object->map()->is_access_check_needed());
14896 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); 14918 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2);
14897 SaveContext save(isolate); 14919 SaveContext save(isolate);
14898 isolate->set_context(observer->context()); 14920 isolate->set_context(observer->context());
14899 if (!isolate->MayNamedAccess( 14921 if (!isolate->MayNamedAccess(
14900 object, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) { 14922 object, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) {
14901 return isolate->heap()->false_value(); 14923 return isolate->heap()->false_value();
14902 } 14924 }
14903 bool access_allowed = false; 14925 bool access_allowed = false;
14904 uint32_t index = 0; 14926 uint32_t index = 0;
14905 if (key->ToArrayIndex(&index) || 14927 if (key->ToArrayIndex(&index) ||
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
15124 } 15146 }
15125 return NULL; 15147 return NULL;
15126 } 15148 }
15127 15149
15128 15150
15129 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15151 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15130 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15152 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15131 } 15153 }
15132 15154
15133 } } // namespace v8::internal 15155 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arraybuffer.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698