OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 // Enter the V8 context in which to perform the event handling. | 73 // Enter the V8 context in which to perform the event handling. |
74 v8::Context::Scope scope(v8Context); | 74 v8::Context::Scope scope(v8Context); |
75 | 75 |
76 // Get the V8 wrapper for the event object. | 76 // Get the V8 wrapper for the event object. |
77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat
e); | 77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat
e); |
78 | 78 |
79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven
t)); | 79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven
t)); |
80 } | 80 } |
81 | 81 |
82 static void devtoolsFunctionInfo(v8::Handle<v8::Function> handlerFunction, v8::I
solate* isolate, int& scriptId, String& resourceName, int& lineNumber) | |
83 { | |
84 lineNumber = 1; | |
85 v8::Handle<v8::Function> originalFunction = getBoundFunction(handlerFunction
); | |
86 v8::ScriptOrigin origin = originalFunction->GetScriptOrigin(); | |
87 if (!origin.ResourceName().IsEmpty()) { | |
88 resourceName = NativeValueTraits<String>::nativeValue(origin.ResourceNam
e(), isolate); | |
89 lineNumber = originalFunction->GetScriptLineNumber() + 1; | |
90 } | |
91 if (resourceName.isEmpty()) | |
92 resourceName = "undefined"; | |
93 } | |
94 | |
95 static PassRefPtr<TraceEvent::ConvertableToTraceFormat> devtoolsTraceEventData(E
xecutionContext* context, v8::Handle<v8::Function> handlerFunction, v8::Isolate*
isolate) | |
96 { | |
97 int scriptId = 0; | |
98 String resourceName; | |
99 int lineNumber = 1; | |
100 devtoolsFunctionInfo(handlerFunction, isolate, scriptId, resourceName, lineN
umber); | |
101 return InspectorFunctionCallEvent::data(context, scriptId, resourceName, lin
eNumber); | |
102 } | |
103 | |
104 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Exec
utionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) | 82 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Exec
utionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) |
105 { | 83 { |
106 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); | 84 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); |
107 v8::Local<v8::Object> receiver = getReceiverObject(context, event); | 85 v8::Local<v8::Object> receiver = getReceiverObject(context, event); |
108 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) | 86 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) |
109 return v8::Local<v8::Value>(); | 87 return v8::Local<v8::Value>(); |
110 | 88 |
111 v8::Isolate* isolate = toIsolate(context); | 89 v8::Isolate* isolate = toIsolate(context); |
112 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devtoolsTraceEventData(context, handlerFunction, isolate)); | 90 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devToolsTraceEventData(context, handlerFunction, isolate)); |
| 91 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
113 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. | 92 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. |
114 InspectorInstrumentationCookie cookie; | 93 InspectorInstrumentationCookie cookie; |
115 if (InspectorInstrumentation::timelineAgentEnabled(context)) { | 94 if (InspectorInstrumentation::timelineAgentEnabled(context)) { |
116 int scriptId = 0; | 95 int scriptId = 0; |
117 String resourceName; | 96 String resourceName; |
118 int lineNumber = 1; | 97 int lineNumber = 1; |
119 devtoolsFunctionInfo(handlerFunction, isolate, scriptId, resourceName, l
ineNumber); | 98 GetDevToolsFunctionInfo(handlerFunction, isolate, scriptId, resourceName
, lineNumber); |
120 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r
esourceName, lineNumber); | 99 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r
esourceName, lineNumber); |
121 } | 100 } |
122 | 101 |
123 v8::Handle<v8::Value> parameters[1] = { jsEvent }; | 102 v8::Handle<v8::Value> parameters[1] = { jsEvent }; |
124 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction,
context, receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate); | 103 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction,
context, receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate); |
125 | 104 |
126 InspectorInstrumentation::didCallFunction(cookie); | 105 InspectorInstrumentation::didCallFunction(cookie); |
127 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); | 106 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); |
128 | 107 |
129 return result; | 108 return result; |
130 } | 109 } |
131 | 110 |
132 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Execut
ionContext* context, Event* event) | 111 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Execut
ionContext* context, Event* event) |
133 { | 112 { |
134 v8::Local<v8::Object> listener = getListenerObject(context); | 113 v8::Local<v8::Object> listener = getListenerObject(context); |
135 | 114 |
136 if (!listener.IsEmpty() && !listener->IsFunction()) | 115 if (!listener.IsEmpty() && !listener->IsFunction()) |
137 return listener; | 116 return listener; |
138 | 117 |
139 EventTarget* target = event->currentTarget(); | 118 EventTarget* target = event->currentTarget(); |
140 v8::Isolate* isolate = toIsolate(context); | 119 v8::Isolate* isolate = toIsolate(context); |
141 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), isolate
); | 120 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), isolate
); |
142 if (value.IsEmpty()) | 121 if (value.IsEmpty()) |
143 return v8::Local<v8::Object>(); | 122 return v8::Local<v8::Object>(); |
144 return v8::Local<v8::Object>::New(isolate, v8::Handle<v8::Object>::Cast(valu
e)); | 123 return v8::Local<v8::Object>::New(isolate, v8::Handle<v8::Object>::Cast(valu
e)); |
145 } | 124 } |
146 | 125 |
147 } // namespace WebCore | 126 } // namespace WebCore |
OLD | NEW |