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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "WorkerContext.h" | 45 #include "WorkerContext.h" |
46 | 46 |
47 namespace WebCore { | 47 namespace WebCore { |
48 | 48 |
49 template<> | 49 template<> |
50 void WeakHandleListener<V8AbstractEventListener>::callback(v8::Isolate*, v8::Per
sistent<v8::Value>, V8AbstractEventListener* listener) | 50 void WeakHandleListener<V8AbstractEventListener>::callback(v8::Isolate*, v8::Per
sistent<v8::Value>, V8AbstractEventListener* listener) |
51 { | 51 { |
52 listener->m_listener.clear(); | 52 listener->m_listener.clear(); |
53 } | 53 } |
54 | 54 |
55 V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, const WorldCo
ntextHandle& worldContext, v8::Isolate* isolate) | 55 V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, PassRefPtr<DO
MWrapperWorld> world, v8::Isolate* isolate) |
56 : EventListener(JSEventListenerType) | 56 : EventListener(JSEventListenerType) |
57 , m_isAttribute(isAttribute) | 57 , m_isAttribute(isAttribute) |
58 , m_worldContext(worldContext) | 58 , m_world(world) |
59 , m_isolate(isolate) | 59 , m_isolate(isolate) |
60 { | 60 { |
61 ThreadLocalInspectorCounters::current().incrementCounter(ThreadLocalInspecto
rCounters::JSEventListenerCounter); | 61 ThreadLocalInspectorCounters::current().incrementCounter(ThreadLocalInspecto
rCounters::JSEventListenerCounter); |
62 } | 62 } |
63 | 63 |
64 V8AbstractEventListener::~V8AbstractEventListener() | 64 V8AbstractEventListener::~V8AbstractEventListener() |
65 { | 65 { |
66 if (!m_listener.isEmpty()) { | 66 if (!m_listener.isEmpty()) { |
67 v8::HandleScope scope; | 67 v8::HandleScope scope; |
68 V8EventListenerList::clearWrapper(v8::Local<v8::Object>::New(m_listener.
get()), m_isAttribute); | 68 V8EventListenerList::clearWrapper(v8::Local<v8::Object>::New(m_listener.
get()), m_isAttribute); |
69 } | 69 } |
70 ThreadLocalInspectorCounters::current().decrementCounter(ThreadLocalInspecto
rCounters::JSEventListenerCounter); | 70 ThreadLocalInspectorCounters::current().decrementCounter(ThreadLocalInspecto
rCounters::JSEventListenerCounter); |
71 } | 71 } |
72 | 72 |
73 void V8AbstractEventListener::handleEvent(ScriptExecutionContext* context, Event
* event) | 73 void V8AbstractEventListener::handleEvent(ScriptExecutionContext* context, Event
* event) |
74 { | 74 { |
75 // Don't reenter V8 if execution was terminated in this instance of V8. | 75 // Don't reenter V8 if execution was terminated in this instance of V8. |
76 if (context->isJSExecutionForbidden()) | 76 if (context->isJSExecutionForbidden()) |
77 return; | 77 return; |
78 | 78 |
79 ASSERT(event); | 79 ASSERT(event); |
80 | 80 |
81 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. | 81 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. |
82 // See issue 889829. | 82 // See issue 889829. |
83 RefPtr<V8AbstractEventListener> protect(this); | 83 RefPtr<V8AbstractEventListener> protect(this); |
84 | 84 |
85 v8::HandleScope handleScope; | 85 v8::HandleScope handleScope; |
86 | 86 |
87 v8::Local<v8::Context> v8Context = toV8Context(context, worldContext()); | 87 v8::Local<v8::Context> v8Context = toV8Context(context, world()); |
88 if (v8Context.IsEmpty()) | 88 if (v8Context.IsEmpty()) |
89 return; | 89 return; |
90 | 90 |
91 // Enter the V8 context in which to perform the event handling. | 91 // Enter the V8 context in which to perform the event handling. |
92 v8::Context::Scope scope(v8Context); | 92 v8::Context::Scope scope(v8Context); |
93 | 93 |
94 // Get the V8 wrapper for the event object. | 94 // Get the V8 wrapper for the event object. |
95 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), v8Cont
ext->GetIsolate()); | 95 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), v8Cont
ext->GetIsolate()); |
96 if (jsEvent.IsEmpty()) | 96 if (jsEvent.IsEmpty()) |
97 return; | 97 return; |
98 invokeEventHandler(context, event, jsEvent); | 98 invokeEventHandler(context, event, jsEvent); |
99 } | 99 } |
100 | 100 |
101 void V8AbstractEventListener::setListenerObject(v8::Handle<v8::Object> listener) | 101 void V8AbstractEventListener::setListenerObject(v8::Handle<v8::Object> listener) |
102 { | 102 { |
103 m_listener.set(listener); | 103 m_listener.set(listener); |
104 WeakHandleListener<V8AbstractEventListener>::makeWeak(m_isolate, m_listener.
get(), this); | 104 WeakHandleListener<V8AbstractEventListener>::makeWeak(m_isolate, m_listener.
get(), this); |
105 } | 105 } |
106 | 106 |
107 void V8AbstractEventListener::invokeEventHandler(ScriptExecutionContext* context
, Event* event, v8::Handle<v8::Value> jsEvent) | 107 void V8AbstractEventListener::invokeEventHandler(ScriptExecutionContext* context
, Event* event, v8::Handle<v8::Value> jsEvent) |
108 { | 108 { |
109 // If jsEvent is empty, attempt to set it as a hidden value would crash v8. | 109 // If jsEvent is empty, attempt to set it as a hidden value would crash v8. |
110 if (jsEvent.IsEmpty()) | 110 if (jsEvent.IsEmpty()) |
111 return; | 111 return; |
112 | 112 |
113 v8::Local<v8::Context> v8Context = toV8Context(context, worldContext()); | 113 v8::Local<v8::Context> v8Context = toV8Context(context, world()); |
114 if (v8Context.IsEmpty()) | 114 if (v8Context.IsEmpty()) |
115 return; | 115 return; |
116 | 116 |
117 // We push the event being processed into the global object, so that it can
be exposed by DOMWindow's bindings. | 117 // We push the event being processed into the global object, so that it can
be exposed by DOMWindow's bindings. |
118 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(); | 118 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(); |
119 v8::Local<v8::Value> returnValue; | 119 v8::Local<v8::Value> returnValue; |
120 | 120 |
121 // In beforeunload/unload handlers, we want to avoid sleeps which do tight l
oops of calling Date.getTime(). | 121 // In beforeunload/unload handlers, we want to avoid sleeps which do tight l
oops of calling Date.getTime(). |
122 if (event->type() == eventNames().beforeunloadEvent || event->type() == even
tNames().unloadEvent) | 122 if (event->type() == eventNames().beforeunloadEvent || event->type() == even
tNames().unloadEvent) |
123 DateExtension::get()->setAllowSleep(false); | 123 DateExtension::get()->setAllowSleep(false); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // http://www.w3.org/TR/html5/webappapis.html#event-handler-attributes | 175 // http://www.w3.org/TR/html5/webappapis.html#event-handler-attributes |
176 return returnValue->IsBoolean() && !returnValue->BooleanValue(); | 176 return returnValue->IsBoolean() && !returnValue->BooleanValue(); |
177 } | 177 } |
178 | 178 |
179 v8::Local<v8::Object> V8AbstractEventListener::getReceiverObject(ScriptExecution
Context* context, Event* event) | 179 v8::Local<v8::Object> V8AbstractEventListener::getReceiverObject(ScriptExecution
Context* context, Event* event) |
180 { | 180 { |
181 if (!m_listener.isEmpty() && !m_listener->IsFunction()) | 181 if (!m_listener.isEmpty() && !m_listener->IsFunction()) |
182 return v8::Local<v8::Object>::New(m_listener.get()); | 182 return v8::Local<v8::Object>::New(m_listener.get()); |
183 | 183 |
184 EventTarget* target = event->currentTarget(); | 184 EventTarget* target = event->currentTarget(); |
185 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), toV8Con
text(context, worldContext())->GetIsolate()); | 185 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), toV8Con
text(context, world())->GetIsolate()); |
186 if (value.IsEmpty()) | 186 if (value.IsEmpty()) |
187 return v8::Local<v8::Object>(); | 187 return v8::Local<v8::Object>(); |
188 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value)); | 188 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value)); |
189 } | 189 } |
190 | 190 |
191 } // namespace WebCore | 191 } // namespace WebCore |
OLD | NEW |