incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmue...@apache.org
Subject [16/27] git commit: closes #11
Date Tue, 03 Jan 2012 18:39:31 GMT
closes #11


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/commit/048ebd64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/tree/048ebd64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/diff/048ebd64

Branch: refs/heads/master
Commit: 048ebd64dac56ab7a902b428bfb7bec03ebaf36f
Parents: 0c13336
Author: Patrick Mueller <pmuellr@yahoo.com>
Authored: Wed Oct 12 13:21:28 2011 -0400
Committer: Patrick Mueller <pmuellr@yahoo.com>
Committed: Wed Oct 12 13:21:28 2011 -0400

----------------------------------------------------------------------
 weinre.build/scripts/build-target-scripts.py       |   30 +-
 weinre.web/client/weinre/check-for-webkit.js       |    4 +-
 weinre.web/client/weinre/client.css                |   24 +-
 weinre.web/demo/weinre-demo-min.html               |   15 +-
 weinre.web/demo/weinre-demo-pieces.html            |   19 +-
 weinre.web/demo/weinre-demo.html                   |   14 +-
 weinre.web/demo/weinre-demo.js                     |  102 ++++++--
 weinre.web/modules/weinre/client/Client.coffee     |    4 +-
 .../modules/weinre/client/ConnectorList.coffee     |    1 +
 weinre.web/modules/weinre/common/Ex.coffee         |    3 +-
 weinre.web/modules/weinre/common/HookLib.coffee    |  114 ++++++++
 weinre.web/modules/weinre/common/Native.coffee     |   43 ---
 .../modules/weinre/common/WebSocketXhr.coffee      |   23 +-
 .../weinre/target/ExceptionalCallbacks.coffee      |  100 +++++++
 weinre.web/modules/weinre/target/HookSites.coffee  |   38 +++
 .../weinre/target/InjectedScriptHostImpl.coffee    |    2 +-
 weinre.web/modules/weinre/target/Target.coffee     |   33 ++-
 weinre.web/modules/weinre/target/Timeline.coffee   |  204 ++++++---------
 .../modules/weinre/target/WiDOMStorageImpl.coffee  |   55 ++--
 .../modules/weinre/target/WiDatabaseImpl.coffee    |   18 +-
 weinre.web/versions.js                             |   12 +-
 21 files changed, 557 insertions(+), 301 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.build/scripts/build-target-scripts.py
----------------------------------------------------------------------
diff --git a/weinre.build/scripts/build-target-scripts.py b/weinre.build/scripts/build-target-scripts.py
index c74c2e7..b82e6fa 100644
--- a/weinre.build/scripts/build-target-scripts.py
+++ b/weinre.build/scripts/build-target-scripts.py
@@ -3,7 +3,7 @@
 # ---
 # weinre is available under *either* the terms of the modified BSD license *or* the
 # MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
-# 
+#
 # Copyright (c) 2010, 2011 IBM Corporation
 # ---
 
@@ -15,47 +15,47 @@ import optparse
 
 #--------------------------------------------------------------------
 def main():
-    
+
     #----------------------------------------------------------------
     if len(sys.argv) < 4:
         error("expecting parameters piecesHtmlFile srcDir outputDir")
-    
+
     iFileName   = sys.argv[1]
     srcDirName  = sys.argv[2]
     oDirName    = sys.argv[3]
-    
+
     if not os.path.exists(iFileName):   error("input file not found: '" + iFileName + "'")
     if not os.path.exists(srcDirName):  error("source directory not found: '" + srcDirName + "'")
     if not os.path.isdir(srcDirName):   error("source directory not a directory: '" + srcDirName + "'")
     if not os.path.exists(oDirName):    error("output directory not found: '" + oDirName + "'")
     if not os.path.isdir(oDirName):     error("output directory not a directory: '" + oDirName + "'")
-    
+
     #----------------------------------------------------------------
     with open(iFileName, "r") as iFile:
         lines = iFile.readlines()
-        
+
     #----------------------------------------------------------------
     scripts     = []
     scriptNames = {}
     scriptSrc   = {}
     scriptMin   = {}
     scriptSrcPattern = re.compile(r'.*?<script\s+src\s*=\s*"/(.*?)"\s*>\s*</script>.*')
-    
+
     for line in lines:
         match = scriptSrcPattern.match(line)
         if not match: continue
-        
+
         baseScriptFile = match.group(1)
         scriptFile = os.path.join(srcDirName, baseScriptFile)
         if scriptFile == "weinre-demo.js": continue
         if not os.path.exists(scriptFile):   error("script file not found: '" + scriptFile + "'")
-        
+
         scripts.append(scriptFile)
         scriptNames[scriptFile] = baseScriptFile
 
         with open(scriptFile, "r") as iFile:
             scriptSrc[scriptFile] = iFile.read()
-            
+
         scriptMin[scriptFile] = min(scriptSrc[scriptFile])
 
         # log("read: %s" % scriptFile)
@@ -73,7 +73,7 @@ def writeMergedFile(oFileName, scripts, scriptNames, srcs):
 
     lines = []
     lines.append(";(function(){")
-    
+
     for script in scripts:
         lines.append("//==================================================")
         lines.append("// file: " + scriptNames[script])
@@ -82,13 +82,13 @@ def writeMergedFile(oFileName, scripts, scriptNames, srcs):
         lines.append(";")
         lines.append("")
 
-    lines.append("require('weinre/target/Target').getClass().main()")
+    lines.append("require('weinre/target/Target').main()")
     lines.append("})();")
     targetScript = "\n".join(lines)
-    
+
     with open(oFileName, "w") as oFile:
         oFile.write(targetScript)
-    
+
     log("generated: %s" % oFileName)
 
 #--------------------------------------------------------------------
@@ -102,7 +102,7 @@ def min(script):
     script = patternCommentCPP.sub( "", script)
     script = patternIndent.sub(     "", script)
     script = patternBlankLine.sub(  "", script)
-    
+
     return script
 
 #--------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/client/weinre/check-for-webkit.js
----------------------------------------------------------------------
diff --git a/weinre.web/client/weinre/check-for-webkit.js b/weinre.web/client/weinre/check-for-webkit.js
index 7077ec8..249e80d 100644
--- a/weinre.web/client/weinre/check-for-webkit.js
+++ b/weinre.web/client/weinre/check-for-webkit.js
@@ -1,10 +1,10 @@
 /*
  * weinre is available under *either* the terms of the modified BSD license *or* the
  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- * 
+ *
  * Copyright (c) 2010, 2011 IBM Corporation
  */
 
 if (!navigator.userAgent.match(/webkit/i)) {
-	alert("This web page is only designed to work in WebKit-based browsers.  Sorry.  Best of luck.")
+    alert("This web page is only designed to work in WebKit-based browsers.  Sorry.  Best of luck.")
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/client/weinre/client.css
----------------------------------------------------------------------
diff --git a/weinre.web/client/weinre/client.css b/weinre.web/client/weinre/client.css
index 196a9cb..383cf96 100644
--- a/weinre.web/client/weinre/client.css
+++ b/weinre.web/client/weinre/client.css
@@ -1,7 +1,7 @@
 /*
  * weinre is available under *either* the terms of the modified BSD license *or* the
  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- * 
+ *
  * Copyright (c) 2010, 2011 IBM Corporation
  */
 
@@ -20,46 +20,46 @@
 }
 
 .panel.resources .cookie-storage-tree-item {
-	display: none;
+    display: none;
 }
 
 .panel.resources .frame-storage-tree-item {
-	display: none;
+    display: none;
 }
 
 .panel.resources .application-cache-storage-tree-item {
-	display: none;
+    display: none;
 }
 
 .panel.timeline .resources-size-graph-sidebar-item {
-	display: none;
+    display: none;
 }
 
 #main-status-bar .timeline-category-rendering {
-	display: none;
+    display: none;
 }
 
 #search {
-	display: none;
+    display: none;
 }
 
 #search-toolbar-label {
-	display: none;
+    display: none;
 }
 
 .weinre-connector-item {
     font-size: 140%;
 }
- 
+
 .weinre-connector-item.target {
-    text-decoration: underline; 
+    text-decoration: underline;
     color: blue;
 }
- 
+
 .weinre-connector-item.target.connected {
     color: #0D0;
 }
- 
+
 .weinre-connector-item.closed {
     color: #B00;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/demo/weinre-demo-min.html
----------------------------------------------------------------------
diff --git a/weinre.web/demo/weinre-demo-min.html b/weinre.web/demo/weinre-demo-min.html
index 95532ee..ef2554a 100644
--- a/weinre.web/demo/weinre-demo-min.html
+++ b/weinre.web/demo/weinre-demo-min.html
@@ -1,7 +1,7 @@
 <!--
  * weinre is available under *either* the terms of the modified BSD license *or* the
  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- * 
+ *
  * Copyright (c) 2010, 2011 IBM Corporation
 -->
 
@@ -10,18 +10,25 @@
 <meta name="viewport" content="user-scalable=no, width=device-width, height=device-height">
 <title>weinre demo</title>
 <link rel="stylesheet" href="weinre-demo.css">
-<script src="weinre-demo.js"></script>
+<script>try {window.WeinreServerId = location.hash.split("#")[1]} catch(e) {window.WeinreServerId = "anonymous"}</script>
 <script src="/target/target-script-min.js"></script>
+<script src="weinre-demo.js"></script>
 
 <script type="text/javascript">
-    require("weinre/common/Weinre").getClass().showNotImplemented()
+    require("weinre/common/Weinre").showNotImplemented()
 </script>
-
 </head>
 
 <body onload="onLoad()">
 <input id="button-start-stuff" type="button" value="start stuff">
 
+<p>exceptions in callbacks<p>
+<input id="button-error-DOM-event"    type="button" value="DOM addEventHandler">
+<input id="button-error-window-event" type="button" value="window addEventHandler">
+<input id="button-error-XHR-event"    type="button" value="XHR addEventHandler">
+<input id="button-error-setTimeout"   type="button" value="setTimeout()">
+<input id="button-error-setInterval"  type="button" value="setInterval()">
+
 <h1>this is a green h1</h1>
 <h1 class="blue">this is a blue h1</h1>
 <h1 style="color:red">this is a red h1</h1>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/demo/weinre-demo-pieces.html
----------------------------------------------------------------------
diff --git a/weinre.web/demo/weinre-demo-pieces.html b/weinre.web/demo/weinre-demo-pieces.html
index bb38a17..04d87d9 100644
--- a/weinre.web/demo/weinre-demo-pieces.html
+++ b/weinre.web/demo/weinre-demo-pieces.html
@@ -9,7 +9,9 @@
 <head>
 <meta name="viewport" content="user-scalable=no, width=device-width, height=device-height">
 <title>weinre demo</title>
-
+<link rel="stylesheet" href="weinre-demo.css">
+<script>window.WeinreServerURL = location.protocol + "//" + location.hostname + ":" + location.port</script>
+<script>try {window.WeinreServerId = location.hash.split("#")[1]} catch(e) {window.WeinreServerId = "anonymous"}</script>
 <script src="/modjewel-require.js"></script>
 <script type="text/javascript">require("modjewel").warnOnRecursiveRequire(true)</script>
 <script src="/weinre/common/Ex.transportd.js"></script>
@@ -21,9 +23,9 @@
 <script src="/weinre/common/Binding.transportd.js"></script>
 <script src="/weinre/common/Callback.transportd.js"></script>
 <script src="/weinre/common/EventListeners.transportd.js"></script>
-<script src="/weinre/common/Native.transportd.js"></script>
 <script src="/weinre/common/IDGenerator.transportd.js"></script>
 <script src="/weinre/common/MethodNamer.transportd.js"></script>
+<script src="/weinre/common/HookLib.transportd.js"></script>
 <script src="/weinre/target/Console.transportd.js"></script>
 <script src="/add-css-properties.js"></script>
 <script src="/weinre/target/CheckForProblems.transportd.js"></script>
@@ -44,20 +46,27 @@
 <script src="/weinre/target/Timeline.transportd.js"></script>
 <script src="/weinre/target/SqlStepper.transportd.js"></script>
 <script src="/weinre/target/WeinreExtraClientCommandsImpl.transportd.js"></script>
+<script src="/weinre/target/HookSites.transportd.js"></script>
+<script src="/weinre/target/ExceptionalCallbacks.transportd.js"></script>
 <script src="/interfaces/all-json-idls-min.js"></script>
+<script src="weinre-demo.js"></script>
 
 <script type="text/javascript">
     require("weinre/common/Weinre").showNotImplemented()
     require('weinre/target/Target').main()
 </script>
-
-<link rel="stylesheet" href="weinre-demo.css">
-<script src="weinre-demo.js"></script>
 </head>
 
 <body onload="onLoad()">
 <input id="button-start-stuff" type="button" value="start stuff">
 
+<p>exceptions in callbacks<p>
+<input id="button-error-DOM-event"    type="button" value="DOM addEventHandler">
+<input id="button-error-window-event" type="button" value="window addEventHandler">
+<input id="button-error-XHR-event"    type="button" value="XHR addEventHandler">
+<input id="button-error-setTimeout"   type="button" value="setTimeout()">
+<input id="button-error-setInterval"  type="button" value="setInterval()">
+
 <h1>this is a green h1</h1>
 <h1 class="blue">this is a blue h1</h1>
 <h1 style="color:red">this is a red h1</h1>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/demo/weinre-demo.html
----------------------------------------------------------------------
diff --git a/weinre.web/demo/weinre-demo.html b/weinre.web/demo/weinre-demo.html
index 5c93023..a499331 100644
--- a/weinre.web/demo/weinre-demo.html
+++ b/weinre.web/demo/weinre-demo.html
@@ -1,7 +1,7 @@
 <!--
  * weinre is available under *either* the terms of the modified BSD license *or* the
  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- * 
+ *
  * Copyright (c) 2010, 2011 IBM Corporation
 -->
 
@@ -10,17 +10,25 @@
 <meta name="viewport" content="user-scalable=no, width=device-width, height=device-height">
 <title>weinre demo</title>
 <link rel="stylesheet" href="weinre-demo.css">
-<script src="weinre-demo.js"></script>
+<script>try {window.WeinreServerId = location.hash.split("#")[1]} catch(e) {window.WeinreServerId = "anonymous"}</script>
 <script src="/target/target-script.js"></script>
+<script src="weinre-demo.js"></script>
 
 <script type="text/javascript">
-    require("weinre/common/Weinre").getClass().showNotImplemented()
+    require("weinre/common/Weinre").showNotImplemented()
 </script>
 </head>
 
 <body onload="onLoad()">
 <input id="button-start-stuff" type="button" value="start stuff">
 
+<p>exceptions in callbacks<p>
+<input id="button-error-DOM-event"    type="button" value="DOM addEventHandler">
+<input id="button-error-window-event" type="button" value="window addEventHandler">
+<input id="button-error-XHR-event"    type="button" value="XHR addEventHandler">
+<input id="button-error-setTimeout"   type="button" value="setTimeout()">
+<input id="button-error-setInterval"  type="button" value="setInterval()">
+
 <h1>this is a green h1</h1>
 <h1 class="blue">this is a blue h1</h1>
 <h1 style="color:red">this is a red h1</h1>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/demo/weinre-demo.js
----------------------------------------------------------------------
diff --git a/weinre.web/demo/weinre-demo.js b/weinre.web/demo/weinre-demo.js
index 32c72b5..b95a50f 100644
--- a/weinre.web/demo/weinre-demo.js
+++ b/weinre.web/demo/weinre-demo.js
@@ -1,7 +1,7 @@
 /*
  * weinre is available under *either* the terms of the modified BSD license *or* the
  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- * 
+ *
  * Copyright (c) 2011 IBM Corporation
  */
 
@@ -10,10 +10,15 @@ var started = false
 
 var buttonStartStuff
 var buttonClearOutput
-var outputElement 
+var buttonErrorDOMEvent
+var buttonErrorWindowEvent
+var buttonErrorXHREvent
+var buttonErrorSetTimeout
+var buttonErrorSetInterval
+var outputElement
 var storageIndex = 0
 var db
-var otherDB 
+var otherDB
 
 // set the id based on the hash
 var hash = location.href.split("#")[1]
@@ -22,43 +27,89 @@ window.WeinreServerId = hash
 
 //------------------------------------------------------------------------------
 function onLoad() {
-    if (!buttonStartStuff)  buttonStartStuff  = document.getElementById("button-start-stuff")
-    if (!buttonClearOutput) buttonClearOutput = document.getElementById("button-clear-output")
-    if (!outputElement)     outputElement     = document.getElementById("output")
-    
+    if (!buttonStartStuff)       buttonStartStuff       = document.getElementById("button-start-stuff")
+    if (!buttonClearOutput)      buttonClearOutput      = document.getElementById("button-clear-output")
+    if (!buttonErrorDOMEvent)    buttonErrorDOMEvent    = document.getElementById("button-error-DOM-event")
+    if (!buttonErrorWindowEvent) buttonErrorWindowEvent = document.getElementById("button-error-window-event")
+    if (!buttonErrorXHREvent)    buttonErrorXHREvent    = document.getElementById("button-error-XHR-event")
+    if (!buttonErrorSetTimeout)  buttonErrorSetTimeout  = document.getElementById("button-error-setTimeout")
+    if (!buttonErrorSetInterval) buttonErrorSetInterval = document.getElementById("button-error-setInterval")
+    if (!outputElement)          outputElement          = document.getElementById("output")
+
     buttonStartStuff.addEventListener("click", function() {
         lastClickTime = new Date().toString()
         if (db) db.transaction(addClick)
-        
+
         openTheOtherDatabase()
-        
+
         if (!started) {
             buttonStartStuff.value = "stop stuff"
             startStuff()
         }
         else {
             buttonStartStuff.value = "start stuff"
-            stopStuff()      
+            stopStuff()
         }
         started = !started
     })
-    
+
+    buttonErrorDOMEvent.addEventListener("click", function buttonClicked() {
+        willThrowError()
+    })
+
+    buttonErrorWindowEvent.addEventListener("click", function() {
+        var event = document.createEvent("Events")
+        event.initEvent("demo", true, true)
+        window.dispatchEvent(event)
+    })
+
+    window.addEventListener("demo", willThrowError)
+
+    buttonErrorXHREvent.addEventListener("click", function() {
+        var xhr = new XMLHttpRequest()
+        xhr.addEventListener("readystatechange", willThrowError)
+        xhr.open("GET", "something.that.doesn't.exist")
+        xhr.send()
+    })
+
+    buttonErrorSetTimeout.addEventListener("click", function() {
+        setTimeout(willThrowError, 1000)
+    })
+
+    buttonErrorSetInterval.addEventListener("click", function() {
+        var intervalID
+
+        setTimeout(function() {clearInterval(intervalID)}, 3000)
+
+        intervalID = setInterval(willThrowError, 1000)
+    })
+
     buttonClearOutput.addEventListener("click", function() {
         outputElement.innerHTML = ""
     })
-    
+
     openTheDatabase()
 }
 
 //------------------------------------------------------------------------------
+function willThrowError() {
+    throwsError()
+}
+
+function throwsError() {
+    x = null
+    x.doSomething()
+}
+
+//------------------------------------------------------------------------------
 var interval
 
 function startStuff() {
     if (window.localStorage)   window.localStorage.clear()
     if (window.sessionStorage) window.sessionStorage.clear()
-    
+
     storageIndex = 0
-    
+
     interval = setInterval(intervalStuff, 1000)
 }
 
@@ -70,38 +121,33 @@ function stopStuff() {
 function intervalStuff() {
 
     var message = "doing interval stuff at " + new Date()
-    
+
     // add a timeout
     setTimeout(function() { console.log(message)}, 333)
-    
+
     // add a timeline marker
     console.markTimeline(message)
-    
+
     // write to local- and sessionStorage
     if (window.localStorage) {
         var smessage = message + " (local)"
         window.localStorage.setItem(  "item-" + storageIndex, smessage)
     }
-    
+
     if (window.sessionStorage) {
         var smessage = message + " (session)"
         window.sessionStorage.setItem("item-" + storageIndex, smessage)
     }
     storageIndex++
-    
+
     // write the message to the page
     output(message)
-    
+
     // do an XHR
     var xhr = new XMLHttpRequest()
     // xhr.addEventListener("readystatechange", function() {logXhr(this)})
     xhr.open("GET", "../target/target-script.js", true)
     xhr.send()
-    
-    // cause an error
-    var empty = null
-    empty.x = 1
-    
 }
 
 //------------------------------------------------------------------------------
@@ -132,7 +178,7 @@ function clearDatabase(tx, resultSet) {
 function createDatabase(tx) {
     var schema = "clicks (id integer primary key, date text)"
     var sql = "create table if not exists " + schema
-    
+
     tx.executeSql(sql, null, clearDatabase, sqlError);
 }
 
@@ -140,7 +186,7 @@ function createDatabase(tx) {
 function createDatabase_other(tx) {
     var schema = "clicks_other (id integer primary key, other text)"
     var sql = "create table if not exists " + schema
-    
+
     tx.executeSql(sql, null, null, sqlError);
 }
 
@@ -155,7 +201,7 @@ function openTheDatabase() {
 //------------------------------------------------------------------------------
 function openTheOtherDatabase() {
     if (otherDB) return
-    
+
     if (window.openDatabase) {
         otherDB = window.openDatabase("clicks_other_db", "1.0", "clicks_other_db", 8192)
         otherDB.transaction(createDatabase_other)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/client/Client.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/client/Client.coffee b/weinre.web/modules/weinre/client/Client.coffee
index eecd963..514ba97 100644
--- a/weinre.web/modules/weinre/client/Client.coffee
+++ b/weinre.web/modules/weinre/client/Client.coffee
@@ -6,7 +6,6 @@
 # Copyright (c) 2010, 2011 IBM Corporation
 #---------------------------------------------------------------------------------
 
-Native            = require('../common/Native')
 IDLTools          = require('../common/IDLTools')
 Callback          = require('../common/Callback')
 Weinre            = require('../common/Weinre')
@@ -110,7 +109,8 @@ module.exports = class Client
 
     #---------------------------------------------------------------------------
     cb_webSocketClosed: ->
-        Native.setTimeout (->
+
+        setTimeout (->
             WebInspector.panels.remote.connectionClosed()
             WebInspector.currentPanel = WebInspector.panels.remote
         ), 1000

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/client/ConnectorList.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/client/ConnectorList.coffee b/weinre.web/modules/weinre/client/ConnectorList.coffee
index 065787a..e1a50fb 100644
--- a/weinre.web/modules/weinre/client/ConnectorList.coffee
+++ b/weinre.web/modules/weinre/client/ConnectorList.coffee
@@ -81,6 +81,7 @@ module.exports = class ConnectorList
         else
             @setState element, "closed"
             element.addStyleClass "weinre-fade"
+
             window.setTimeout (->
                 self._remove element
             ), 5000

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/common/Ex.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/common/Ex.coffee b/weinre.web/modules/weinre/common/Ex.coffee
index e5c1591..3de56c7 100644
--- a/weinre.web/modules/weinre/common/Ex.coffee
+++ b/weinre.web/modules/weinre/common/Ex.coffee
@@ -17,7 +17,8 @@ module.exports = class Ex
 
         StackTrace.dump args
         message = "threw error: " + message if message instanceof Error
-        new Error(prefix(args, message))
+        message = prefix(args, message)
+        message
 
 #-------------------------------------------------------------------------------
 prefix = (args, string) ->

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/common/HookLib.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/common/HookLib.coffee b/weinre.web/modules/weinre/common/HookLib.coffee
new file mode 100644
index 0000000..9f2b868
--- /dev/null
+++ b/weinre.web/modules/weinre/common/HookLib.coffee
@@ -0,0 +1,114 @@
+
+#---------------------------------------------------------------------------------
+# weinre is available under *either* the terms of the modified BSD license *or* the
+# MIT License (2008). See http:#opensource.org/licenses/alphabetical for full text.
+#
+# Copyright (c) 2010, 2011 IBM Corporation
+#---------------------------------------------------------------------------------
+
+HookLib = exports
+
+#-------------------------------------------------------------------------------
+HookSites   = []
+IgnoreHooks = 0
+
+module.exports = class HookLib
+
+    #---------------------------------------------------------------------------
+    @addHookSite = (object, property) ->
+        getHookSite object, property, true
+
+    #---------------------------------------------------------------------------
+    @getHookSite = (object, property) ->
+        getHookSite object, property, false
+
+    #---------------------------------------------------------------------------
+    @ignoreHooks = (func) ->
+        try
+            IgnoreHooks++
+            result = func.call()
+        finally
+            IgnoreHooks--
+        result
+
+#-------------------------------------------------------------------------------
+getHookSite = (object, property, addIfNotFound) ->
+    i = 0
+
+    for hookSite in HookSites
+        continue  unless hookSite.object == object
+        continue  unless hookSite.property == property
+        return hookSite
+
+    return null unless addIfNotFound
+
+    hookSite = new HookSite(object, property)
+    HookSites.push hookSite
+    hookSite
+
+#-------------------------------------------------------------------------------
+class HookSite
+
+    #---------------------------------------------------------------------------
+    constructor: (object, property) ->
+        @object = object
+        @property = property
+        @target = object[property]
+        @hookss = []
+
+        hookedFunction   = getHookedFunction(@target, this)
+        object[property] = hookedFunction
+
+    #---------------------------------------------------------------------------
+    addHooks: (hooks) ->
+        @hookss.push hooks
+
+    #---------------------------------------------------------------------------
+    removeHooks: (hooks) ->
+        for i in [0..@hookss.length]
+            if @hookss[i] == hooks
+                @hookss.splice i, 1
+                return
+
+#-------------------------------------------------------------------------------
+getHookedFunction = (func, hookSite) ->
+    hookedFunction = ->
+
+        callBeforeHooks hookSite, this, arguments
+        try
+            result = func.apply(this, arguments)
+        catch e
+            callExceptHooks hookSite, this, arguments, e
+            throw e
+        finally
+            callAfterHooks hookSite, this, arguments, result
+
+        result
+
+    hookedFunction.displayName = func.displayName || func.name
+
+    hookedFunction
+
+#-------------------------------------------------------------------------------
+callBeforeHooks = (hookSite, receiver, args) ->
+    return if IgnoreHooks > 0
+
+    for hooks in hookSite.hookss
+        hooks.before.call hooks, receiver, args if hooks.before
+
+#-------------------------------------------------------------------------------
+callAfterHooks = (hookSite, receiver, args, result) ->
+    return if IgnoreHooks > 0
+
+    for hooks in hookSite.hookss
+        hooks.after.call hooks, receiver, args, result if hooks.after
+
+#-------------------------------------------------------------------------------
+callExceptHooks = (hookSite, receiver, args, e) ->
+    return if IgnoreHooks > 0
+
+    for hooks in hookSite.hookss
+        hooks.except.call hooks, receiver, args, e if hooks.except
+
+#-------------------------------------------------------------------------------
+require("../common/MethodNamer").setNamesForClass(module.exports)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/common/Native.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/common/Native.coffee b/weinre.web/modules/weinre/common/Native.coffee
deleted file mode 100644
index 04ea3c3..0000000
--- a/weinre.web/modules/weinre/common/Native.coffee
+++ /dev/null
@@ -1,43 +0,0 @@
-
-#---------------------------------------------------------------------------------
-# weinre is available under *either* the terms of the modified BSD license *or* the
-# MIT License (2008). See http:#opensource.org/licenses/alphabetical for full text.
-#
-# Copyright (c) 2010, 2011 IBM Corporation
-#---------------------------------------------------------------------------------
-
-exports.original = {}
-
-exports.original.clearInterval             = window.clearInterval
-exports.original.clearTimeout              = window.clearTimeout
-exports.original.setTimeout                = window.setTimeout
-exports.original.setInterval               = window.setInterval
-exports.original.XMLHttpRequest            = window.XMLHttpRequest
-exports.original.XMLHttpRequest_open       = window.XMLHttpRequest.prototype.open
-exports.original.LocalStorage_setItem      = window.localStorage?.setItem
-exports.original.LocalStorage_removeItem   = window.localStorage?.removeItem
-exports.original.LocalStorage_clear        = window.localStorage?.clear
-exports.original.SessionStorage_setItem    = window.sessionStorage?.setItem
-exports.original.SessionStorage_removeItem = window.sessionStorage?.removeItem
-exports.original.SessionStorage_clear      = window.sessionStorage?.clear
-exports.original.openDatabase              = window.openDatabase
-
-exports.clearInterval             = -> exports.original.clearInterval.apply( window, [].slice.call(arguments))
-exports.clearTimeout              = -> exports.original.clearTimeout.apply(  window, [].slice.call(arguments))
-exports.setInterval               = -> exports.original.setInterval.apply(   window, [].slice.call(arguments))
-exports.setTimeout                = -> exports.original.setTimeout.apply(    window, [].slice.call(arguments))
-exports.XMLHttpRequest            = -> new exports.original.XMLHttpRequest()
-exports.XMLHttpRequest_open       = -> exports.original.XMLHttpRequest_open.apply(this, [].slice.call(arguments))
-exports.LocalStorage_setItem      = -> exports.original.LocalStorage_setItem.apply(      window.localStorage,   [].slice.call(arguments))
-exports.LocalStorage_removeItem   = -> exports.original.LocalStorage_removeItem.apply(   window.localStorage,   [].slice.call(arguments))
-exports.LocalStorage_clear        = -> exports.original.LocalStorage_clear.apply(        window.localStorage,   [].slice.call(arguments))
-exports.SessionStorage_setItem    = -> exports.original.SessionStorage_setItem.apply(    window.sessionStorage, [].slice.call(arguments))
-exports.SessionStorage_removeItem = -> exports.original.SessionStorage_removeItem.apply( window.sessionStorage, [].slice.call(arguments))
-exports.SessionStorage_clear      = -> exports.original.SessionStorage_clear.apply(      window.sessionStorage, [].slice.call(arguments))
-exports.openDatabase              = -> exports.original.openDatabase.apply(              window,                [].slice.call(arguments))
-
-for own key, val of exports
-    if typeof(val) is "function"
-        val.signature   = "Native::#{key}"
-        val.displayName = key
-        val.name        = key

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/common/WebSocketXhr.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/common/WebSocketXhr.coffee b/weinre.web/modules/weinre/common/WebSocketXhr.coffee
index acc1f90..f37be52 100644
--- a/weinre.web/modules/weinre/common/WebSocketXhr.coffee
+++ b/weinre.web/modules/weinre/common/WebSocketXhr.coffee
@@ -8,10 +8,8 @@
 
 Ex             = require('./Ex')
 Weinre         = require('./Weinre')
+HookLib        = require('./HookLib')
 EventListeners = require('./EventListeners')
-Native         = require('./Native')
-
-XMLHttpRequest = Native.XMLHttpRequest
 
 #-------------------------------------------------------------------------------
 module.exports = class WebSocketXhr
@@ -94,9 +92,10 @@ module.exports = class WebSocketXhr
             @_fireEventListeners "error", message: "non-JSON response from read request"
             return
 
-        Native.setTimeout (->
-            self._readLoop()
-        ), 0
+        HookLib.ignoreHooks ->
+            setTimeout (->
+                self._readLoop()
+            ), 0
 
         for data in datum
             self._fireEventListeners "message", data: data
@@ -128,9 +127,10 @@ module.exports = class WebSocketXhr
 
         @_sendInProgress = false
 
-        Native.setTimeout (->
-            httpSocket._sendQueued()
-        ), 0
+        HookLib.ignoreHooks ->
+            setTimeout (->
+                httpSocket._sendQueued()
+            ), 0
 
     #---------------------------------------------------------------------------
     close: ->
@@ -187,7 +187,10 @@ module.exports = class WebSocketXhr
         xhr.httpSocket = this
         xhr.httpSocketHandler = handler
         xhr.onreadystatechange = _xhrEventHandler
-        xhr.open method, url, true
+
+        HookLib.ignoreHooks ->
+            xhr.open method, url, true
+
         xhr.setRequestHeader "Content-Type", "text/plain"
         xhr.send data
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/ExceptionalCallbacks.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/ExceptionalCallbacks.coffee b/weinre.web/modules/weinre/target/ExceptionalCallbacks.coffee
new file mode 100644
index 0000000..8d88e5d
--- /dev/null
+++ b/weinre.web/modules/weinre/target/ExceptionalCallbacks.coffee
@@ -0,0 +1,100 @@
+
+#---------------------------------------------------------------------------------
+# weinre is available under *either* the terms of the modified BSD license *or* the
+# MIT License (2008). See http:#opensource.org/licenses/alphabetical for full text.
+#
+# Copyright (c) 2010, 2011 IBM Corporation
+#---------------------------------------------------------------------------------
+
+Ex        = require('../common/Ex')
+HookSites = require('./HookSites')
+
+#-------------------------------------------------------------------------------
+module.exports = class ExceptionalCallbacks
+
+    @addHooks: ->
+        addHookTimer HookSites.window_setInterval, callSite_setInterval
+        addHookTimer HookSites.window_setTimeout,  callSite_setTimeout
+
+        addHookEventListener HookSites.window_addEventListener,         callSite_windowAEL
+        addHookEventListener HookSites.Node_addEventListener,           callSite_nodeAEL
+        addHookEventListener HookSites.XMLHttpRequest_addEventListener, callSite_xhrAEL
+
+#-------------------------------------------------------------------------------
+addHookTimer = (hookSite, formatter) ->
+    hookSite.addHooks
+        before:  (receiver, args) ->
+            code = args[0]
+            return unless typeof(code) is "function"
+
+            millis   = args[1]
+            callSite = formatter(millis, code)
+
+            args[0] = instrumentedCallback(code, callSite)
+
+#-------------------------------------------------------------------------------
+addHookEventListener = (hookSite, formatter) ->
+    hookSite.addHooks
+        before:  (receiver, args) ->
+            code = args[1]
+            return unless typeof(code) is "function"
+
+            event    = args[0]
+            callSite = formatter(event, code, receiver)
+
+            args[1] = instrumentedCallback(code, callSite)
+
+#-------------------------------------------------------------------------------
+instrumentedCallback = (code, callSite) ->
+    return code unless typeof(code) is "function"
+
+    instrumentedCode = ->
+        try
+            return code.apply(this, arguments)
+        catch e
+            console.log "exception in callback: #{e}"
+            console.log "  callsite: #{callSite}"
+
+            if e.stack
+                console.log "stack at time of exception:"
+                console.log e.stack
+
+            throw e
+
+    instrumentedCode
+
+#-------------------------------------------------------------------------------
+callSite_setTimeout = (time, func) ->
+    "setTimeout(#{getFunctionName(func)}, #{time})"
+
+#-------------------------------------------------------------------------------
+callSite_setInterval = (time, func) ->
+    "setInterval(#{getFunctionName(func)}, #{time})"
+
+#-------------------------------------------------------------------------------
+callSite_windowAEL = (event, func) ->
+    "window.addEventListener('#{event}', #{getFunctionName(func)})"
+
+#-------------------------------------------------------------------------------
+callSite_nodeAEL = (event, func, node) ->
+    node = node.nodeName if node.nodeName
+    "#{node}.addEventListener('#{event}', #{getFunctionName(func)})"
+
+#-------------------------------------------------------------------------------
+callSite_xhrAEL = (event, func) ->
+    "XMLHttpRequest.addEventListener('#{event}', #{getFunctionName(func)})"
+
+#-------------------------------------------------------------------------------
+getFunctionName = (func) ->
+    return func.displayName if func.displayName
+    return func.name if func.name
+    return '<anonymous>'
+
+#-------------------------------------------------------------------------------
+getStackTrace = (e) ->
+    return e.stack if e.stack
+
+    return null
+
+#-------------------------------------------------------------------------------
+require("../common/MethodNamer").setNamesForClass(module.exports)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/HookSites.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/HookSites.coffee b/weinre.web/modules/weinre/target/HookSites.coffee
new file mode 100644
index 0000000..ef37e98
--- /dev/null
+++ b/weinre.web/modules/weinre/target/HookSites.coffee
@@ -0,0 +1,38 @@
+
+#---------------------------------------------------------------------------------
+# weinre is available under *either* the terms of the modified BSD license *or* the
+# MIT License (2008). See http:#opensource.org/licenses/alphabetical for full text.
+#
+# Copyright (c) 2010, 2011 IBM Corporation
+#---------------------------------------------------------------------------------
+
+HookLib = require('../common/HookLib')
+
+#-------------------------------------------------------------------------------
+module.exports = class HookSites
+
+#---------------------------------------------------------------------------
+HookSites.window_clearInterval            = HookLib.addHookSite window, "clearInterval"
+HookSites.window_clearTimeout             = HookLib.addHookSite window, "clearTimeout"
+HookSites.window_setInterval              = HookLib.addHookSite window, "setInterval"
+HookSites.window_setTimeout               = HookLib.addHookSite window, "setTimeout"
+HookSites.window_addEventListener         = HookLib.addHookSite window, "addEventListener"
+HookSites.Node_addEventListener           = HookLib.addHookSite Node.prototype, "addEventListener"
+HookSites.XMLHttpRequest_open             = HookLib.addHookSite XMLHttpRequest.prototype, "open"
+HookSites.XMLHttpRequest_addEventListener = HookLib.addHookSite XMLHttpRequest.prototype, "addEventListener"
+
+if window.openDatabase
+    HookSites.window_openDatabase = HookLib.addHookSite window, "openDatabase"
+
+if window.localStorage
+    HookSites.LocalStorage_setItem    = HookLib.addHookSite window.localStorage, "setItem"
+    HookSites.LocalStorage_removeItem = HookLib.addHookSite window.localStorage, "removeItem"
+    HookSites.LocalStorage_clear      = HookLib.addHookSite window.localStorage, "clear"
+
+if window.sessionStorage
+    HookSites.SessionStorage_setItem    = HookLib.addHookSite window.sessionStorage, "setItem"
+    HookSites.SessionStorage_removeItem = HookLib.addHookSite window.sessionStorage, "removeItem"
+    HookSites.SessionStorage_clear      = HookLib.addHookSite window.sessionStorage, "clear"
+
+#-------------------------------------------------------------------------------
+require("../common/MethodNamer").setNamesForClass(module.exports)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee b/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
index a4ba59f..d1553c6 100644
--- a/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
+++ b/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
@@ -40,7 +40,7 @@ module.exports = class InjectedScriptHostImpl
         return ctorName if ctorName and (ctorName != "Object")
 
         pattern = /\[object (.*)\]/
-        match = pattern.exec(ctor.toString())
+        match = pattern.exec(object.toString())
 
         return match[1] if match
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/Target.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/Target.coffee b/weinre.web/modules/weinre/target/Target.coffee
index 130a05b..f7291a0 100644
--- a/weinre.web/modules/weinre/target/Target.coffee
+++ b/weinre.web/modules/weinre/target/Target.coffee
@@ -6,17 +6,18 @@
 # Copyright (c) 2010, 2011 IBM Corporation
 #---------------------------------------------------------------------------------
 
-Native                        = require('../common/Native')
 Ex                            = require('../common/Ex')
 Binding                       = require('../common/Binding')
 Callback                      = require('../common/Callback')
 MessageDispatcher             = require('../common/MessageDispatcher')
 Weinre                        = require('../common/Weinre')
+HookLib                       = require('../common/HookLib')
 
 CheckForProblems              = require('./CheckForProblems')
 NodeStore                     = require('./NodeStore')
 CSSStore                      = require('./CSSStore')
 ElementHighlighter            = require('./ElementHighlighter')
+ExceptionalCallbacks          = require('./ExceptionalCallbacks')
 InjectedScriptHostImpl        = require('./InjectedScriptHostImpl')
 WeinreTargetEventsImpl        = require('./WeinreTargetEventsImpl')
 WeinreExtraClientCommandsImpl = require('./WeinreExtraClientCommandsImpl')
@@ -42,6 +43,8 @@ module.exports = class Target
         Weinre.addCSSProperties = addCSSProperties = (properties) ->
             CSSStore.addCSSProperties properties
 
+        ExceptionalCallbacks.addHooks()
+
     #----------------------------------------------------------------------------
     setWeinreServerURLFromScriptSrc: (element) ->
         return if window.WeinreServerURL
@@ -77,7 +80,7 @@ module.exports = class Target
     #---------------------------------------------------------------------------
     getTargetScriptElement: ->
         elements = document.getElementsByTagName("script")
-        scripts = [ "Target.", "target-script.", "target-script-min." ]
+        scripts = [ "target-script.js", "target-script-min.js" ]
         i = 0
 
         while i < elements.length
@@ -90,8 +93,6 @@ module.exports = class Target
 
     #---------------------------------------------------------------------------
     initialize: () ->
-        self = this
-
         element = @getTargetScriptElement()
 
         @setWeinreServerURLFromScriptSrc element
@@ -106,17 +107,13 @@ module.exports = class Target
 
         @_startTime = currentTime()
         if document.readyState == "loaded"
-            setTimeout (->
-                self.onDOMContent()
-            ), 10
+            HookLib.ignoreHooks =>
+                setTimeout (=> this.onDOMContent()), 10
 
         if document.readyState == "complete"
-            setTimeout (->
-                self.onDOMContent()
-            ), 10
-            setTimeout (->
-                self.onLoaded()
-            ), 20
+            HookLib.ignoreHooks =>
+                setTimeout (=> this.onDOMContent()), 10
+                setTimeout (=> this.onLoaded()), 20
 
 #        MessageDispatcher.verbose(true)
         messageDispatcher = new MessageDispatcher(window.WeinreServerURL + "ws/target", window.WeinreServerId)
@@ -179,10 +176,20 @@ module.exports = class Target
 
     #---------------------------------------------------------------------------
     onLoaded: ->
+        if not Weinre.wi.InspectorNotify
+            HookLib.ignoreHooks =>
+                setTimeout (=> this.onLoaded()), 10
+            return
+
         Weinre.wi.InspectorNotify.loadEventFired currentTime() - @_startTime
 
     #---------------------------------------------------------------------------
     onDOMContent: ->
+        if not Weinre.wi.InspectorNotify
+            HookLib.ignoreHooks =>
+                setTimeout (=> this.onDOMContent()), 10
+            return
+
         Weinre.wi.InspectorNotify.domContentEventFired currentTime() - @_startTime
 
     #---------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/Timeline.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/Timeline.coffee b/weinre.web/modules/weinre/target/Timeline.coffee
index 488f0e9..6a9a3ce 100644
--- a/weinre.web/modules/weinre/target/Timeline.coffee
+++ b/weinre.web/modules/weinre/target/Timeline.coffee
@@ -10,7 +10,8 @@ Ex          = require('../common/Ex')
 Weinre      = require('../common/Weinre')
 IDGenerator = require('../common/IDGenerator')
 StackTrace  = require('../common/StackTrace')
-Native      = require('../common/Native')
+HookLib     = require('../common/HookLib')
+HookSites   = require('./HookSites')
 
 Running = false
 
@@ -163,122 +164,99 @@ module.exports = class Timeline
 
         Weinre.wi.TimelineNotify.addRecordToTimeline record
 
+
     #---------------------------------------------------------------------------
     @installGlobalListeners: ->
         if applicationCache
-            applicationCache.addEventListener "checking", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.checking", "loading"
-            ), false
-
-            applicationCache.addEventListener "error", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.error", "loading"
-            ), false
-
-            applicationCache.addEventListener "noupdate", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.noupdate", "loading"
-            ), false
-
-            applicationCache.addEventListener "downloading", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.downloading", "loading"
-            ), false
-
-            applicationCache.addEventListener "progress", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.progress", "loading"
-            ), false
-
-            applicationCache.addEventListener "updateready", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.updateready", "loading"
-            ), false
+            applicationCache.addEventListener "checking",    ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.checking", "loading"    ), false
+            applicationCache.addEventListener "error",       ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.error", "loading"       ), false
+            applicationCache.addEventListener "noupdate",    ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.noupdate", "loading"    ), false
+            applicationCache.addEventListener "downloading", ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.downloading", "loading" ), false
+            applicationCache.addEventListener "progress",    ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.progress", "loading"    ), false
+            applicationCache.addEventListener "updateready", ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.updateready", "loading" ), false
+            applicationCache.addEventListener "cached",      ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.cached", "loading"      ), false
+            applicationCache.addEventListener "obsolete",    ((e) -> Timeline.addRecord_EventDispatch e, "applicationCache.obsolete", "loading"    ), false
+
+        window.addEventListener "error",      ((e) -> Timeline.addRecord_EventDispatch e, "window.error"      ), false
+        window.addEventListener "hashchange", ((e) -> Timeline.addRecord_EventDispatch e, "window.hashchange" ), false
+        window.addEventListener "message",    ((e) -> Timeline.addRecord_EventDispatch e, "window.message"    ), false
+        window.addEventListener "offline",    ((e) -> Timeline.addRecord_EventDispatch e, "window.offline"    ), false
+        window.addEventListener "online",     ((e) -> Timeline.addRecord_EventDispatch e, "window.online"     ), false
+        window.addEventListener "scroll",     ((e) -> Timeline.addRecord_EventDispatch e, "window.scroll"     ), false
 
-            applicationCache.addEventListener "cached", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.cached", "loading"
-            ), false
-
-            applicationCache.addEventListener "obsolete", ((e) ->
-                Timeline.addRecord_EventDispatch e, "applicationCache.obsolete", "loading"
-            ), false
+    #---------------------------------------------------------------------------
+    @installNativeHooks: ->
 
-        window.addEventListener "error", ((e) ->
-            Timeline.addRecord_EventDispatch e, "window.error"
-        ), false
+        #-----------------------------------------------------------------------
+        HookSites.window_setInterval.addHooks
 
-        window.addEventListener "hashchange", ((e) ->
-            Timeline.addRecord_EventDispatch e, "window.hashchange"
-        ), false
+            before: (receiver, args) ->
+                code = args[0]
+                return unless typeof(code) is "function"
 
-        window.addEventListener "message", ((e) ->
-            Timeline.addRecord_EventDispatch e, "window.message"
-        ), false
+                interval  = args[1]
+                code      = instrumentedTimerCode(code, interval, false)
+                args[0]   = code
+                @userData = code
 
-        window.addEventListener "offline", ((e) ->
-            Timeline.addRecord_EventDispatch e, "window.offline"
-        ), false
+            after: (receiver, args, result) ->
+                code = @userData
+                return unless typeof(code) is "function"
 
-        window.addEventListener "online", ((e) ->
-            Timeline.addRecord_EventDispatch e, "window.online"
-        ), false
+                id             = result
+                code.__timerId = id
+                addTimer id, interval, false
 
-        window.addEventListener "scroll", ((e) ->
-            Timeline.addRecord_EventDispatch e, "window.scroll"
-        ), false
+        #-----------------------------------------------------------------------
+        HookSites.window_clearInterval.addHooks
 
-    #---------------------------------------------------------------------------
-    @installFunctionWrappers: ->
-        window.clearInterval        = wrapped_clearInterval
-        window.clearTimeout         = wrapped_clearTimeout
-        window.setTimeout           = wrapped_setTimeout
-        window.setInterval          = wrapped_setInterval
-        window.XMLHttpRequest::open = wrapped_XMLHttpRequest_open
-        window.XMLHttpRequest       = wrapped_XMLHttpRequest
+            before: (receiver, args) ->
+                id = args[0]
+                removeTimer id, false
 
+        #-----------------------------------------------------------------------
+        HookSites.window_setTimeout.addHooks
 
-#-------------------------------------------------------------------------------
-addStackTrace = (record, skip) ->
-      skip = 1 unless skip
-      trace = new StackTrace(arguments).trace
-      record.stackTrace = []
-      i = skip
+            before: (receiver, args) ->
+                code = args[0]
+                return unless typeof(code) is "function"
 
-      while i < trace.length
-          record.stackTrace.push
-              functionName: trace[i]
-              scriptName:   ""
-              lineNumber:   ""
-          i++
+                interval  = args[1]
+                code      = instrumentedTimerCode(code, interval, true)
+                args[0]   = code
+                @userData = code
 
-#-------------------------------------------------------------------------------
-wrapped_setInterval = (code, interval) ->
-      code = instrumentedTimerCode(code, interval, false)
+            after: (receiver, args, result) ->
+                code = @userData
+                return unless typeof(code) is "function"
 
-      id = Native.setInterval(code, interval)
-      code.__timerId = id
-      addTimer id, interval, false
+                id             = result
+                code.__timerId = id
+                addTimer id, interval, true
 
-      id
+        #-----------------------------------------------------------------------
+        HookSites.window_clearTimeout.addHooks
 
-#-------------------------------------------------------------------------------
-wrapped_setTimeout = (code, delay) ->
-      code = instrumentedTimerCode(code, delay, true)
+            before: (receiver, args) ->
+                id = args[0]
+                removeTimer id, true
 
-      id = Native.setTimeout(code, delay)
-      code.__timerId = id
-      addTimer id, delay, true
+        #-----------------------------------------------------------------------
+        HookSites.XMLHttpRequest_open.addHooks
 
-      id
+            before:  (receiver, args) ->
+                xhr = receiver
+                IDGenerator.getId xhr
 
-#-------------------------------------------------------------------------------
-wrapped_clearInterval = (id) ->
-      result = Native.clearInterval(id)
-      removeTimer id, false
+                xhr.__weinre_method = args[0]
+                xhr.__weinre_url    = args[1]
 
-      result
+                xhr.addEventListener "readystatechange", getXhrEventHandler(xhr), false
 
 #-------------------------------------------------------------------------------
-wrapped_clearTimeout = (id) ->
-      result = Native.clearTimeout(id)
-      removeTimer id, true
-
-      result
+getXhrEventHandler = (xhr) ->
+      (event) ->
+          Timeline.addRecord_XHRReadyStateChange xhr.__weinre_method, xhr.__weinre_url, IDGenerator.getId(xhr), xhr
 
 #-------------------------------------------------------------------------------
 addTimer = (id, timeout, singleShot) ->
@@ -310,39 +288,27 @@ instrumentedTimerCode = (code, timeout, singleShot) ->
           Timeline.addRecord_TimerFire id, timeout, singleShot
           result
 
-      instrumentedCode
+      instrumentedCode.displayName = code.name || code.displayName
 
-#-------------------------------------------------------------------------------
-wrapped_XMLHttpRequest = () ->
-      xhr = new Native.XMLHttpRequest()
-      IDGenerator.getId xhr
-      xhr.addEventListener "readystatechange", getXhrEventHandler(xhr), false
-      xhr
-
-wrapped_XMLHttpRequest.UNSENT           = 0
-wrapped_XMLHttpRequest.OPENED           = 1
-wrapped_XMLHttpRequest.HEADERS_RECEIVED = 2
-wrapped_XMLHttpRequest.LOADING          = 3
-wrapped_XMLHttpRequest.DONE             = 4
+      instrumentedCode
 
 #-------------------------------------------------------------------------------
-wrapped_XMLHttpRequest_open = () ->
-      xhr = this
-
-      xhr.__weinre_method = arguments[0]
-      xhr.__weinre_url = arguments[1]
-      result = Native.XMLHttpRequest_open.apply(xhr, [].slice.call(arguments))
-
-      result
+addStackTrace = (record, skip) ->
+      skip = 1 unless skip
+      trace = new StackTrace(arguments).trace
+      record.stackTrace = []
+      i = skip
 
-#-------------------------------------------------------------------------------
-getXhrEventHandler = (xhr) ->
-      (event) ->
-          Timeline.addRecord_XHRReadyStateChange xhr.__weinre_method, xhr.__weinre_url, IDGenerator.getId(xhr), xhr
+      while i < trace.length
+          record.stackTrace.push
+              functionName: trace[i]
+              scriptName:   ""
+              lineNumber:   ""
+          i++
 
 #-------------------------------------------------------------------------------
 Timeline.installGlobalListeners()
-Timeline.installFunctionWrappers()
+Timeline.installNativeHooks()
 
 #-------------------------------------------------------------------------------
 require("../common/MethodNamer").setNamesForClass(module.exports)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/WiDOMStorageImpl.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/WiDOMStorageImpl.coffee b/weinre.web/modules/weinre/target/WiDOMStorageImpl.coffee
index 23ef0ad..536a181 100644
--- a/weinre.web/modules/weinre/target/WiDOMStorageImpl.coffee
+++ b/weinre.web/modules/weinre/target/WiDOMStorageImpl.coffee
@@ -6,8 +6,8 @@
 # Copyright (c) 2010, 2011 IBM Corporation
 #---------------------------------------------------------------------------------
 
-Weinre = require('../common/Weinre')
-Native = require('../common/Native')
+Weinre    = require('../common/Weinre')
+HookSites = require('./HookSites')
 
 #-------------------------------------------------------------------------------
 module.exports = class WiDOMStorageImpl
@@ -45,9 +45,11 @@ module.exports = class WiDOMStorageImpl
 
         result = true
         try
-            if storageArea == window.localStorage
-                Native.LocalStorage_setItem key, value
-            else Native.SessionStorage_setItem key, value if storageArea == window.sessionStorage
+            HookLib.ignoreHooks ->
+                if storageArea == window.localStorage
+                    localStorage.setItem key, value
+                else if storageArea == window.sessionStorage
+                    sessionStorage.setItem key, value
         catch e
             result = false
 
@@ -64,11 +66,11 @@ module.exports = class WiDOMStorageImpl
 
         result = true
         try
-            if storageArea == window.localStorage
-                Native.LocalStorage_removeItem key
-            else
-                if storageArea == window.sessionStorage
-                    Native.SessionStorage_removeItem key
+            HookLib.ignoreHooks ->
+                if storageArea == window.localStorage
+                    localStorage.removeItem key
+                else if storageArea == window.sessionStorage
+                    sessionStorage.removeItem key
         catch e
             result = false
 
@@ -82,17 +84,14 @@ module.exports = class WiDOMStorageImpl
                 host: window.location.host
                 isLocalStorage: true
 
-            window.localStorage.setItem = (key, value) ->
-                Native.LocalStorage_setItem key, value
-                _storageEventHandler storageArea: window.localStorage
+            HookSites.LocalStorage_setItem.addHooks
+                after: -> _storageEventHandler storageArea: window.localStorage
 
-            window.localStorage.removeItem = (key) ->
-                Native.LocalStorage_removeItem key
-                _storageEventHandler storageArea: window.localStorage
+            HookSites.LocalStorage_removeItem.addHooks
+                after: -> _storageEventHandler storageArea: window.localStorage
 
-            window.localStorage.clear = ->
-                Native.LocalStorage_clear()
-                _storageEventHandler storageArea: window.localStorage
+            HookSites.LocalStorage_clear.addHooks
+                after: -> _storageEventHandler storageArea: window.localStorage
 
         if window.sessionStorage
             Weinre.wi.DOMStorageNotify.addDOMStorage
@@ -100,17 +99,14 @@ module.exports = class WiDOMStorageImpl
                 host: window.location.host
                 isLocalStorage: false
 
-            window.sessionStorage.setItem = (key, value) ->
-                Native.SessionStorage_setItem key, value
-                _storageEventHandler storageArea: window.sessionStorage
+            HookSites.SeesionStorage_setItem.addHooks
+                after: -> _storageEventHandler storageArea: window.sessionStorage
 
-            window.sessionStorage.removeItem = (key) ->
-                Native.SessionStorage_removeItem key
-                _storageEventHandler storageArea: window.sessionStorage
+            HookSites.SeesionStorage_removeItem.addHooks
+                after: -> _storageEventHandler storageArea: window.sessionStorage
 
-            window.sessionStorage.clear = ->
-                Native.SessionStorage_clear()
-                _storageEventHandler storageArea: window.sessionStorage
+            HookSites.SeesionStorage_clear.addHooks
+                after: -> _storageEventHandler storageArea: window.sessionStorage
 
         document.addEventListener "storage", _storageEventHandler, false
 
@@ -118,7 +114,8 @@ module.exports = class WiDOMStorageImpl
 _getStorageArea = (storageId) ->
       if storageId == 1
           return window.localStorage
-      else return window.sessionStorage if storageId == 2
+      else if storageId == 2
+          return window.sessionStorage
 
       null
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/modules/weinre/target/WiDatabaseImpl.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/WiDatabaseImpl.coffee b/weinre.web/modules/weinre/target/WiDatabaseImpl.coffee
index e458615..0c58b13 100644
--- a/weinre.web/modules/weinre/target/WiDatabaseImpl.coffee
+++ b/weinre.web/modules/weinre/target/WiDatabaseImpl.coffee
@@ -7,8 +7,8 @@
 #---------------------------------------------------------------------------------
 
 Weinre      = require('../common/Weinre')
-Native      = require('../common/Native')
 IDGenerator = require('../common/IDGenerator')
+HookSites   = require('./HookSites')
 SqlStepper  = require('./SqlStepper')
 
 id2db   = {}
@@ -19,7 +19,15 @@ module.exports = class WiDatabaseImpl
 
     constructor: ->
         return unless window.openDatabase
-        window.openDatabase = wrappedOpenDatabase
+
+        HookSites.window_openDatabase.addHooks
+            after: (receiver, args, db) ->
+                return if not db
+
+                name    = args[0]
+                version = args[1]
+
+                dbAdd db, name, version
 
     #---------------------------------------------------------------------------
     @getDatabases: ->
@@ -113,12 +121,6 @@ executeSQL_error = (sqlError) ->
       Weinre.wi.DatabaseNotify.sqlTransactionFailed @txid, error
 
 #-------------------------------------------------------------------------------
-wrappedOpenDatabase = (name, version, displayName, estimatedSize, creationCallback) ->
-      db = Native.openDatabase(name, version, displayName, estimatedSize, creationCallback)
-      dbAdd db, name, version
-      db
-
-#-------------------------------------------------------------------------------
 dbById = (id) ->
       record = id2db[id]
       return null unless record

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/048ebd64/weinre.web/versions.js
----------------------------------------------------------------------
diff --git a/weinre.web/versions.js b/weinre.web/versions.js
index 1b62da4..174adc9 100644
--- a/weinre.web/versions.js
+++ b/weinre.web/versions.js
@@ -1,17 +1,17 @@
 /*
  * weinre is available under *either* the terms of the modified BSD license *or* the
  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- * 
+ *
  * Copyright (c) 2010, 2011 IBM Corporation
  */
 
  if (typeof Weinre == "undefined") Weinre = {};
- 
+
  Weinre.Versions = {
-    weinre:   "@WEINRE_VERSION@", 
-    build:    "@BUILD_NUMBER_DATE@", 
-    jetty:    "@JETTY_VERSION@", 
-    servlet:  "@JAVAX_SERVLET_VERSION@-@JAVAX_SERVLET_VERSION_IMPL@", 
+    weinre:   "@WEINRE_VERSION@",
+    build:    "@BUILD_NUMBER_DATE@",
+    jetty:    "@JETTY_VERSION@",
+    servlet:  "@JAVAX_SERVLET_VERSION@-@JAVAX_SERVLET_VERSION_IMPL@",
     webkit:   "@WEBKIT_VERSION@",
     cli:      "@CLI_VERSION@",
     json4j:   "@JSON4J_VERSION@",


Mime
View raw message