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 27 matching lines...) Expand all Loading... |
38 #include "bindings/v8/V8DOMWrapper.h" | 38 #include "bindings/v8/V8DOMWrapper.h" |
39 #include "bindings/v8/V8GCController.h" | 39 #include "bindings/v8/V8GCController.h" |
40 #include "bindings/v8/V8ScriptRunner.h" | 40 #include "bindings/v8/V8ScriptRunner.h" |
41 #include "bindings/v8/WorkerScriptController.h" | 41 #include "bindings/v8/WorkerScriptController.h" |
42 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
43 #include "core/inspector/InspectorTraceEvents.h" | 43 #include "core/inspector/InspectorTraceEvents.h" |
44 #include "core/workers/WorkerGlobalScope.h" | 44 #include "core/workers/WorkerGlobalScope.h" |
45 | 45 |
46 namespace WebCore { | 46 namespace WebCore { |
47 | 47 |
48 V8WorkerGlobalScopeEventListener::V8WorkerGlobalScopeEventListener(v8::Local<v8:
:Object> listener, bool isInline, v8::Isolate* isolate) | 48 V8WorkerGlobalScopeEventListener::V8WorkerGlobalScopeEventListener(v8::Local<v8:
:Object> listener, bool isInline, ScriptState* scriptState) |
49 : V8EventListener(listener, isInline, isolate) | 49 : V8EventListener(listener, isInline, scriptState) |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 void V8WorkerGlobalScopeEventListener::handleEvent(ExecutionContext* context, Ev
ent* event) | 53 void V8WorkerGlobalScopeEventListener::handleEvent(ExecutionContext*, Event* eve
nt) |
54 { | 54 { |
55 if (!context) | |
56 return; | |
57 | |
58 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. | 55 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. |
59 // See issue 889829. | 56 // See issue 889829. |
60 RefPtr<V8AbstractEventListener> protect(this); | 57 RefPtr<V8AbstractEventListener> protect(this); |
61 | 58 |
62 v8::Isolate* isolate = toIsolate(context); | 59 WorkerScriptController* script = toWorkerGlobalScope(scriptState()->executio
nContext())->script(); |
63 v8::HandleScope handleScope(isolate); | |
64 | |
65 WorkerScriptController* script = toWorkerGlobalScope(context)->script(); | |
66 if (!script) | 60 if (!script) |
67 return; | 61 return; |
68 | 62 |
69 v8::Handle<v8::Context> v8Context = script->context(); | 63 if (scriptState()->contextIsEmpty()) |
70 if (v8Context.IsEmpty()) | |
71 return; | 64 return; |
72 | 65 ScriptState::Scope scope(scriptState()); |
73 // Enter the V8 context in which to perform the event handling. | |
74 v8::Context::Scope scope(v8Context); | |
75 | 66 |
76 // Get the V8 wrapper for the event object. | 67 // Get the V8 wrapper for the event object. |
77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat
e); | 68 v8::Handle<v8::Value> jsEvent = toV8(event, scriptState()->context()->Global
(), isolate()); |
78 | 69 |
79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven
t)); | 70 invokeEventHandler(event, v8::Local<v8::Value>::New(isolate(), jsEvent)); |
80 } | 71 } |
81 | 72 |
82 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Exec
utionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) | 73 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Exec
utionContext*, v8::Handle<v8::Value> jsEvent, Event* event) |
83 { | 74 { |
84 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); | 75 v8::Local<v8::Function> handlerFunction = getListenerFunction(scriptState()-
>executionContext()); |
85 v8::Local<v8::Object> receiver = getReceiverObject(context, event); | 76 v8::Local<v8::Object> receiver = getReceiverObject(event); |
86 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) | 77 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) |
87 return v8::Local<v8::Value>(); | 78 return v8::Local<v8::Value>(); |
88 | 79 |
89 v8::Isolate* isolate = toIsolate(context); | 80 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devToolsTraceEventData(scriptState()->executionContext(), handlerFuncti
on, 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()); | 81 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
92 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. | 82 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. |
93 InspectorInstrumentationCookie cookie; | 83 InspectorInstrumentationCookie cookie; |
94 if (InspectorInstrumentation::timelineAgentEnabled(context)) { | 84 if (InspectorInstrumentation::timelineAgentEnabled(scriptState()->executionC
ontext())) { |
95 int scriptId = 0; | 85 int scriptId = 0; |
96 String resourceName; | 86 String resourceName; |
97 int lineNumber = 1; | 87 int lineNumber = 1; |
98 GetDevToolsFunctionInfo(handlerFunction, isolate, scriptId, resourceName
, lineNumber); | 88 GetDevToolsFunctionInfo(handlerFunction, isolate(), scriptId, resourceNa
me, lineNumber); |
99 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r
esourceName, lineNumber); | 89 cookie = InspectorInstrumentation::willCallFunction(scriptState()->execu
tionContext(), scriptId, resourceName, lineNumber); |
100 } | 90 } |
101 | 91 |
102 v8::Handle<v8::Value> parameters[1] = { jsEvent }; | 92 v8::Handle<v8::Value> parameters[1] = { jsEvent }; |
103 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction,
context, receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate); | 93 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction,
scriptState()->executionContext(), receiver, WTF_ARRAY_LENGTH(parameters), param
eters, isolate()); |
104 | 94 |
105 InspectorInstrumentation::didCallFunction(cookie); | 95 InspectorInstrumentation::didCallFunction(cookie); |
106 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); | 96 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); |
107 | 97 |
108 return result; | 98 return result; |
109 } | 99 } |
110 | 100 |
111 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Execut
ionContext* context, Event* event) | 101 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Event*
event) |
112 { | 102 { |
113 v8::Local<v8::Object> listener = getListenerObject(context); | 103 v8::Local<v8::Object> listener = getListenerObject(scriptState()->executionC
ontext()); |
114 | 104 |
115 if (!listener.IsEmpty() && !listener->IsFunction()) | 105 if (!listener.IsEmpty() && !listener->IsFunction()) |
116 return listener; | 106 return listener; |
117 | 107 |
118 EventTarget* target = event->currentTarget(); | 108 EventTarget* target = event->currentTarget(); |
119 v8::Isolate* isolate = toIsolate(context); | 109 v8::Handle<v8::Value> value = toV8(target, scriptState()->context()->Global(
), isolate()); |
120 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), isolate
); | |
121 if (value.IsEmpty()) | 110 if (value.IsEmpty()) |
122 return v8::Local<v8::Object>(); | 111 return v8::Local<v8::Object>(); |
123 return v8::Local<v8::Object>::New(isolate, v8::Handle<v8::Object>::Cast(valu
e)); | 112 return v8::Local<v8::Object>::New(isolate(), v8::Handle<v8::Object>::Cast(va
lue)); |
124 } | 113 } |
125 | 114 |
126 } // namespace WebCore | 115 } // namespace WebCore |
OLD | NEW |