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

Side by Side Diff: Source/bindings/dart/DartEventListener.cpp

Issue 24492005: Keep a strong handle to an event listener during handleEvent (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Reupload Created 7 years, 2 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
« no previous file with comments | « Source/bindings/dart/DartEventListener.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return; 89 return;
90 90
91 ASSERT(event); 91 ASSERT(event);
92 92
93 DartIsolateScope scope(m_isolate); 93 DartIsolateScope scope(m_isolate);
94 DartApiScope apiScope; 94 DartApiScope apiScope;
95 95
96 // The callback function on XMLHttpRequest can clear the event listener and destroys 'this' object. Keep a local reference to it. 96 // The callback function on XMLHttpRequest can clear the event listener and destroys 'this' object. Keep a local reference to it.
97 // See issue 889829. 97 // See issue 889829.
98 RefPtr<DartEventListener> protect(this); 98 RefPtr<DartEventListener> protect(this);
99 // Keep a strong handle to the listener.
100 Dart_Handle listener = Dart_HandleFromWeakPersistent(m_listener);
99 101
100 // Get the Dart wrapper for the event object. 102 // Get the Dart wrapper for the event object.
101 Dart_Handle dartEvent = DartEvent::toDart(event); 103 Dart_Handle dartEvent = DartEvent::toDart(event);
102 ASSERT(dartEvent); 104 ASSERT(dartEvent);
103 105
104 // FIXME: consider if DateExtension manipulations are necessary and if yes ( most probably), 106 // FIXME: consider if DateExtension manipulations are necessary and if yes ( most probably),
105 // factor out common logic. For example by introducing EventProcessScope RAI I to manage DateExtension. 107 // factor out common logic. For example by introducing EventProcessScope RAI I to manage DateExtension.
106 Dart_Handle result = callListenerFunction(context, dartEvent, event); 108 Dart_Handle result = callListenerFunction(context, listener, dartEvent);
107 if (Dart_IsError(result)) { 109 if (Dart_IsError(result)) {
108 DartUtilities::reportProblem(context, result); 110 DartUtilities::reportProblem(context, result);
109 return; 111 return;
110 } 112 }
111 113
112 if (Dart_IsString(result)) { 114 if (Dart_IsString(result)) {
113 if (event->storesResultAsString()) 115 if (event->storesResultAsString())
114 event->storeResult(DartUtilities::toString(result)); 116 event->storeResult(DartUtilities::toString(result));
115 } 117 }
116 } 118 }
117 119
118 EventListener* DartEventListener::toNative(Dart_Handle handle, Dart_Handle& exce ption) 120 EventListener* DartEventListener::toNative(Dart_Handle handle, Dart_Handle& exce ption)
119 { 121 {
120 if (Dart_IsNull(handle)) { 122 if (Dart_IsNull(handle)) {
121 exception = Dart_NewStringFromCString("Null passed where Dart closure is expected"); 123 exception = Dart_NewStringFromCString("Null passed where Dart closure is expected");
122 return 0; 124 return 0;
123 } 125 }
124 126
125 if (!Dart_IsClosure(handle)) { 127 if (!Dart_IsClosure(handle)) {
126 exception = Dart_NewStringFromCString("Not a Dart closure passed"); 128 exception = Dart_NewStringFromCString("Not a Dart closure passed");
127 return 0; 129 return 0;
128 } 130 }
129 131
130 return createOrFetch(handle); 132 return createOrFetch(handle);
131 } 133 }
132 134
133 Dart_Handle DartEventListener::callListenerFunction(ScriptExecutionContext* cont ext, Dart_Handle dartEvent, Event* event) 135 Dart_Handle DartEventListener::callListenerFunction(ScriptExecutionContext* cont ext, Dart_Handle listener, Dart_Handle dartEvent)
134 { 136 {
135 ASSERT(m_listener); 137 ASSERT(listener);
136 138
137 DartController* dartController = DartController::retrieve(context); 139 DartController* dartController = DartController::retrieve(context);
138 if (!dartController) 140 if (!dartController)
139 return Dart_Error("Internal error: failed to fetch Dart controller"); 141 return Dart_Error("Internal error: failed to fetch Dart controller");
140 142
141 Dart_Handle parameters[1] = { dartEvent }; 143 Dart_Handle parameters[1] = { dartEvent };
142 return dartController->callFunction(Dart_HandleFromWeakPersistent(m_listener ), 1, parameters); 144 return dartController->callFunction(listener, 1, parameters);
143 } 145 }
144 146
145 } 147 }
OLDNEW
« no previous file with comments | « Source/bindings/dart/DartEventListener.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698