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

Side by Side Diff: src/messages.cc

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 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/mark-compact.cc ('k') | src/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 15 matching lines...) Expand all
61 PrintF("%s\n", msg); 60 PrintF("%s\n", msg);
62 } 61 }
63 62
64 63
65 Handle<JSMessageObject> MessageHandler::MakeMessageObject( 64 Handle<JSMessageObject> MessageHandler::MakeMessageObject(
66 const char* type, 65 const char* type,
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 Handle<JSArray> stack_frames) { 69 Handle<JSArray> stack_frames) {
71 Handle<String> type_handle = Factory::LookupAsciiSymbol(type); 70 Handle<String> type_handle = FACTORY->LookupAsciiSymbol(type);
72 Handle<FixedArray> arguments_elements = 71 Handle<FixedArray> arguments_elements =
73 Factory::NewFixedArray(args.length()); 72 FACTORY->NewFixedArray(args.length());
74 for (int i = 0; i < args.length(); i++) { 73 for (int i = 0; i < args.length(); i++) {
75 arguments_elements->set(i, *args[i]); 74 arguments_elements->set(i, *args[i]);
76 } 75 }
77 Handle<JSArray> arguments_handle = 76 Handle<JSArray> arguments_handle =
78 Factory::NewJSArrayWithElements(arguments_elements); 77 FACTORY->NewJSArrayWithElements(arguments_elements);
79 78
80 int start = 0; 79 int start = 0;
81 int end = 0; 80 int end = 0;
82 Handle<Object> script_handle = Factory::undefined_value(); 81 Handle<Object> script_handle = FACTORY->undefined_value();
83 if (loc) { 82 if (loc) {
84 start = loc->start_pos(); 83 start = loc->start_pos();
85 end = loc->end_pos(); 84 end = loc->end_pos();
86 script_handle = GetScriptWrapper(loc->script()); 85 script_handle = GetScriptWrapper(loc->script());
87 } 86 }
88 87
89 Handle<Object> stack_trace_handle = stack_trace.is_null() 88 Handle<Object> stack_trace_handle = stack_trace.is_null()
90 ? Factory::undefined_value() 89 ? FACTORY->undefined_value()
91 : Handle<Object>::cast(stack_trace); 90 : Handle<Object>::cast(stack_trace);
92 91
93 Handle<Object> stack_frames_handle = stack_frames.is_null() 92 Handle<Object> stack_frames_handle = stack_frames.is_null()
94 ? Factory::undefined_value() 93 ? FACTORY->undefined_value()
95 : Handle<Object>::cast(stack_frames); 94 : Handle<Object>::cast(stack_frames);
96 95
97 Handle<JSMessageObject> message = 96 Handle<JSMessageObject> message =
98 Factory::NewJSMessageObject(type_handle, 97 FACTORY->NewJSMessageObject(type_handle,
99 arguments_handle, 98 arguments_handle,
100 start, 99 start,
101 end, 100 end,
102 script_handle, 101 script_handle,
103 stack_trace_handle, 102 stack_trace_handle,
104 stack_frames_handle); 103 stack_frames_handle);
105 104
106 return message; 105 return message;
107 } 106 }
108 107
109 108
110 void MessageHandler::ReportMessage(MessageLocation* loc, 109 void MessageHandler::ReportMessage(MessageLocation* loc,
111 Handle<Object> message) { 110 Handle<Object> message) {
112 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); 111 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
113 112
114 v8::NeanderArray global_listeners(Factory::message_listeners()); 113 v8::NeanderArray global_listeners(FACTORY->message_listeners());
115 int global_length = global_listeners.length(); 114 int global_length = global_listeners.length();
116 if (global_length == 0) { 115 if (global_length == 0) {
117 DefaultMessageReport(loc, message); 116 DefaultMessageReport(loc, message);
118 } else { 117 } else {
119 for (int i = 0; i < global_length; i++) { 118 for (int i = 0; i < global_length; i++) {
120 HandleScope scope; 119 HandleScope scope;
121 if (global_listeners.get(i)->IsUndefined()) continue; 120 if (global_listeners.get(i)->IsUndefined()) continue;
122 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i))); 121 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i)));
123 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0))); 122 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0)));
124 v8::MessageCallback callback = 123 v8::MessageCallback callback =
125 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy()); 124 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy());
126 Handle<Object> callback_data(listener.get(1)); 125 Handle<Object> callback_data(listener.get(1));
127 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); 126 callback(api_message_obj, v8::Utils::ToLocal(callback_data));
128 } 127 }
129 } 128 }
130 } 129 }
131 130
132 131
133 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { 132 Handle<String> MessageHandler::GetMessage(Handle<Object> data) {
134 Handle<String> fmt_str = Factory::LookupAsciiSymbol("FormatMessage"); 133 Handle<String> fmt_str = FACTORY->LookupAsciiSymbol("FormatMessage");
135 Handle<JSFunction> fun = 134 Handle<JSFunction> fun =
136 Handle<JSFunction>(JSFunction::cast( 135 Handle<JSFunction>(
137 Top::builtins()->GetPropertyNoExceptionThrown(*fmt_str))); 136 JSFunction::cast(
137 Isolate::Current()->js_builtins_object()->
138 GetPropertyNoExceptionThrown(*fmt_str)));
138 Object** argv[1] = { data.location() }; 139 Object** argv[1] = { data.location() };
139 140
140 bool caught_exception; 141 bool caught_exception;
141 Handle<Object> result = 142 Handle<Object> result =
142 Execution::TryCall(fun, Top::builtins(), 1, argv, &caught_exception); 143 Execution::TryCall(fun,
144 Isolate::Current()->js_builtins_object(), 1, argv, &caught_exception);
143 145
144 if (caught_exception || !result->IsString()) { 146 if (caught_exception || !result->IsString()) {
145 return Factory::LookupAsciiSymbol("<error>"); 147 return FACTORY->LookupAsciiSymbol("<error>");
146 } 148 }
147 Handle<String> result_string = Handle<String>::cast(result); 149 Handle<String> result_string = Handle<String>::cast(result);
148 // A string that has been obtained from JS code in this way is 150 // A string that has been obtained from JS code in this way is
149 // likely to be a complicated ConsString of some sort. We flatten it 151 // likely to be a complicated ConsString of some sort. We flatten it
150 // here to improve the efficiency of converting it to a C string and 152 // here to improve the efficiency of converting it to a C string and
151 // other operations that are likely to take place (see GetLocalizedMessage 153 // other operations that are likely to take place (see GetLocalizedMessage
152 // for example). 154 // for example).
153 FlattenString(result_string); 155 FlattenString(result_string);
154 return result_string; 156 return result_string;
155 } 157 }
156 158
157 159
158 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { 160 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) {
159 HandleScope scope; 161 HandleScope scope;
160 return GetMessage(data)->ToCString(DISALLOW_NULLS); 162 return GetMessage(data)->ToCString(DISALLOW_NULLS);
161 } 163 }
162 164
163 165
164 } } // namespace v8::internal 166 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mark-compact.cc ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698