| OLD | NEW |
| 1 | 1 |
| 2 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 2 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 5 // met: | 5 // met: |
| 6 // | 6 // |
| 7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following | 10 // copyright notice, this list of conditions and the following |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 loc->start_pos(), *str); | 54 loc->start_pos(), *str); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 void MessageHandler::ReportMessage(const char* msg) { | 59 void MessageHandler::ReportMessage(const char* msg) { |
| 60 PrintF("%s\n", msg); | 60 PrintF("%s\n", msg); |
| 61 } | 61 } |
| 62 | 62 |
| 63 | 63 |
| 64 Handle<Object> MessageHandler::MakeMessageObject( | 64 Handle<JSMessageObject> MessageHandler::MakeMessageObject( |
| 65 const char* type, | 65 const char* type, |
| 66 MessageLocation* loc, | 66 MessageLocation* loc, |
| 67 Vector< Handle<Object> > args, | 67 Vector< Handle<Object> > args, |
| 68 Handle<String> stack_trace, | 68 Handle<String> stack_trace, |
| 69 Handle<JSArray> stack_frames) { | 69 Handle<JSArray> stack_frames) { |
| 70 // Build error message object | 70 Handle<String> type_handle = FACTORY->LookupAsciiSymbol(type); |
| 71 v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. | 71 Handle<FixedArray> arguments_elements = |
| 72 Handle<Object> type_str = FACTORY->LookupAsciiSymbol(type); | 72 FACTORY->NewFixedArray(args.length()); |
| 73 Handle<Object> array = FACTORY->NewJSArray(args.length()); | 73 for (int i = 0; i < args.length(); i++) { |
| 74 for (int i = 0; i < args.length(); i++) | 74 arguments_elements->set(i, *args[i]); |
| 75 SetElement(Handle<JSArray>::cast(array), i, args[i]); | 75 } |
| 76 Handle<JSArray> arguments_handle = |
| 77 FACTORY->NewJSArrayWithElements(arguments_elements); |
| 76 | 78 |
| 77 Handle<JSFunction> fun( | 79 int start = 0; |
| 78 Isolate::Current()->global_context()->make_message_fun()); | 80 int end = 0; |
| 79 int start, end; | 81 Handle<Object> script_handle = FACTORY->undefined_value(); |
| 80 Handle<Object> script; | |
| 81 if (loc) { | 82 if (loc) { |
| 82 start = loc->start_pos(); | 83 start = loc->start_pos(); |
| 83 end = loc->end_pos(); | 84 end = loc->end_pos(); |
| 84 script = GetScriptWrapper(loc->script()); | 85 script_handle = GetScriptWrapper(loc->script()); |
| 85 } else { | |
| 86 start = end = 0; | |
| 87 script = FACTORY->undefined_value(); | |
| 88 } | 86 } |
| 89 Handle<Object> start_handle(Smi::FromInt(start)); | |
| 90 Handle<Object> end_handle(Smi::FromInt(end)); | |
| 91 Handle<Object> stack_trace_val = stack_trace.is_null() | |
| 92 ? FACTORY->undefined_value() | |
| 93 : Handle<Object>::cast(stack_trace); | |
| 94 Handle<Object> stack_frames_val = stack_frames.is_null() | |
| 95 ? FACTORY->undefined_value() | |
| 96 : Handle<Object>::cast(stack_frames); | |
| 97 const int argc = 7; | |
| 98 Object** argv[argc] = { type_str.location(), | |
| 99 array.location(), | |
| 100 start_handle.location(), | |
| 101 end_handle.location(), | |
| 102 script.location(), | |
| 103 stack_trace_val.location(), | |
| 104 stack_frames_val.location() }; | |
| 105 | 87 |
| 106 // Setup a catch handler to catch exceptions in creating the message. This | 88 Handle<Object> stack_trace_handle = stack_trace.is_null() |
| 107 // handler is non-verbose to avoid calling MakeMessage recursively in case of | 89 ? FACTORY->undefined_value() |
| 108 // an exception. | 90 : Handle<Object>::cast(stack_trace); |
| 109 v8::TryCatch catcher; | |
| 110 catcher.SetVerbose(false); | |
| 111 catcher.SetCaptureMessage(false); | |
| 112 | 91 |
| 113 // Format the message. | 92 Handle<Object> stack_frames_handle = stack_frames.is_null() |
| 114 bool caught_exception = false; | 93 ? FACTORY->undefined_value() |
| 115 Handle<Object> message = | 94 : Handle<Object>::cast(stack_frames); |
| 116 Execution::Call(fun, FACTORY->undefined_value(), argc, argv, | |
| 117 &caught_exception); | |
| 118 | 95 |
| 119 // If creating the message (in JS code) resulted in an exception, we | 96 Handle<JSMessageObject> message = |
| 120 // skip doing the callback. This usually only happens in case of | 97 FACTORY->NewJSMessageObject(type_handle, |
| 121 // stack overflow exceptions being thrown by the parser when the | 98 arguments_handle, |
| 122 // stack is almost full. | 99 start, |
| 123 if (caught_exception) return Handle<Object>(); | 100 end, |
| 101 script_handle, |
| 102 stack_trace_handle, |
| 103 stack_frames_handle); |
| 124 | 104 |
| 125 return message.EscapeFrom(&scope); | 105 return message; |
| 126 } | 106 } |
| 127 | 107 |
| 128 | 108 |
| 129 void MessageHandler::ReportMessage(MessageLocation* loc, | 109 void MessageHandler::ReportMessage(MessageLocation* loc, |
| 130 Handle<Object> message) { | 110 Handle<Object> message) { |
| 131 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); | 111 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); |
| 132 | 112 |
| 133 v8::NeanderArray global_listeners(FACTORY->message_listeners()); | 113 v8::NeanderArray global_listeners(FACTORY->message_listeners()); |
| 134 int global_length = global_listeners.length(); | 114 int global_length = global_listeners.length(); |
| 135 if (global_length == 0) { | 115 if (global_length == 0) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 157 } |
| 178 | 158 |
| 179 | 159 |
| 180 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { | 160 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { |
| 181 HandleScope scope; | 161 HandleScope scope; |
| 182 return GetMessage(data)->ToCString(DISALLOW_NULLS); | 162 return GetMessage(data)->ToCString(DISALLOW_NULLS); |
| 183 } | 163 } |
| 184 | 164 |
| 185 | 165 |
| 186 } } // namespace v8::internal | 166 } } // namespace v8::internal |
| OLD | NEW |