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

Side by Side Diff: Source/bindings/v8/V8WorkerGlobalScopeEventListener.cpp

Issue 293053007: V8AbstractEventListener should hold a ScriptState (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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
OLDNEW
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
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* context, Ev ent* event)
54 { 54 {
55 if (!context) 55 if (!context)
56 return; 56 return;
57 57
58 // The callback function on XMLHttpRequest can clear the event listener and destroys 'this' object. Keep a local reference to it. 58 // The callback function on XMLHttpRequest can clear the event listener and destroys 'this' object. Keep a local reference to it.
59 // See issue 889829. 59 // See issue 889829.
60 RefPtr<V8AbstractEventListener> protect(this); 60 RefPtr<V8AbstractEventListener> protect(this);
61 61
62 v8::Isolate* isolate = toIsolate(context);
63 v8::HandleScope handleScope(isolate);
64
65 WorkerScriptController* script = toWorkerGlobalScope(context)->script(); 62 WorkerScriptController* script = toWorkerGlobalScope(context)->script();
66 if (!script) 63 if (!script)
67 return; 64 return;
68 65
69 v8::Handle<v8::Context> v8Context = script->context(); 66 if (scriptState()->contextIsEmpty())
70 if (v8Context.IsEmpty())
71 return; 67 return;
72 68 ScriptState::Scope scope(scriptState());
73 // Enter the V8 context in which to perform the event handling.
74 v8::Context::Scope scope(v8Context);
75 69
76 // Get the V8 wrapper for the event object. 70 // Get the V8 wrapper for the event object.
77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat e); 71 v8::Handle<v8::Value> jsEvent = toV8(event, scriptState()->context()->Global (), isolate());
78 72
79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven t)); 73 invokeEventHandler(event, v8::Local<v8::Value>::New(isolate(), jsEvent));
80 } 74 }
81 75
82 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Exec utionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) 76 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Exec utionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
83 { 77 {
84 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); 78 v8::Local<v8::Function> handlerFunction = getListenerFunction(context);
85 v8::Local<v8::Object> receiver = getReceiverObject(context, event); 79 v8::Local<v8::Object> receiver = getReceiverObject(event);
86 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) 80 if (handlerFunction.IsEmpty() || receiver.IsEmpty())
87 return v8::Local<v8::Value>(); 81 return v8::Local<v8::Value>();
88 82
89 v8::Isolate* isolate = toIsolate(context); 83 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()); 84 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. 85 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing.
93 InspectorInstrumentationCookie cookie; 86 InspectorInstrumentationCookie cookie;
94 if (InspectorInstrumentation::timelineAgentEnabled(context)) { 87 if (InspectorInstrumentation::timelineAgentEnabled(context)) {
95 int scriptId = 0; 88 int scriptId = 0;
96 String resourceName; 89 String resourceName;
97 int lineNumber = 1; 90 int lineNumber = 1;
98 GetDevToolsFunctionInfo(handlerFunction, isolate, scriptId, resourceName , lineNumber); 91 GetDevToolsFunctionInfo(handlerFunction, isolate(), scriptId, resourceNa me, lineNumber);
99 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r esourceName, lineNumber); 92 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r esourceName, lineNumber);
100 } 93 }
101 94
102 v8::Handle<v8::Value> parameters[1] = { jsEvent }; 95 v8::Handle<v8::Value> parameters[1] = { jsEvent };
103 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction, context, receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate); 96 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction, context, receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate());
104 97
105 InspectorInstrumentation::didCallFunction(cookie); 98 InspectorInstrumentation::didCallFunction(cookie);
106 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", "data", InspectorUpdateCountersEvent::data()); 99 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", "data", InspectorUpdateCountersEvent::data());
107 100
108 return result; 101 return result;
109 } 102 }
110 103
111 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Execut ionContext* context, Event* event) 104 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Event* event)
112 { 105 {
113 v8::Local<v8::Object> listener = getListenerObject(context); 106 v8::Local<v8::Object> listener = getListenerObject(scriptState()->executionC ontext());
114 107
115 if (!listener.IsEmpty() && !listener->IsFunction()) 108 if (!listener.IsEmpty() && !listener->IsFunction())
116 return listener; 109 return listener;
117 110
118 EventTarget* target = event->currentTarget(); 111 EventTarget* target = event->currentTarget();
119 v8::Isolate* isolate = toIsolate(context); 112 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()) 113 if (value.IsEmpty())
122 return v8::Local<v8::Object>(); 114 return v8::Local<v8::Object>();
123 return v8::Local<v8::Object>::New(isolate, v8::Handle<v8::Object>::Cast(valu e)); 115 return v8::Local<v8::Object>::New(isolate(), v8::Handle<v8::Object>::Cast(va lue));
124 } 116 }
125 117
126 } // namespace WebCore 118 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698