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

Side by Side Diff: Source/WebCore/bindings/dart/DartUtilities.cpp

Issue 9837116: DOM wrappers that are not retained from Dart should be collected. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Address comments. Created 8 years, 8 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/WebCore/bindings/dart/DartUtilities.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 // Copyright 2011, Google Inc. 1 // Copyright 2011, 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 static DartDOMData* domDataForIsolate(Dart_Isolate isolate) 256 static DartDOMData* domDataForIsolate(Dart_Isolate isolate)
257 { 257 {
258 IsolateToDartDOMDataMap::iterator it = isolateToDartDOMDataMap().find(isolat e); 258 IsolateToDartDOMDataMap::iterator it = isolateToDartDOMDataMap().find(isolat e);
259 ASSERT(it != isolateToDartDOMDataMap().end()); 259 ASSERT(it != isolateToDartDOMDataMap().end());
260 return it->second; 260 return it->second;
261 } 261 }
262 262
263 static DartDOMData* currentDOMData() 263 static DartDOMData* currentDOMData()
264 { 264 {
265 return domDataForIsolate(DartIsolate::current()->isolate()); 265 return domDataForIsolate(Dart_CurrentIsolate());
266 } 266 }
267 267
268 void DartUtilities::registerDOMIsolate(Dart_Isolate isolate, PassRefPtr<DartAppl icationLoader> applicationLoader, ScriptExecutionContext* context) 268 void DartUtilities::registerDOMIsolate(Dart_Isolate isolate, PassRefPtr<DartAppl icationLoader> applicationLoader, ScriptExecutionContext* context)
269 { 269 {
270 ASSERT(!isolateToDartDOMDataMap().contains(isolate)); 270 ASSERT(!isolateToDartDOMDataMap().contains(isolate));
271 isolateToDartDOMDataMap().set(isolate, new DartDOMData(applicationLoader, co ntext)); 271 isolateToDartDOMDataMap().set(isolate, new DartDOMData(applicationLoader, co ntext));
272 ASSERT(context->isDocument()); 272 ASSERT(context->isDocument());
273 } 273 }
274 274
275 void DartUtilities::registerPureIsolate(Dart_Isolate isolate, PassRefPtr<DartApp licationLoader> applicationLoader) 275 void DartUtilities::registerPureIsolate(Dart_Isolate isolate, PassRefPtr<DartApp licationLoader> applicationLoader)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 375 }
376 376
377 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack() 377 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack()
378 { 378 {
379 // FIXME: wrap current dart call stack as ScriptCallStack. 379 // FIXME: wrap current dart call stack as ScriptCallStack.
380 Vector<ScriptCallFrame> wrappedCallFrames; 380 Vector<ScriptCallFrame> wrappedCallFrames;
381 wrappedCallFrames.append(ScriptCallFrame("undefined", "undefined", 0)); 381 wrappedCallFrames.append(ScriptCallFrame("undefined", "undefined", 0));
382 return ScriptCallStack::create(wrappedCallFrames); 382 return ScriptCallStack::create(wrappedCallFrames);
383 } 383 }
384 384
385 class DartWeakCallback
386 {
387 public:
388 DartWeakCallback(void* peer, Dart_WeakPersistentHandleFinalizer weakCallback )
389 : peer(peer)
390 , weakCallback(weakCallback)
391 , object(0)
392 {
393 }
394
395 void* peer;
Anton Muhin 2012/03/30 11:36:00 nit: m_peer, m_weakCallback, etc.?
396 Dart_WeakPersistentHandleFinalizer weakCallback;
397 Dart_Handle object;
398 };
399
400 static void weakCallbackWrapper(Dart_Handle object, void* peer)
401 {
402 DartWeakCallback* callback = static_cast<DartWeakCallback*>(peer);
403 DartUtilities::domDataForCurrentIsolate()->weakCallbacks()->remove(callback) ;
404 (*callback->weakCallback)(object, callback->peer);
405 delete callback;
406 }
407
408 Dart_Handle DartUtilities::createWeakPersistentHandle(Dart_Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback)
409 {
410 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback);
411 callback->object = Dart_NewWeakPersistentHandle(object, callback, &weakCallb ackWrapper);
412 domDataForCurrentIsolate()->weakCallbacks()->add(callback);
413 return callback->object;
414 }
415
416 void DartUtilities::disposeWeakPersistentHandles()
417 {
418 DartWeakCallbacks* weakCallbacks = domDataForCurrentIsolate()->weakCallbacks ();
419 for (DartWeakCallbacks::iterator it = weakCallbacks->begin(); it != weakCall backs->end(); ++it) {
420 DartWeakCallback* callback = *it;
421 (*callback->weakCallback)(callback->object, callback->peer);
422 delete callback;
423 }
424 weakCallbacks->clear();
425 }
426
385 const uint8_t* DartUtilities::fullSnapshot() 427 const uint8_t* DartUtilities::fullSnapshot()
386 { 428 {
387 static const uint8_t snapshotBuffer[] = { 429 static const uint8_t snapshotBuffer[] = {
388 // DartSnapshot.bytes is generated by build system. 430 // DartSnapshot.bytes is generated by build system.
389 #include "DartSnapshot.bytes" 431 #include "DartSnapshot.bytes"
390 }; 432 };
391 return snapshotBuffer; 433 return snapshotBuffer;
392 } 434 }
393 435
394 void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r esult) 436 void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r esult)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 ASSERT(!Dart_IsError(library)); 485 ASSERT(!Dart_IsError(library));
444 Dart_Handle args[2] = {0}; 486 Dart_Handle args[2] = {0};
445 args[0] = Dart_NewString(fileName); 487 args[0] = Dart_NewString(fileName);
446 args[1] = Dart_NewInteger(lineNumber); 488 args[1] = Dart_NewInteger(lineNumber);
447 Dart_Handle result = Dart_InvokeStatic(library, Dart_NewString("Utils"), Dar t_NewString("makeNotImplementedException"), 2, args); 489 Dart_Handle result = Dart_InvokeStatic(library, Dart_NewString("Utils"), Dar t_NewString("makeNotImplementedException"), 2, args);
448 ASSERT(!Dart_IsError(result)); 490 ASSERT(!Dart_IsError(result));
449 return result; 491 return result;
450 } 492 }
451 493
452 } 494 }
OLDNEW
« no previous file with comments | « Source/WebCore/bindings/dart/DartUtilities.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698