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 14 matching lines...) Expand all Loading... |
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 #include "v8.h" | 29 #include "v8.h" |
30 | 30 |
31 #include "api.h" | 31 #include "api.h" |
32 #include "execution.h" | 32 #include "execution.h" |
33 #include "messages.h" | 33 #include "messages.h" |
34 #include "spaces-inl.h" | 34 #include "spaces-inl.h" |
35 #include "top.h" | |
36 | 35 |
37 namespace v8 { | 36 namespace v8 { |
38 namespace internal { | 37 namespace internal { |
39 | 38 |
40 | 39 |
41 // If no message listeners have been registered this one is called | 40 // If no message listeners have been registered this one is called |
42 // by default. | 41 // by default. |
43 void MessageHandler::DefaultMessageReport(const MessageLocation* loc, | 42 void MessageHandler::DefaultMessageReport(const MessageLocation* loc, |
44 Handle<Object> message_obj) { | 43 Handle<Object> message_obj) { |
45 SmartPointer<char> str = GetLocalizedMessage(message_obj); | 44 SmartPointer<char> str = GetLocalizedMessage(message_obj); |
(...skipping 21 matching lines...) Expand all Loading... |
67 MessageLocation* loc, | 66 MessageLocation* loc, |
68 Vector< Handle<Object> > args, | 67 Vector< Handle<Object> > args, |
69 Handle<String> stack_trace) { | 68 Handle<String> stack_trace) { |
70 // Build error message object | 69 // Build error message object |
71 v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. | 70 v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. |
72 Handle<Object> type_str = Factory::LookupAsciiSymbol(type); | 71 Handle<Object> type_str = Factory::LookupAsciiSymbol(type); |
73 Handle<Object> array = Factory::NewJSArray(args.length()); | 72 Handle<Object> array = Factory::NewJSArray(args.length()); |
74 for (int i = 0; i < args.length(); i++) | 73 for (int i = 0; i < args.length(); i++) |
75 SetElement(Handle<JSArray>::cast(array), i, args[i]); | 74 SetElement(Handle<JSArray>::cast(array), i, args[i]); |
76 | 75 |
77 Handle<JSFunction> fun(Top::global_context()->make_message_fun()); | 76 Handle<JSFunction> fun( |
| 77 Isolate::Current()->global_context()->make_message_fun()); |
78 int start, end; | 78 int start, end; |
79 Handle<Object> script; | 79 Handle<Object> script; |
80 if (loc) { | 80 if (loc) { |
81 start = loc->start_pos(); | 81 start = loc->start_pos(); |
82 end = loc->end_pos(); | 82 end = loc->end_pos(); |
83 script = GetScriptWrapper(loc->script()); | 83 script = GetScriptWrapper(loc->script()); |
84 } else { | 84 } else { |
85 start = end = 0; | 85 start = end = 0; |
86 script = Factory::undefined_value(); | 86 script = Factory::undefined_value(); |
87 } | 87 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); | 141 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { | 147 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { |
148 Handle<String> fmt_str = Factory::LookupAsciiSymbol("FormatMessage"); | 148 Handle<String> fmt_str = Factory::LookupAsciiSymbol("FormatMessage"); |
149 Handle<JSFunction> fun = | 149 Handle<JSFunction> fun = |
150 Handle<JSFunction>( | 150 Handle<JSFunction>( |
151 JSFunction::cast(Top::builtins()->GetProperty(*fmt_str))); | 151 JSFunction::cast( |
| 152 Isolate::Current()->builtins()->GetProperty(*fmt_str))); |
152 Object** argv[1] = { data.location() }; | 153 Object** argv[1] = { data.location() }; |
153 | 154 |
154 bool caught_exception; | 155 bool caught_exception; |
155 Handle<Object> result = | 156 Handle<Object> result = |
156 Execution::TryCall(fun, Top::builtins(), 1, argv, &caught_exception); | 157 Execution::TryCall(fun, |
| 158 Isolate::Current()->builtins(), 1, argv, &caught_exception); |
157 | 159 |
158 if (caught_exception || !result->IsString()) { | 160 if (caught_exception || !result->IsString()) { |
159 return Factory::LookupAsciiSymbol("<error>"); | 161 return Factory::LookupAsciiSymbol("<error>"); |
160 } | 162 } |
161 Handle<String> result_string = Handle<String>::cast(result); | 163 Handle<String> result_string = Handle<String>::cast(result); |
162 // A string that has been obtained from JS code in this way is | 164 // A string that has been obtained from JS code in this way is |
163 // likely to be a complicated ConsString of some sort. We flatten it | 165 // likely to be a complicated ConsString of some sort. We flatten it |
164 // here to improve the efficiency of converting it to a C string and | 166 // here to improve the efficiency of converting it to a C string and |
165 // other operations that are likely to take place (see GetLocalizedMessage | 167 // other operations that are likely to take place (see GetLocalizedMessage |
166 // for example). | 168 // for example). |
167 FlattenString(result_string); | 169 FlattenString(result_string); |
168 return result_string; | 170 return result_string; |
169 } | 171 } |
170 | 172 |
171 | 173 |
172 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { | 174 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { |
173 HandleScope scope; | 175 HandleScope scope; |
174 return GetMessage(data)->ToCString(DISALLOW_NULLS); | 176 return GetMessage(data)->ToCString(DISALLOW_NULLS); |
175 } | 177 } |
176 | 178 |
177 | 179 |
178 } } // namespace v8::internal | 180 } } // namespace v8::internal |
OLD | NEW |