| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 incomplete_message_ = NULL; | 516 incomplete_message_ = NULL; |
| 517 stack_trace_nesting_level_ = 0; | 517 stack_trace_nesting_level_ = 0; |
| 518 return stack_trace; | 518 return stack_trace; |
| 519 } else if (stack_trace_nesting_level_ == 1) { | 519 } else if (stack_trace_nesting_level_ == 1) { |
| 520 stack_trace_nesting_level_++; | 520 stack_trace_nesting_level_++; |
| 521 OS::PrintError( | 521 OS::PrintError( |
| 522 "\n\nAttempt to print stack while printing stack (double fault)\n"); | 522 "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 523 OS::PrintError( | 523 OS::PrintError( |
| 524 "If you are lucky you may find a partial stack dump on stdout.\n\n"); | 524 "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 525 incomplete_message_->OutputToStdOut(); | 525 incomplete_message_->OutputToStdOut(); |
| 526 return factory()->empty_symbol(); | 526 return factory()->empty_string(); |
| 527 } else { | 527 } else { |
| 528 OS::Abort(); | 528 OS::Abort(); |
| 529 // Unreachable | 529 // Unreachable |
| 530 return factory()->empty_symbol(); | 530 return factory()->empty_string(); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 | 534 |
| 535 void Isolate::PushStackTraceAndDie(unsigned int magic, | 535 void Isolate::PushStackTraceAndDie(unsigned int magic, |
| 536 Object* object, | 536 Object* object, |
| 537 Map* map, | 537 Map* map, |
| 538 unsigned int magic2) { | 538 unsigned int magic2) { |
| 539 const int kMaxStackTraceSize = 8192; | 539 const int kMaxStackTraceSize = 8192; |
| 540 Handle<String> trace = StackTraceString(); | 540 Handle<String> trace = StackTraceString(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 } | 637 } |
| 638 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); | 638 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); |
| 639 result->set_length(Smi::FromInt(cursor)); | 639 result->set_length(Smi::FromInt(cursor)); |
| 640 return result; | 640 return result; |
| 641 } | 641 } |
| 642 | 642 |
| 643 | 643 |
| 644 void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) { | 644 void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) { |
| 645 if (capture_stack_trace_for_uncaught_exceptions_) { | 645 if (capture_stack_trace_for_uncaught_exceptions_) { |
| 646 // Capture stack trace for a detailed exception message. | 646 // Capture stack trace for a detailed exception message. |
| 647 Handle<String> key = factory()->hidden_stack_trace_symbol(); | 647 Handle<String> key = factory()->hidden_stack_trace_string(); |
| 648 Handle<JSArray> stack_trace = CaptureCurrentStackTrace( | 648 Handle<JSArray> stack_trace = CaptureCurrentStackTrace( |
| 649 stack_trace_for_uncaught_exceptions_frame_limit_, | 649 stack_trace_for_uncaught_exceptions_frame_limit_, |
| 650 stack_trace_for_uncaught_exceptions_options_); | 650 stack_trace_for_uncaught_exceptions_options_); |
| 651 JSObject::SetHiddenProperty(error_object, key, stack_trace); | 651 JSObject::SetHiddenProperty(error_object, key, stack_trace); |
| 652 } | 652 } |
| 653 } | 653 } |
| 654 | 654 |
| 655 | 655 |
| 656 Handle<JSArray> Isolate::CaptureCurrentStackTrace( | 656 Handle<JSArray> Isolate::CaptureCurrentStackTrace( |
| 657 int frame_limit, StackTrace::StackTraceOptions options) { | 657 int frame_limit, StackTrace::StackTraceOptions options) { |
| 658 // Ensure no negative values. | 658 // Ensure no negative values. |
| 659 int limit = Max(frame_limit, 0); | 659 int limit = Max(frame_limit, 0); |
| 660 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); | 660 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); |
| 661 | 661 |
| 662 Handle<String> column_key = | 662 Handle<String> column_key = |
| 663 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("column")); | 663 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column")); |
| 664 Handle<String> line_key = | 664 Handle<String> line_key = |
| 665 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("lineNumber")); | 665 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber")); |
| 666 Handle<String> script_key = | 666 Handle<String> script_key = |
| 667 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("scriptName")); | 667 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("scriptName")); |
| 668 Handle<String> script_name_or_source_url_key = | 668 Handle<String> script_name_or_source_url_key = |
| 669 factory()->LookupOneByteSymbol( | 669 factory()->InternalizeOneByteString( |
| 670 STATIC_ASCII_VECTOR("scriptNameOrSourceURL")); | 670 STATIC_ASCII_VECTOR("scriptNameOrSourceURL")); |
| 671 Handle<String> function_key = | 671 Handle<String> function_key = |
| 672 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("functionName")); | 672 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("functionName")); |
| 673 Handle<String> eval_key = | 673 Handle<String> eval_key = |
| 674 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("isEval")); | 674 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("isEval")); |
| 675 Handle<String> constructor_key = | 675 Handle<String> constructor_key = |
| 676 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("isConstructor")); | 676 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("isConstructor")); |
| 677 | 677 |
| 678 StackTraceFrameIterator it(this); | 678 StackTraceFrameIterator it(this); |
| 679 int frames_seen = 0; | 679 int frames_seen = 0; |
| 680 while (!it.done() && (frames_seen < limit)) { | 680 while (!it.done() && (frames_seen < limit)) { |
| 681 JavaScriptFrame* frame = it.frame(); | 681 JavaScriptFrame* frame = it.frame(); |
| 682 // Set initial size to the maximum inlining level + 1 for the outermost | 682 // Set initial size to the maximum inlining level + 1 for the outermost |
| 683 // function. | 683 // function. |
| 684 List<FrameSummary> frames(Compiler::kMaxInliningLevels + 1); | 684 List<FrameSummary> frames(Compiler::kMaxInliningLevels + 1); |
| 685 frame->Summarize(&frames); | 685 frame->Summarize(&frames); |
| 686 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { | 686 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 | 908 |
| 909 bool Isolate::MayNamedAccess(JSObject* receiver, Object* key, | 909 bool Isolate::MayNamedAccess(JSObject* receiver, Object* key, |
| 910 v8::AccessType type) { | 910 v8::AccessType type) { |
| 911 ASSERT(receiver->IsAccessCheckNeeded()); | 911 ASSERT(receiver->IsAccessCheckNeeded()); |
| 912 | 912 |
| 913 // The callers of this method are not expecting a GC. | 913 // The callers of this method are not expecting a GC. |
| 914 AssertNoAllocation no_gc; | 914 AssertNoAllocation no_gc; |
| 915 | 915 |
| 916 // Skip checks for hidden properties access. Note, we do not | 916 // Skip checks for hidden properties access. Note, we do not |
| 917 // require existence of a context in this case. | 917 // require existence of a context in this case. |
| 918 if (key == heap_.hidden_symbol()) return true; | 918 if (key == heap_.hidden_string()) return true; |
| 919 | 919 |
| 920 // Check for compatibility between the security tokens in the | 920 // Check for compatibility between the security tokens in the |
| 921 // current lexical context and the accessed object. | 921 // current lexical context and the accessed object. |
| 922 ASSERT(context()); | 922 ASSERT(context()); |
| 923 | 923 |
| 924 MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); | 924 MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); |
| 925 if (decision != UNKNOWN) return decision == YES; | 925 if (decision != UNKNOWN) return decision == YES; |
| 926 | 926 |
| 927 // Get named access check callback | 927 // Get named access check callback |
| 928 // TODO(dcarney): revert | 928 // TODO(dcarney): revert |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 | 1004 |
| 1005 const char* const Isolate::kStackOverflowMessage = | 1005 const char* const Isolate::kStackOverflowMessage = |
| 1006 "Uncaught RangeError: Maximum call stack size exceeded"; | 1006 "Uncaught RangeError: Maximum call stack size exceeded"; |
| 1007 | 1007 |
| 1008 | 1008 |
| 1009 Failure* Isolate::StackOverflow() { | 1009 Failure* Isolate::StackOverflow() { |
| 1010 HandleScope scope; | 1010 HandleScope scope; |
| 1011 // At this point we cannot create an Error object using its javascript | 1011 // At this point we cannot create an Error object using its javascript |
| 1012 // constructor. Instead, we copy the pre-constructed boilerplate and | 1012 // constructor. Instead, we copy the pre-constructed boilerplate and |
| 1013 // attach the stack trace as a hidden property. | 1013 // attach the stack trace as a hidden property. |
| 1014 Handle<String> key = factory()->stack_overflow_symbol(); | 1014 Handle<String> key = factory()->stack_overflow_string(); |
| 1015 Handle<JSObject> boilerplate = | 1015 Handle<JSObject> boilerplate = |
| 1016 Handle<JSObject>::cast(GetProperty(js_builtins_object(), key)); | 1016 Handle<JSObject>::cast(GetProperty(js_builtins_object(), key)); |
| 1017 Handle<JSObject> exception = Copy(boilerplate); | 1017 Handle<JSObject> exception = Copy(boilerplate); |
| 1018 DoThrow(*exception, NULL); | 1018 DoThrow(*exception, NULL); |
| 1019 | 1019 |
| 1020 // Get stack trace limit. | 1020 // Get stack trace limit. |
| 1021 Handle<Object> error = GetProperty(js_builtins_object(), "$Error"); | 1021 Handle<Object> error = GetProperty(js_builtins_object(), "$Error"); |
| 1022 if (!error->IsJSObject()) return Failure::Exception(); | 1022 if (!error->IsJSObject()) return Failure::Exception(); |
| 1023 Handle<Object> stack_trace_limit = | 1023 Handle<Object> stack_trace_limit = |
| 1024 GetProperty(Handle<JSObject>::cast(error), "stackTraceLimit"); | 1024 GetProperty(Handle<JSObject>::cast(error), "stackTraceLimit"); |
| 1025 if (!stack_trace_limit->IsNumber()) return Failure::Exception(); | 1025 if (!stack_trace_limit->IsNumber()) return Failure::Exception(); |
| 1026 int limit = static_cast<int>(stack_trace_limit->Number()); | 1026 int limit = static_cast<int>(stack_trace_limit->Number()); |
| 1027 | 1027 |
| 1028 Handle<JSArray> stack_trace = CaptureSimpleStackTrace( | 1028 Handle<JSArray> stack_trace = CaptureSimpleStackTrace( |
| 1029 exception, factory()->undefined_value(), limit); | 1029 exception, factory()->undefined_value(), limit); |
| 1030 JSObject::SetHiddenProperty(exception, | 1030 JSObject::SetHiddenProperty(exception, |
| 1031 factory()->hidden_stack_trace_symbol(), | 1031 factory()->hidden_stack_trace_string(), |
| 1032 stack_trace); | 1032 stack_trace); |
| 1033 return Failure::Exception(); | 1033 return Failure::Exception(); |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 | 1036 |
| 1037 Failure* Isolate::TerminateExecution() { | 1037 Failure* Isolate::TerminateExecution() { |
| 1038 DoThrow(heap_.termination_exception(), NULL); | 1038 DoThrow(heap_.termination_exception(), NULL); |
| 1039 return Failure::Exception(); | 1039 return Failure::Exception(); |
| 1040 } | 1040 } |
| 1041 | 1041 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1055 try_catch_handler() : NULL; | 1055 try_catch_handler() : NULL; |
| 1056 | 1056 |
| 1057 // Set the exception being re-thrown. | 1057 // Set the exception being re-thrown. |
| 1058 set_pending_exception(exception); | 1058 set_pending_exception(exception); |
| 1059 if (exception->IsFailure()) return exception->ToFailureUnchecked(); | 1059 if (exception->IsFailure()) return exception->ToFailureUnchecked(); |
| 1060 return Failure::Exception(); | 1060 return Failure::Exception(); |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 | 1063 |
| 1064 Failure* Isolate::ThrowIllegalOperation() { | 1064 Failure* Isolate::ThrowIllegalOperation() { |
| 1065 return Throw(heap_.illegal_access_symbol()); | 1065 return Throw(heap_.illegal_access_string()); |
| 1066 } | 1066 } |
| 1067 | 1067 |
| 1068 | 1068 |
| 1069 void Isolate::ScheduleThrow(Object* exception) { | 1069 void Isolate::ScheduleThrow(Object* exception) { |
| 1070 // When scheduling a throw we first throw the exception to get the | 1070 // When scheduling a throw we first throw the exception to get the |
| 1071 // error reporting if it is uncaught before rescheduling it. | 1071 // error reporting if it is uncaught before rescheduling it. |
| 1072 Throw(exception); | 1072 Throw(exception); |
| 1073 PropagatePendingExceptionToExternalTryCatch(); | 1073 PropagatePendingExceptionToExternalTryCatch(); |
| 1074 if (has_pending_exception()) { | 1074 if (has_pending_exception()) { |
| 1075 thread_local_top()->scheduled_exception_ = pending_exception(); | 1075 thread_local_top()->scheduled_exception_ = pending_exception(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 // Report the exception if it isn't caught by JavaScript code. | 1161 // Report the exception if it isn't caught by JavaScript code. |
| 1162 return handler == NULL; | 1162 return handler == NULL; |
| 1163 } | 1163 } |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 | 1166 |
| 1167 bool Isolate::IsErrorObject(Handle<Object> obj) { | 1167 bool Isolate::IsErrorObject(Handle<Object> obj) { |
| 1168 if (!obj->IsJSObject()) return false; | 1168 if (!obj->IsJSObject()) return false; |
| 1169 | 1169 |
| 1170 String* error_key = | 1170 String* error_key = |
| 1171 *(factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("$Error"))); | 1171 *(factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$Error"))); |
| 1172 Object* error_constructor = | 1172 Object* error_constructor = |
| 1173 js_builtins_object()->GetPropertyNoExceptionThrown(error_key); | 1173 js_builtins_object()->GetPropertyNoExceptionThrown(error_key); |
| 1174 | 1174 |
| 1175 for (Object* prototype = *obj; !prototype->IsNull(); | 1175 for (Object* prototype = *obj; !prototype->IsNull(); |
| 1176 prototype = prototype->GetPrototype()) { | 1176 prototype = prototype->GetPrototype()) { |
| 1177 if (!prototype->IsJSObject()) return false; | 1177 if (!prototype->IsJSObject()) return false; |
| 1178 if (JSObject::cast(prototype)->map()->constructor() == error_constructor) { | 1178 if (JSObject::cast(prototype)->map()->constructor() == error_constructor) { |
| 1179 return true; | 1179 return true; |
| 1180 } | 1180 } |
| 1181 } | 1181 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 // It's not safe to try to make message objects or collect stack traces | 1217 // It's not safe to try to make message objects or collect stack traces |
| 1218 // while the bootstrapper is active since the infrastructure may not have | 1218 // while the bootstrapper is active since the infrastructure may not have |
| 1219 // been properly initialized. | 1219 // been properly initialized. |
| 1220 if (!bootstrapping) { | 1220 if (!bootstrapping) { |
| 1221 Handle<String> stack_trace; | 1221 Handle<String> stack_trace; |
| 1222 if (FLAG_trace_exception) stack_trace = StackTraceString(); | 1222 if (FLAG_trace_exception) stack_trace = StackTraceString(); |
| 1223 Handle<JSArray> stack_trace_object; | 1223 Handle<JSArray> stack_trace_object; |
| 1224 if (capture_stack_trace_for_uncaught_exceptions_) { | 1224 if (capture_stack_trace_for_uncaught_exceptions_) { |
| 1225 if (IsErrorObject(exception_handle)) { | 1225 if (IsErrorObject(exception_handle)) { |
| 1226 // We fetch the stack trace that corresponds to this error object. | 1226 // We fetch the stack trace that corresponds to this error object. |
| 1227 String* key = heap()->hidden_stack_trace_symbol(); | 1227 String* key = heap()->hidden_stack_trace_string(); |
| 1228 Object* stack_property = | 1228 Object* stack_property = |
| 1229 JSObject::cast(*exception_handle)->GetHiddenProperty(key); | 1229 JSObject::cast(*exception_handle)->GetHiddenProperty(key); |
| 1230 // Property lookup may have failed. In this case it's probably not | 1230 // Property lookup may have failed. In this case it's probably not |
| 1231 // a valid Error object. | 1231 // a valid Error object. |
| 1232 if (stack_property->IsJSArray()) { | 1232 if (stack_property->IsJSArray()) { |
| 1233 stack_trace_object = Handle<JSArray>(JSArray::cast(stack_property)); | 1233 stack_trace_object = Handle<JSArray>(JSArray::cast(stack_property)); |
| 1234 } | 1234 } |
| 1235 } | 1235 } |
| 1236 if (stack_trace_object.is_null()) { | 1236 if (stack_trace_object.is_null()) { |
| 1237 // Not an error object, we capture at throw site. | 1237 // Not an error object, we capture at throw site. |
| 1238 stack_trace_object = CaptureCurrentStackTrace( | 1238 stack_trace_object = CaptureCurrentStackTrace( |
| 1239 stack_trace_for_uncaught_exceptions_frame_limit_, | 1239 stack_trace_for_uncaught_exceptions_frame_limit_, |
| 1240 stack_trace_for_uncaught_exceptions_options_); | 1240 stack_trace_for_uncaught_exceptions_options_); |
| 1241 } | 1241 } |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 Handle<Object> exception_arg = exception_handle; | 1244 Handle<Object> exception_arg = exception_handle; |
| 1245 // If the exception argument is a custom object, turn it into a string | 1245 // If the exception argument is a custom object, turn it into a string |
| 1246 // before throwing as uncaught exception. Note that the pending | 1246 // before throwing as uncaught exception. Note that the pending |
| 1247 // exception object to be set later must not be turned into a string. | 1247 // exception object to be set later must not be turned into a string. |
| 1248 if (exception_arg->IsJSObject() && !IsErrorObject(exception_arg)) { | 1248 if (exception_arg->IsJSObject() && !IsErrorObject(exception_arg)) { |
| 1249 bool failed = false; | 1249 bool failed = false; |
| 1250 exception_arg = Execution::ToDetailString(exception_arg, &failed); | 1250 exception_arg = Execution::ToDetailString(exception_arg, &failed); |
| 1251 if (failed) { | 1251 if (failed) { |
| 1252 exception_arg = | 1252 exception_arg = factory()->InternalizeOneByteString( |
| 1253 factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("exception")); | 1253 STATIC_ASCII_VECTOR("exception")); |
| 1254 } | 1254 } |
| 1255 } | 1255 } |
| 1256 Handle<Object> message_obj = MessageHandler::MakeMessageObject( | 1256 Handle<Object> message_obj = MessageHandler::MakeMessageObject( |
| 1257 "uncaught_exception", | 1257 "uncaught_exception", |
| 1258 location, | 1258 location, |
| 1259 HandleVector<Object>(&exception_arg, 1), | 1259 HandleVector<Object>(&exception_arg, 1), |
| 1260 stack_trace, | 1260 stack_trace, |
| 1261 stack_trace_object); | 1261 stack_trace_object); |
| 1262 thread_local_top()->pending_message_obj_ = *message_obj; | 1262 thread_local_top()->pending_message_obj_ = *message_obj; |
| 1263 if (location != NULL) { | 1263 if (location != NULL) { |
| (...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2267 | 2267 |
| 2268 #ifdef DEBUG | 2268 #ifdef DEBUG |
| 2269 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 2269 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 2270 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 2270 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 2271 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 2271 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 2272 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 2272 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 2273 #undef ISOLATE_FIELD_OFFSET | 2273 #undef ISOLATE_FIELD_OFFSET |
| 2274 #endif | 2274 #endif |
| 2275 | 2275 |
| 2276 } } // namespace v8::internal | 2276 } } // namespace v8::internal |
| OLD | NEW |