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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 | 114 |
115 void V8AbstractEventListener::invokeEventHandler(ScriptState* scriptState, | 115 void V8AbstractEventListener::invokeEventHandler(ScriptState* scriptState, |
116 Event* event, | 116 Event* event, |
117 v8::Local<v8::Value> jsEvent) { | 117 v8::Local<v8::Value> jsEvent) { |
118 if (!event->canBeDispatchedInWorld(world())) | 118 if (!event->canBeDispatchedInWorld(world())) |
119 return; | 119 return; |
120 | 120 |
121 v8::Local<v8::Value> returnValue; | 121 v8::Local<v8::Value> returnValue; |
122 { | 122 { |
123 // Catch exceptions thrown in the event handler so they do not propagate to
javascript code that caused the event to fire. | 123 // Catch exceptions thrown in the event handler so they do not propagate to |
| 124 // javascript code that caused the event to fire. |
124 v8::TryCatch tryCatch(isolate()); | 125 v8::TryCatch tryCatch(isolate()); |
125 tryCatch.SetVerbose(true); | 126 tryCatch.SetVerbose(true); |
126 | 127 |
127 // Save the old 'event' property so we can restore it later. | 128 // Save the old 'event' property so we can restore it later. |
128 v8::Local<v8::Value> savedEvent = V8HiddenValue::getHiddenValue( | 129 v8::Local<v8::Value> savedEvent = V8HiddenValue::getHiddenValue( |
129 scriptState, scriptState->context()->Global(), | 130 scriptState, scriptState->context()->Global(), |
130 V8HiddenValue::event(isolate())); | 131 V8HiddenValue::event(isolate())); |
131 tryCatch.Reset(); | 132 tryCatch.Reset(); |
132 | 133 |
133 // Make the event available in the global object, so LocalDOMWindow can expo
se it. | 134 // Make the event available in the global object, so LocalDOMWindow can |
| 135 // expose it. |
134 V8HiddenValue::setHiddenValue(scriptState, scriptState->context()->Global(), | 136 V8HiddenValue::setHiddenValue(scriptState, scriptState->context()->Global(), |
135 V8HiddenValue::event(isolate()), jsEvent); | 137 V8HiddenValue::event(isolate()), jsEvent); |
136 tryCatch.Reset(); | 138 tryCatch.Reset(); |
137 | 139 |
138 returnValue = callListenerFunction(scriptState, jsEvent, event); | 140 returnValue = callListenerFunction(scriptState, jsEvent, event); |
139 if (tryCatch.HasCaught()) | 141 if (tryCatch.HasCaught()) |
140 event->target()->uncaughtExceptionInEventHandler(); | 142 event->target()->uncaughtExceptionInEventHandler(); |
141 | 143 |
142 if (!tryCatch.CanContinue()) { // Result of TerminateExecution(). | 144 if (!tryCatch.CanContinue()) { // Result of TerminateExecution(). |
143 if (scriptState->getExecutionContext()->isWorkerGlobalScope()) | 145 if (scriptState->getExecutionContext()->isWorkerGlobalScope()) |
144 toWorkerGlobalScope(scriptState->getExecutionContext()) | 146 toWorkerGlobalScope(scriptState->getExecutionContext()) |
145 ->scriptController() | 147 ->scriptController() |
146 ->forbidExecution(); | 148 ->forbidExecution(); |
147 return; | 149 return; |
148 } | 150 } |
149 tryCatch.Reset(); | 151 tryCatch.Reset(); |
150 | 152 |
151 // Restore the old event. This must be done for all exit paths through this
method. | 153 // Restore the old event. This must be done for all exit paths through this |
| 154 // method. |
152 if (savedEvent.IsEmpty()) | 155 if (savedEvent.IsEmpty()) |
153 V8HiddenValue::setHiddenValue( | 156 V8HiddenValue::setHiddenValue( |
154 scriptState, scriptState->context()->Global(), | 157 scriptState, scriptState->context()->Global(), |
155 V8HiddenValue::event(isolate()), v8::Undefined(isolate())); | 158 V8HiddenValue::event(isolate()), v8::Undefined(isolate())); |
156 else | 159 else |
157 V8HiddenValue::setHiddenValue( | 160 V8HiddenValue::setHiddenValue( |
158 scriptState, scriptState->context()->Global(), | 161 scriptState, scriptState->context()->Global(), |
159 V8HiddenValue::event(isolate()), savedEvent); | 162 V8HiddenValue::event(isolate()), savedEvent); |
160 tryCatch.Reset(); | 163 tryCatch.Reset(); |
161 } | 164 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 DEFINE_TRACE(V8AbstractEventListener) { | 223 DEFINE_TRACE(V8AbstractEventListener) { |
221 visitor->trace(m_workerGlobalScope); | 224 visitor->trace(m_workerGlobalScope); |
222 EventListener::trace(visitor); | 225 EventListener::trace(visitor); |
223 } | 226 } |
224 | 227 |
225 DEFINE_TRACE_WRAPPERS(V8AbstractEventListener) { | 228 DEFINE_TRACE_WRAPPERS(V8AbstractEventListener) { |
226 visitor->traceWrappers(&m_listener); | 229 visitor->traceWrappers(&m_listener); |
227 } | 230 } |
228 | 231 |
229 } // namespace blink | 232 } // namespace blink |
OLD | NEW |