| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 // Assert that the given argument has a valid value for a StrictMode | 145 // Assert that the given argument has a valid value for a StrictMode |
| 146 // and store it in a StrictMode variable with the given name. | 146 // and store it in a StrictMode variable with the given name. |
| 147 #define CONVERT_STRICT_MODE_ARG_CHECKED(name, index) \ | 147 #define CONVERT_STRICT_MODE_ARG_CHECKED(name, index) \ |
| 148 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 148 RUNTIME_ASSERT(args[index]->IsSmi()); \ |
| 149 RUNTIME_ASSERT(args.smi_at(index) == STRICT || \ | 149 RUNTIME_ASSERT(args.smi_at(index) == STRICT || \ |
| 150 args.smi_at(index) == SLOPPY); \ | 150 args.smi_at(index) == SLOPPY); \ |
| 151 StrictMode name = static_cast<StrictMode>(args.smi_at(index)); | 151 StrictMode name = static_cast<StrictMode>(args.smi_at(index)); |
| 152 | 152 |
| 153 | 153 |
| 154 // Assert that the given argument is a number within the Int32 range |
| 155 // and convert it to int32_t. If the argument is not an Int32 call |
| 156 // IllegalOperation and return. |
| 157 #define CONVERT_INT32_ARG_CHECKED(name, index) \ |
| 158 RUNTIME_ASSERT(args[index]->IsNumber()); \ |
| 159 int32_t name = 0; \ |
| 160 RUNTIME_ASSERT(args[index]->ToInt32(&name)); |
| 161 |
| 162 |
| 154 static Handle<Map> ComputeObjectLiteralMap( | 163 static Handle<Map> ComputeObjectLiteralMap( |
| 155 Handle<Context> context, | 164 Handle<Context> context, |
| 156 Handle<FixedArray> constant_properties, | 165 Handle<FixedArray> constant_properties, |
| 157 bool* is_result_from_cache) { | 166 bool* is_result_from_cache) { |
| 158 Isolate* isolate = context->GetIsolate(); | 167 Isolate* isolate = context->GetIsolate(); |
| 159 int properties_length = constant_properties->length(); | 168 int properties_length = constant_properties->length(); |
| 160 int number_of_properties = properties_length / 2; | 169 int number_of_properties = properties_length / 2; |
| 161 // Check that there are only internal strings and array indices among keys. | 170 // Check that there are only internal strings and array indices among keys. |
| 162 int number_of_string_keys = 0; | 171 int number_of_string_keys = 0; |
| 163 for (int p = 0; p != properties_length; p += 2) { | 172 for (int p = 0; p != properties_length; p += 2) { |
| (...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 } | 2503 } |
| 2495 return *object; | 2504 return *object; |
| 2496 } | 2505 } |
| 2497 | 2506 |
| 2498 | 2507 |
| 2499 RUNTIME_FUNCTION(Runtime_RegExpExecRT) { | 2508 RUNTIME_FUNCTION(Runtime_RegExpExecRT) { |
| 2500 HandleScope scope(isolate); | 2509 HandleScope scope(isolate); |
| 2501 DCHECK(args.length() == 4); | 2510 DCHECK(args.length() == 4); |
| 2502 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 2511 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
| 2503 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 2512 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
| 2513 CONVERT_INT32_ARG_CHECKED(index, 2); |
| 2514 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); |
| 2504 // Due to the way the JS calls are constructed this must be less than the | 2515 // Due to the way the JS calls are constructed this must be less than the |
| 2505 // length of a string, i.e. it is always a Smi. We check anyway for security. | 2516 // length of a string, i.e. it is always a Smi. We check anyway for security. |
| 2506 CONVERT_SMI_ARG_CHECKED(index, 2); | |
| 2507 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); | |
| 2508 RUNTIME_ASSERT(index >= 0); | 2517 RUNTIME_ASSERT(index >= 0); |
| 2509 RUNTIME_ASSERT(index <= subject->length()); | 2518 RUNTIME_ASSERT(index <= subject->length()); |
| 2510 isolate->counters()->regexp_entry_runtime()->Increment(); | 2519 isolate->counters()->regexp_entry_runtime()->Increment(); |
| 2511 Handle<Object> result; | 2520 Handle<Object> result; |
| 2512 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2521 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2513 isolate, result, | 2522 isolate, result, |
| 2514 RegExpImpl::Exec(regexp, subject, index, last_match_info)); | 2523 RegExpImpl::Exec(regexp, subject, index, last_match_info)); |
| 2515 return *result; | 2524 return *result; |
| 2516 } | 2525 } |
| 2517 | 2526 |
| (...skipping 3718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6236 } | 6245 } |
| 6237 | 6246 |
| 6238 return *isolate->factory()->NewNumber(StringToDouble( | 6247 return *isolate->factory()->NewNumber(StringToDouble( |
| 6239 isolate->unicode_cache(), *subject, flags)); | 6248 isolate->unicode_cache(), *subject, flags)); |
| 6240 } | 6249 } |
| 6241 | 6250 |
| 6242 | 6251 |
| 6243 RUNTIME_FUNCTION(Runtime_NewString) { | 6252 RUNTIME_FUNCTION(Runtime_NewString) { |
| 6244 HandleScope scope(isolate); | 6253 HandleScope scope(isolate); |
| 6245 DCHECK(args.length() == 2); | 6254 DCHECK(args.length() == 2); |
| 6246 CONVERT_SMI_ARG_CHECKED(length, 0); | 6255 CONVERT_INT32_ARG_CHECKED(length, 0); |
| 6247 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1); | 6256 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1); |
| 6248 if (length == 0) return isolate->heap()->empty_string(); | 6257 if (length == 0) return isolate->heap()->empty_string(); |
| 6249 Handle<String> result; | 6258 Handle<String> result; |
| 6250 if (is_one_byte) { | 6259 if (is_one_byte) { |
| 6251 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 6260 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 6252 isolate, result, isolate->factory()->NewRawOneByteString(length)); | 6261 isolate, result, isolate->factory()->NewRawOneByteString(length)); |
| 6253 } else { | 6262 } else { |
| 6254 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 6263 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 6255 isolate, result, isolate->factory()->NewRawTwoByteString(length)); | 6264 isolate, result, isolate->factory()->NewRawTwoByteString(length)); |
| 6256 } | 6265 } |
| 6257 return *result; | 6266 return *result; |
| 6258 } | 6267 } |
| 6259 | 6268 |
| 6260 | 6269 |
| 6261 RUNTIME_FUNCTION(Runtime_TruncateString) { | 6270 RUNTIME_FUNCTION(Runtime_TruncateString) { |
| 6262 HandleScope scope(isolate); | 6271 HandleScope scope(isolate); |
| 6263 DCHECK(args.length() == 2); | 6272 DCHECK(args.length() == 2); |
| 6264 CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); | 6273 CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); |
| 6265 CONVERT_SMI_ARG_CHECKED(new_length, 1); | 6274 CONVERT_INT32_ARG_CHECKED(new_length, 1); |
| 6266 RUNTIME_ASSERT(new_length >= 0); | 6275 RUNTIME_ASSERT(new_length >= 0); |
| 6267 return *SeqString::Truncate(string, new_length); | 6276 return *SeqString::Truncate(string, new_length); |
| 6268 } | 6277 } |
| 6269 | 6278 |
| 6270 | 6279 |
| 6271 RUNTIME_FUNCTION(Runtime_URIEscape) { | 6280 RUNTIME_FUNCTION(Runtime_URIEscape) { |
| 6272 HandleScope scope(isolate); | 6281 HandleScope scope(isolate); |
| 6273 DCHECK(args.length() == 1); | 6282 DCHECK(args.length() == 1); |
| 6274 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 6283 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| 6275 Handle<String> string = String::Flatten(source); | 6284 Handle<String> string = String::Flatten(source); |
| (...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8933 return *result; | 8942 return *result; |
| 8934 } | 8943 } |
| 8935 | 8944 |
| 8936 | 8945 |
| 8937 RUNTIME_FUNCTION(Runtime_Apply) { | 8946 RUNTIME_FUNCTION(Runtime_Apply) { |
| 8938 HandleScope scope(isolate); | 8947 HandleScope scope(isolate); |
| 8939 DCHECK(args.length() == 5); | 8948 DCHECK(args.length() == 5); |
| 8940 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, fun, 0); | 8949 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, fun, 0); |
| 8941 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | 8950 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
| 8942 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); | 8951 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); |
| 8943 CONVERT_SMI_ARG_CHECKED(offset, 3); | 8952 CONVERT_INT32_ARG_CHECKED(offset, 3); |
| 8944 CONVERT_SMI_ARG_CHECKED(argc, 4); | 8953 CONVERT_INT32_ARG_CHECKED(argc, 4); |
| 8945 RUNTIME_ASSERT(offset >= 0); | 8954 RUNTIME_ASSERT(offset >= 0); |
| 8946 // Loose upper bound to allow fuzzing. We'll most likely run out of | 8955 // Loose upper bound to allow fuzzing. We'll most likely run out of |
| 8947 // stack space before hitting this limit. | 8956 // stack space before hitting this limit. |
| 8948 static int kMaxArgc = 1000000; | 8957 static int kMaxArgc = 1000000; |
| 8949 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); | 8958 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); |
| 8950 | 8959 |
| 8951 // If there are too many arguments, allocate argv via malloc. | 8960 // If there are too many arguments, allocate argv via malloc. |
| 8952 const int argv_small_size = 10; | 8961 const int argv_small_size = 10; |
| 8953 Handle<Object> argv_small_buffer[argv_small_size]; | 8962 Handle<Object> argv_small_buffer[argv_small_size]; |
| 8954 SmartArrayPointer<Handle<Object> > argv_large_buffer; | 8963 SmartArrayPointer<Handle<Object> > argv_large_buffer; |
| (...skipping 6265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15220 | 15229 |
| 15221 // TODO(dcarney): remove this function when TurboFan supports it. | 15230 // TODO(dcarney): remove this function when TurboFan supports it. |
| 15222 // Takes (the object to be iterated over, | 15231 // Takes (the object to be iterated over, |
| 15223 // cache_array from ForInInit, | 15232 // cache_array from ForInInit, |
| 15224 // cache_type from ForInInit, | 15233 // cache_type from ForInInit, |
| 15225 // the current index) | 15234 // the current index) |
| 15226 // Returns pair (array[index], needs_filtering). | 15235 // Returns pair (array[index], needs_filtering). |
| 15227 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ForInNext) { | 15236 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ForInNext) { |
| 15228 SealHandleScope scope(isolate); | 15237 SealHandleScope scope(isolate); |
| 15229 DCHECK(args.length() == 4); | 15238 DCHECK(args.length() == 4); |
| 15239 int32_t index; |
| 15230 // This simulates CONVERT_ARG_HANDLE_CHECKED for calls returning pairs. | 15240 // This simulates CONVERT_ARG_HANDLE_CHECKED for calls returning pairs. |
| 15231 // Not worth creating a macro atm as this function should be removed. | 15241 // Not worth creating a macro atm as this function should be removed. |
| 15232 if (!args[0]->IsJSReceiver() || !args[1]->IsFixedArray() || | 15242 if (!args[0]->IsJSReceiver() || !args[1]->IsFixedArray() || |
| 15233 !args[2]->IsObject() || !args[3]->IsSmi()) { | 15243 !args[2]->IsObject() || !args[3]->ToInt32(&index)) { |
| 15234 Object* error = isolate->ThrowIllegalOperation(); | 15244 Object* error = isolate->ThrowIllegalOperation(); |
| 15235 return MakePair(error, isolate->heap()->undefined_value()); | 15245 return MakePair(error, isolate->heap()->undefined_value()); |
| 15236 } | 15246 } |
| 15237 Handle<JSReceiver> object = args.at<JSReceiver>(0); | 15247 Handle<JSReceiver> object = args.at<JSReceiver>(0); |
| 15238 Handle<FixedArray> array = args.at<FixedArray>(1); | 15248 Handle<FixedArray> array = args.at<FixedArray>(1); |
| 15239 Handle<Object> cache_type = args.at<Object>(2); | 15249 Handle<Object> cache_type = args.at<Object>(2); |
| 15240 int index = args.smi_at(3); | |
| 15241 // Figure out first if a slow check is needed for this object. | 15250 // Figure out first if a slow check is needed for this object. |
| 15242 bool slow_check_needed = false; | 15251 bool slow_check_needed = false; |
| 15243 if (cache_type->IsMap()) { | 15252 if (cache_type->IsMap()) { |
| 15244 if (object->map() != Map::cast(*cache_type)) { | 15253 if (object->map() != Map::cast(*cache_type)) { |
| 15245 // Object transitioned. Need slow check. | 15254 // Object transitioned. Need slow check. |
| 15246 slow_check_needed = true; | 15255 slow_check_needed = true; |
| 15247 } | 15256 } |
| 15248 } else { | 15257 } else { |
| 15249 // No slow check needed for proxies. | 15258 // No slow check needed for proxies. |
| 15250 slow_check_needed = Smi::cast(*cache_type)->value() == 1; | 15259 slow_check_needed = Smi::cast(*cache_type)->value() == 1; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15388 Object* code = __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 15397 Object* code = __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
| 15389 if (code->IsNaN()) return isolate->heap()->empty_string(); | 15398 if (code->IsNaN()) return isolate->heap()->empty_string(); |
| 15390 return __RT_impl_Runtime_CharFromCode(Arguments(1, &code), isolate); | 15399 return __RT_impl_Runtime_CharFromCode(Arguments(1, &code), isolate); |
| 15391 } | 15400 } |
| 15392 | 15401 |
| 15393 | 15402 |
| 15394 RUNTIME_FUNCTION(RuntimeReference_OneByteSeqStringSetChar) { | 15403 RUNTIME_FUNCTION(RuntimeReference_OneByteSeqStringSetChar) { |
| 15395 SealHandleScope shs(isolate); | 15404 SealHandleScope shs(isolate); |
| 15396 DCHECK(args.length() == 3); | 15405 DCHECK(args.length() == 3); |
| 15397 CONVERT_ARG_CHECKED(SeqOneByteString, string, 0); | 15406 CONVERT_ARG_CHECKED(SeqOneByteString, string, 0); |
| 15398 CONVERT_SMI_ARG_CHECKED(index, 1); | 15407 CONVERT_INT32_ARG_CHECKED(index, 1); |
| 15399 CONVERT_SMI_ARG_CHECKED(value, 2); | 15408 CONVERT_INT32_ARG_CHECKED(value, 2); |
| 15400 string->SeqOneByteStringSet(index, value); | 15409 string->SeqOneByteStringSet(index, value); |
| 15401 return string; | 15410 return string; |
| 15402 } | 15411 } |
| 15403 | 15412 |
| 15404 | 15413 |
| 15405 RUNTIME_FUNCTION(RuntimeReference_TwoByteSeqStringSetChar) { | 15414 RUNTIME_FUNCTION(RuntimeReference_TwoByteSeqStringSetChar) { |
| 15406 SealHandleScope shs(isolate); | 15415 SealHandleScope shs(isolate); |
| 15407 DCHECK(args.length() == 3); | 15416 DCHECK(args.length() == 3); |
| 15408 CONVERT_ARG_CHECKED(SeqTwoByteString, string, 0); | 15417 CONVERT_ARG_CHECKED(SeqTwoByteString, string, 0); |
| 15409 CONVERT_SMI_ARG_CHECKED(index, 1); | 15418 CONVERT_INT32_ARG_CHECKED(index, 1); |
| 15410 CONVERT_SMI_ARG_CHECKED(value, 2); | 15419 CONVERT_INT32_ARG_CHECKED(value, 2); |
| 15411 string->SeqTwoByteStringSet(index, value); | 15420 string->SeqTwoByteStringSet(index, value); |
| 15412 return string; | 15421 return string; |
| 15413 } | 15422 } |
| 15414 | 15423 |
| 15415 | 15424 |
| 15416 RUNTIME_FUNCTION(RuntimeReference_ObjectEquals) { | 15425 RUNTIME_FUNCTION(RuntimeReference_ObjectEquals) { |
| 15417 SealHandleScope shs(isolate); | 15426 SealHandleScope shs(isolate); |
| 15418 DCHECK(args.length() == 2); | 15427 DCHECK(args.length() == 2); |
| 15419 CONVERT_ARG_CHECKED(Object, obj1, 0); | 15428 CONVERT_ARG_CHECKED(Object, obj1, 0); |
| 15420 CONVERT_ARG_CHECKED(Object, obj2, 1); | 15429 CONVERT_ARG_CHECKED(Object, obj2, 1); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15657 } | 15666 } |
| 15658 return NULL; | 15667 return NULL; |
| 15659 } | 15668 } |
| 15660 | 15669 |
| 15661 | 15670 |
| 15662 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15671 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15663 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15672 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15664 } | 15673 } |
| 15665 | 15674 |
| 15666 } } // namespace v8::internal | 15675 } } // namespace v8::internal |
| OLD | NEW |