| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 m_columnNumber = 0; | 55 m_columnNumber = 0; |
| 56 if (m_isInline && m_frame->document()->tokenizer()) { | 56 if (m_isInline && m_frame->document()->tokenizer()) { |
| 57 m_lineNumber = m_frame->document()->tokenizer()->lineNumber(); | 57 m_lineNumber = m_frame->document()->tokenizer()->lineNumber(); |
| 58 m_columnNumber = m_frame->document()->tokenizer()->columnNumber(); | 58 m_columnNumber = m_frame->document()->tokenizer()->columnNumber(); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 void V8AbstractEventListener::HandleEventHelper(v8::Handle<v8::Context> context, | 63 void V8AbstractEventListener::HandleEventHelper(v8::Handle<v8::Context> context, |
| 64 Event* event, | 64 Event* event, |
| 65 v8::Handle<v8::Value> jsevent, |
| 65 bool isWindowEvent) { | 66 bool isWindowEvent) { |
| 66 | 67 |
| 67 // Enter the V8 context in which to perform the event handling. | |
| 68 v8::Context::Scope scope(context); | |
| 69 | |
| 70 // Get the V8 wrapper for the event object. | |
| 71 v8::Handle<v8::Value> jsevent = V8Proxy::EventToV8Object(event); | |
| 72 | |
| 73 // For compatibility, we store the event object as a property on the window | 68 // For compatibility, we store the event object as a property on the window |
| 74 // called "event". Because this is the global namespace, we save away any | 69 // called "event". Because this is the global namespace, we save away any |
| 75 // existing "event" property, and then restore it after executing the | 70 // existing "event" property, and then restore it after executing the |
| 76 // javascript handler. | 71 // javascript handler. |
| 77 v8::Local<v8::String> event_symbol = v8::String::NewSymbol("event"); | 72 v8::Local<v8::String> event_symbol = v8::String::NewSymbol("event"); |
| 78 v8::Local<v8::Value> saved_evt; | 73 v8::Local<v8::Value> saved_evt; |
| 79 v8::Local<v8::Value> ret; | 74 v8::Local<v8::Value> ret; |
| 80 | 75 |
| 81 { | 76 { |
| 82 // Catch exceptions thrown in the event handler so they do not | 77 // Catch exceptions thrown in the event handler so they do not |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_frame); | 147 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_frame); |
| 153 if (context.IsEmpty()) | 148 if (context.IsEmpty()) |
| 154 return; | 149 return; |
| 155 | 150 |
| 156 // m_frame can removed by the callback function, | 151 // m_frame can removed by the callback function, |
| 157 // protect it until the callback function returns. | 152 // protect it until the callback function returns. |
| 158 RefPtr<Frame> protector(m_frame); | 153 RefPtr<Frame> protector(m_frame); |
| 159 | 154 |
| 160 IF_DEVEL(log_info(frame, "Handling DOM event", m_frame->document()->URL())); | 155 IF_DEVEL(log_info(frame, "Handling DOM event", m_frame->document()->URL())); |
| 161 | 156 |
| 162 HandleEventHelper(context, event, isWindowEvent); | 157 { |
| 158 // Enter the V8 context in which to perform the event handling. |
| 159 v8::Context::Scope scope(context); |
| 160 |
| 161 // Get the V8 wrapper for the event object. |
| 162 v8::Handle<v8::Value> jsevent = V8Proxy::EventToV8Object(event); |
| 163 |
| 164 HandleEventHelper(context, event, jsevent, isWindowEvent); |
| 165 } |
| 163 | 166 |
| 164 Document::updateDocumentsRendering(); | 167 Document::updateDocumentsRendering(); |
| 165 } | 168 } |
| 166 | 169 |
| 167 | 170 |
| 168 void V8AbstractEventListener::DisposeListenerObject() { | 171 void V8AbstractEventListener::DisposeListenerObject() { |
| 169 if (!m_listener.IsEmpty()) { | 172 if (!m_listener.IsEmpty()) { |
| 170 #ifndef NDEBUG | 173 #ifndef NDEBUG |
| 171 V8Proxy::UnregisterGlobalHandle(this, m_listener); | 174 V8Proxy::UnregisterGlobalHandle(this, m_listener); |
| 172 #endif | 175 #endif |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 // and destroys 'this' object. Keep a local reference of it. | 503 // and destroys 'this' object. Keep a local reference of it. |
| 501 // See issue 889829 | 504 // See issue 889829 |
| 502 RefPtr<V8AbstractEventListener> self(this); | 505 RefPtr<V8AbstractEventListener> self(this); |
| 503 | 506 |
| 504 v8::HandleScope handle_scope; | 507 v8::HandleScope handle_scope; |
| 505 | 508 |
| 506 v8::Handle<v8::Context> context = m_proxy->GetContext(); | 509 v8::Handle<v8::Context> context = m_proxy->GetContext(); |
| 507 if (context.IsEmpty()) | 510 if (context.IsEmpty()) |
| 508 return; | 511 return; |
| 509 | 512 |
| 510 HandleEventHelper(context, event, isWindowEvent); | 513 { |
| 514 // Enter the V8 context in which to perform the event handling. |
| 515 v8::Context::Scope scope(context); |
| 516 |
| 517 // Get the V8 wrapper for the event object. |
| 518 v8::Handle<v8::Value> jsevent = |
| 519 WorkerContextExecutionProxy::EventToV8Object(event); |
| 520 |
| 521 HandleEventHelper(context, event, jsevent, isWindowEvent); |
| 522 } |
| 511 } | 523 } |
| 512 | 524 |
| 513 v8::Local<v8::Value> V8WorkerContextEventListener::CallListenerFunction( | 525 v8::Local<v8::Value> V8WorkerContextEventListener::CallListenerFunction( |
| 514 v8::Handle<v8::Value> jsevent, Event* event, bool isWindowEvent) { | 526 v8::Handle<v8::Value> jsevent, Event* event, bool isWindowEvent) { |
| 515 v8::Local<v8::Function> handler_func = GetListenerFunction(); | 527 v8::Local<v8::Function> handler_func = GetListenerFunction(); |
| 516 if (handler_func.IsEmpty()) return v8::Local<v8::Value>(); | 528 if (handler_func.IsEmpty()) return v8::Local<v8::Value>(); |
| 517 | 529 |
| 518 v8::Local<v8::Object> receiver = GetReceiverObject(event, isWindowEvent); | 530 v8::Local<v8::Object> receiver = GetReceiverObject(event, isWindowEvent); |
| 519 v8::Handle<v8::Value> parameters[1] = {jsevent}; | 531 v8::Handle<v8::Value> parameters[1] = {jsevent}; |
| 520 | 532 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 542 | 554 |
| 543 EventTarget* target = event->currentTarget(); | 555 EventTarget* target = event->currentTarget(); |
| 544 v8::Handle<v8::Value> value = | 556 v8::Handle<v8::Value> value = |
| 545 WorkerContextExecutionProxy::EventTargetToV8Object(target); | 557 WorkerContextExecutionProxy::EventTargetToV8Object(target); |
| 546 if (value.IsEmpty()) return v8::Local<v8::Object>(); | 558 if (value.IsEmpty()) return v8::Local<v8::Object>(); |
| 547 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value)); | 559 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value)); |
| 548 } | 560 } |
| 549 #endif // WORKERS | 561 #endif // WORKERS |
| 550 | 562 |
| 551 } // namespace WebCore | 563 } // namespace WebCore |
| OLD | NEW |