Mercurial > my-ubiquity-commands
comparison pseudo-weak-refs/index.html @ 18:08bddf757ed8
Added pseudo-weak-refs feed.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 25 Apr 2009 13:38:25 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:f3e03596fcf9 | 18:08bddf757ed8 |
---|---|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
4 <head> | |
5 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
6 <link rel="stylesheet" type="text/css" media="all" | |
7 href="index.css" /> | |
8 <link rel="commands" href="pseudo-weak-refs.js"/> | |
9 <title>Pseudo Weak References for Web Content</title> | |
10 </head> | |
11 <body> | |
12 <div id="container"> | |
13 <div id="content"> | |
14 <h1>Pseudo Weak References for Web Content</h1> | |
15 <p>This Ubiquity feed provides pseudo weak reference functionality to | |
16 web content, for the purpose of making it easier to debug memory | |
17 management issues. Specifically, it adds two new functions to | |
18 the global <tt>window</tt> object of all web pages:</p> | |
19 <ul> | |
20 <li><tt>PseudoWeakRef(object)</tt> is a constructor that makes a | |
21 pseudo-weak reference for the object. The returned object has one | |
22 method, <tt>exists()</tt>, which returns whether or not the | |
23 referent still exists.</li> | |
24 <li><tt>forceGC()</tt> forces garbage collection.</li> | |
25 </ul> | |
26 <p>Here's some example code:</p> | |
27 <script id="tests"> | |
28 function testExistsReturnsFalse() { | |
29 var object = new Object(); | |
30 var weak = new PseudoWeakRef(object); | |
31 | |
32 // Destroy our one strong reference to the object, leaving it available | |
33 // for garbage collection. | |
34 object = null; | |
35 | |
36 forceGC(); | |
37 if (weak.exists()) | |
38 throw new Error("weak referent should not exist"); | |
39 } | |
40 </script> | |
41 <p>The above source code is actually part of the test suite for this | |
42 feed. <span id="test-result">If this feed were installed, the suite would | |
43 run now.</span></p> | |
44 <p>The source code for this feed can be viewed | |
45 at <a href="pseudo-weak-refs.js">pseudo-weak-refs.js</a>.</p> | |
46 </div> | |
47 <div id="messages"> | |
48 <span id="tests-failed">The suite was run, but some tests failed.</span> | |
49 <span id="tests-passed">The suite was run, and all tests passed.</span> | |
50 </div> | |
51 </div> | |
52 <script> | |
53 function testExistsReturnsTrue() { | |
54 var object = new Object(); | |
55 var weak = new PseudoWeakRef(object); | |
56 forceGC(); | |
57 if (!weak.exists()) | |
58 throw new Error("weak referent should exist"); | |
59 } | |
60 | |
61 function onLoad() { | |
62 function $(id) { return document.getElementById(id); } | |
63 | |
64 $("tests").innerHTML = $("tests").innerHTML.slice(1); | |
65 if (window.PseudoWeakRef && window.forceGC) { | |
66 try { | |
67 testExistsReturnsFalse(); | |
68 testExistsReturnsTrue(); | |
69 } catch (e) { | |
70 $("test-result").innerHTML = $("tests-failed").innerHTML; | |
71 throw e; | |
72 } | |
73 $("test-result").innerHTML = $("tests-passed").innerHTML; | |
74 } | |
75 } | |
76 | |
77 window.addEventListener("load", onLoad, false); | |
78 </script> | |
79 </body> | |
80 </html> |