You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by fa...@apache.org on 2014/09/27 12:13:43 UTC

svn commit: r1627942 [3/4] - in /qpid/proton/branches/fadams-javascript-binding: examples/messenger/javascript/ proton-c/bindings/javascript/ tests/javascript/

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/recv.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/recv.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/recv.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/recv.js Sat Sep 27 10:13:43 2014
@@ -20,51 +20,50 @@
  */
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("recv.js should be run in Node.js");
-    return;
-}
-
-var proton = require("qpid-proton");
-
-var address = "amqp://~0.0.0.0";
-var message = new proton.Message();
-var messenger = new proton.Messenger();
-
-var pumpData = function() {
-    while (messenger.incoming()) {
-        var t = messenger.get(message);
-
-        console.log("Address: " + message.getAddress());
-        console.log("Subject: " + message.getSubject());
-
-        // body is the body as a native JavaScript Object, useful for most real cases.
-        //console.log("Content: " + message.body);
+if (typeof process === 'object' && typeof require === 'function') {
+    var proton = require("qpid-proton");
 
-        // data is the body as a proton.Data Object, used in this case because
-        // format() returns exactly the same representation as recv.c
-        console.log("Content: " + message.data.format());
-
-        messenger.accept(t);
-    }
-};
-
-var args = process.argv.slice(2);
-if (args.length > 0) {
-    if (args[0] === '-h' || args[0] === '--help') {
-        console.log("Usage: node recv.js <addr> (default " + address + ")");
-        process.exit(0);
+    var address = "amqp://~0.0.0.0";
+    var message = new proton.Message();
+    var messenger = new proton.Messenger();
+
+    var pumpData = function() {
+        while (messenger.incoming()) {
+            var t = messenger.get(message);
+
+            console.log("Address: " + message.getAddress());
+            console.log("Subject: " + message.getSubject());
+    
+            // body is the body as a native JavaScript Object, useful for most real cases.
+            //console.log("Content: " + message.body);
+    
+            // data is the body as a proton.Data Object, used in this case because
+            // format() returns exactly the same representation as recv.c
+            console.log("Content: " + message.data.format());
+    
+            messenger.accept(t);
+        }
+    };
+
+    var args = process.argv.slice(2);
+    if (args.length > 0) {
+        if (args[0] === '-h' || args[0] === '--help') {
+            console.log("Usage: node recv.js <addr> (default " + address + ")");
+            process.exit(0);
+        }
+    
+        address = args[0];
     }
+    
+    messenger.setIncomingWindow(1024);
+    
+    messenger.on('error', function(error) {console.log(error);});
+    messenger.on('work', pumpData);
+    messenger.recv(); // Receive as many messages as messenger can buffer.
+    messenger.start();
 
-    address = args[0];
+    messenger.subscribe(address);
+} else {
+    console.error("recv.js should be run in Node.js");
 }
 
-messenger.setIncomingWindow(1024);
-
-messenger.on('error', function(error) {console.log(error);});
-messenger.on('work', pumpData);
-messenger.start();
-
-messenger.subscribe(address);
-messenger.recv(); // Receive as many messages as messenger can buffer.
-

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.html
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.html?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.html (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.html Sat Sep 27 10:13:43 2014
@@ -28,19 +28,20 @@
 <!--
   Import the Messenger Binding proton.js. Note that this simple example pulls
   it from the node_modules/qpid-proton/lib, which is created by the build process
-  so that the node.js based examples "just work", in a real Web App you would need
-  to copy the proton.js to your own server.
+  so that the node.js based examples "just work", in a real Web App you would
+  clearly need to copy the proton.js to your own server.
 
   In actual fact the CMake build actually builds proton.js into the directory:
   <build>/proton-c/bindings/javascript
-  where <build> is the build directory created to run cmake from.
+  where <build> is the build directory created to run cmake from, it is then
+  copied to the node_modules/qpid-proton/lib directory.
 
-  In this example we also set the global variable PROTON_HEAP_SIZE in order to
+  In this example we also set the global variable PROTON_TOTAL_MEMORY in order to
   increase the virtual heap available to the emscripten compiled C runtime. It
   is not really necessary to do this for this application as the default value
   of 16777216 is fine, it is simply done here to illustrate how to do it.
 -->
-<script type="text/javascript">PROTON_HEAP_SIZE = 50000000;</script>
+<script type="text/javascript">PROTON_TOTAL_MEMORY = 50000000;</script>
 <script type="text/javascript" src="../../../node_modules/qpid-proton/lib/proton.js"></script>
 
 <script type="text/javascript">

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/send.js Sat Sep 27 10:13:43 2014
@@ -20,81 +20,86 @@
  */
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (typeof process !== 'object' || typeof require !== 'function') {
-    console.error("send.js should be run in Node.js");
-    return;
-}
-
-PROTON_HEAP_SIZE = 50000000;
-var proton = require("qpid-proton");
-
-var address = "amqp://0.0.0.0";
-var subject = "UK.WEATHER";
-var msgtext = "Hello World!";
-var tracker = null;
-var running = true;
-
-var message = new proton.Message();
-var messenger = new proton.Messenger();
-
-// Because this is an asynchronous send we can't simply call messenger.put(message)
-// then exit. The following callback function (and messenger.setOutgoingWindow())
-// gives us a means to wait until the consumer has received the message before
-// exiting. The recv.js example explicitly accepts messages it receives.
-var pumpData = function() {
-    var status = messenger.status(tracker);
-    if (status != proton.Status.PENDING) {
-        if (running) {
-            messenger.stop();
-            running = false;
-        } 
-    }
+if (typeof process === 'object' && typeof require === 'function') {
+    // In this example we also set the global variable PROTON_TOTAL_MEMORY in order
+    // to increase the virtual heap available to the emscripten compiled C runtime.
+    // It is not really necessary to do this for this application as the default
+    // value of 16777216 is fine, it is simply done here to illustrate how to do it.
+    PROTON_TOTAL_MEMORY = 50000000;
+    var proton = require("qpid-proton");
+
+    var address = "amqp://0.0.0.0";
+    var subject = "UK.WEATHER";
+    var msgtext = "Hello World!";
+    var tracker = null;
+    var running = true;
+
+    var message = new proton.Message();
+    var messenger = new proton.Messenger();
+
+    // This is an asynchronous send, so we can't simply call messenger.put(message)
+    // at the end of the application as we would with a synchronous/blocking
+    // version, as the application would simply exit without actually sending.
+    // The following callback function (and messenger.setOutgoingWindow())
+    // gives us a means to wait until the consumer has received the message before
+    // exiting. The recv.js example explicitly accepts messages it receives.
+    var pumpData = function() {
+        var status = messenger.status(tracker);
+        if (status != proton.Status.PENDING) {
+            if (running) {
+                messenger.stop();
+                running = false;
+            } 
+        }
 
-    if (messenger.isStopped()) {
-        message.free();
-        messenger.free();
-    }
-};
+        if (messenger.isStopped()) {
+            message.free();
+            messenger.free();
+        }
+    };
 
-var args = process.argv.slice(2);
-if (args.length > 0) {
-    if (args[0] === '-h' || args[0] === '--help') {
-        console.log("Usage: node send.js [options] [message]");
-        console.log("Options:");
-        console.log("  -a <addr> The target address [amqp[s]://domain[/name]] (default " + address + ")");
-        console.log("  -s <subject> The message subject (default " + subject + ")");
-        console.log("message A text string to send.");
-        process.exit(0);
-    }
+    var args = process.argv.slice(2);
+    if (args.length > 0) {
+        if (args[0] === '-h' || args[0] === '--help') {
+            console.log("Usage: node send.js [options] [message]");
+            console.log("Options:");
+            console.log("  -a <addr> The target address [amqp[s]://domain[/name]] (default " + address + ")");
+            console.log("  -s <subject> The message subject (default " + subject + ")");
+            console.log("message A text string to send.");
+            process.exit(0);
+        }
 
-    for (var i = 0; i < args.length; i++) {
-        var arg = args[i];
-        if (arg.charAt(0) === '-') {
-            i++;
-            var val = args[i];
-            if (arg === '-a') {
-                address = val;
-            } else if (arg === '-s') {
-                subject = val;
+        for (var i = 0; i < args.length; i++) {
+            var arg = args[i];
+            if (arg.charAt(0) === '-') {
+                i++;
+                var val = args[i];
+                if (arg === '-a') {
+                    address = val;
+                } else if (arg === '-s') {
+                    subject = val;
+                }
+            } else {
+                msgtext = arg;
             }
-        } else {
-            msgtext = arg;
         }
     }
-}
 
-console.log("Address: " + address);
-console.log("Subject: " + subject);
-console.log("Content: " + msgtext);
-
-messenger.on('error', function(error) {console.log(error);});
-messenger.on('work', pumpData);
-messenger.setOutgoingWindow(1024); // So we can track status of send message.
-messenger.start();
-
-message.setAddress(address);
-message.setSubject(subject);
-message.body = msgtext;
+    console.log("Address: " + address);
+    console.log("Subject: " + subject);
+    console.log("Content: " + msgtext);
+
+    messenger.on('error', function(error) {console.log(error);});
+    messenger.on('work', pumpData);
+    messenger.setOutgoingWindow(1024); // So we can track status of send message.
+    messenger.start();
+
+    message.setAddress(address);
+    message.setSubject(subject);
+    message.body = msgtext;
 
-tracker = messenger.put(message);
+    tracker = messenger.put(message);
+} else {
+    console.error("send.js should be run in Node.js");
+}
 

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/server.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/server.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/server.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/server.js Sat Sep 27 10:13:43 2014
@@ -22,61 +22,60 @@
 // Simple server for use with client.js illustrating request/response
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("server.js should be run in Node.js");
-    return;
-}
+if (typeof process === 'object' && typeof require === 'function') {
+    var proton = require("qpid-proton");
 
-var proton = require("qpid-proton");
-
-var address = "amqp://~0.0.0.0";
-var message = new proton.Message();
-var reply   = new proton.Message();
-var messenger = new proton.Messenger();
-
-var dispatch = function(request, response) {
-    var subject = request.getSubject();
-    if (subject) {
-        response.setSubject('Re: ' + subject);
-    }
-    response.properties = request.properties
-    console.log("Dispatched " + subject + " " + JSON.stringify(request.properties));
-};
-
-var pumpData = function() {
-    while (messenger.incoming()) {
-        var t = messenger.get(message);
-
-        var replyTo = message.getReplyTo();
-        if (replyTo) {
-            console.log(replyTo);
-            reply.setAddress(replyTo);
-            reply.setCorrelationID(message.getCorrelationID());
-            reply.body = message.body;
-            dispatch(message, reply);
-            messenger.put(reply);
+    var address = "amqp://~0.0.0.0";
+    var message = new proton.Message();
+    var reply   = new proton.Message();
+    var messenger = new proton.Messenger();
+
+    var dispatch = function(request, response) {
+        var subject = request.getSubject();
+        if (subject) {
+            response.setSubject('Re: ' + subject);
         }
+        response.properties = request.properties
+        console.log("Dispatched " + subject + " " + JSON.stringify(request.properties));
+    };
+
+    var pumpData = function() {
+        while (messenger.incoming()) {
+            var t = messenger.get(message);
+    
+            var replyTo = message.getReplyTo();
+            if (replyTo) {
+                console.log(replyTo);
+                reply.setAddress(replyTo);
+                reply.setCorrelationID(message.getCorrelationID());
+                reply.body = message.body;
+                dispatch(message, reply);
+                messenger.put(reply);
+            }
+    
+            messenger.accept(t);
+        }
+    };
 
-        messenger.accept(t);
-    }
-};
-
-var args = process.argv.slice(2);
-if (args.length > 0) {
-    if (args[0] === '-h' || args[0] === '--help') {
-        console.log("Usage: node server.js <addr> (default " + address + ")");
-        process.exit(0);
+    var args = process.argv.slice(2);
+    if (args.length > 0) {
+        if (args[0] === '-h' || args[0] === '--help') {
+            console.log("Usage: node server.js <addr> (default " + address + ")");
+            process.exit(0);
+        }
+    
+        address = args[0];
     }
-
-    address = args[0];
+    
+    messenger.setIncomingWindow(1024);
+    
+    messenger.on('error', function(error) {console.log(error);});
+    messenger.on('work', pumpData);
+    messenger.recv(); // Receive as many messages as messenger can buffer.
+    messenger.start();
+    
+    messenger.subscribe(address);
+} else {
+    console.error("server.js should be run in Node.js");
 }
 
-messenger.setIncomingWindow(1024);
-
-messenger.on('error', function(error) {console.log(error);});
-messenger.on('work', pumpData);
-messenger.start();
-
-messenger.subscribe(address);
-messenger.recv(); // Receive as many messages as messenger can buffer.
-

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/spout.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/spout.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/spout.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/javascript/spout.js Sat Sep 27 10:13:43 2014
@@ -20,102 +20,52 @@
  */
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("spout.js should be run in Node.js");
-    return;
-}
-
-var proton = require("qpid-proton");
-
-console.log("spout not implemented yet");
-process.exit(0);
+if (typeof process === 'object' && typeof require === 'function') {
+    var proton = require("qpid-proton");
 
-var address = "amqp://0.0.0.0";
-var subject = "UK.WEATHER";
-var msgtext = "Hello World!";
-var tracker = null;
-var running = true;
-
-var message = new proton.Message();
-var messenger = new proton.Messenger();
-
-function pumpData() {
-    var status = messenger.status(tracker);
-    if (status != proton.Status.PENDING) {
+    console.log("spout not implemented yet");
+    process.exit(0);
+    
+    var address = "amqp://0.0.0.0";
+    var subject = "UK.WEATHER";
+    var msgtext = "Hello World!";
+    var tracker = null;
+    var running = true;
+    
+    var message = new proton.Message();
+    var messenger = new proton.Messenger();
+
+    function pumpData() {
+        var status = messenger.status(tracker);
+        if (status != proton.Status.PENDING) {
 console.log("status = " + status);
 
-        if (running) {
+            if (running) {
 console.log("stopping");
-            messenger.stop();
-            running = false;
-        } 
-    }
-
-    if (messenger.isStopped()) {
+                messenger.stop();
+                running = false;
+            } 
+        }
+    
+        if (messenger.isStopped()) {
 console.log("exiting");
-        message.free();
-        messenger.free();
-    }
-};
-
-messenger.on('error', function(error) {console.log(error);});
-messenger.on('work', pumpData);
-messenger.setOutgoingWindow(1024);
-messenger.start();
-
-message.setAddress(address);
-message.setSubject(subject);
-
-//message.body = msgtext;
-//message.body = new proton.Data.Uuid();
-//message.body = new proton.Data.Symbol("My Symbol");
-message.body = new proton.Data.Binary("Monkey Bathпогромзхцвбнм");
-//message.body = new proton.Data.Described("persian", "feline mammals");
-
-//message.body = new Date();
-
-//message.body = new proton.Data.Array('INT', [1, 3, 5, 7], "odd numbers");
-
-//message.body = new proton.Data.Array('UINT', [1, 3, 5, 7], "odd");
-//message.body = new proton.Data.Array('ULONG', [1, 3, 5, 7], "odd");
-//message.body = new proton.Data.Array('FLOAT', [1, 3, 5, 7], "odd");
-//message.body = new proton.Data.Array('STRING', ["1", "3", "5", "7"], "odd");
-
-//message.body = new Uint8Array([1, 3, 5, 7]);
-
-//message.body = new proton.Data.Array('UINT', new Uint8Array([1, 3, 5, 7]), "odd");
-
-//message.body = new proton.Data.Array('UUID', [new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid()], "unique");
-
-/*message.body = new proton.Data.Binary(4);
-var buffer = message.body.getBuffer();
-buffer[0] = 65;
-buffer[1] = 77;
-buffer[2] = 81;
-buffer[3] = 80;*/
-//message.body = new proton.Data.Binary([65, 77, 81, 80]);
-//message.body = new proton.Data.Binary(2485);
-//message.body = new proton.Data.Binary(100000);
-
-//message.body = null;
-//message.body = true;
-//message.body = 66..char();
-//message.body = "   \"127.0\"  ";
-
-//message.body = 2147483647; // int
-//message.body = -2147483649; // long
-//message.body = 12147483649; // long
-//message.body = (12147483649).long(); // long
-//message.body = (-12147483649).ulong(); // long
-//message.body = (17223372036854778000).ulong(); // ulong
-
-//message.body = (121474.836490).float(); // float TODO check me
-//message.body = 12147483649.0.float(); // float TODO check me
-//message.body = (4294967296).uint();
-//message.body = (255).ubyte();
+            message.free();
+            messenger.free();
+        }
+    };
+
+    messenger.on('error', function(error) {console.log(error);});
+    messenger.on('work', pumpData);
+    messenger.setOutgoingWindow(1024);
+    messenger.start();
+
+    message.setAddress(address);
+    message.setSubject(subject);
 
-//message.body = ['Rod', 'Jane', 'Freddy'];
-//message.body = ['Rod', 'Jane', 'Freddy', {cat: true, donkey: 'hee haw'}];
+    message.body = msgtext;
 
-tracker = messenger.put(message);
+    tracker = messenger.put(message);
+} else {
+    console.error("spout.js should be run in Node.js");
+}
 

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/README Sat Sep 27 10:13:43 2014
@@ -7,7 +7,7 @@ with the Qpid Proton AMQP 1.0 protocol e
 Important Note - Modern Browser Needed
 ======================================
 
-The JavaScript binding requires ArrayBuffer/TypeArray and WebSocket support.
+The JavaScript binding requires ArrayBuffer/TypedArray and WebSocket support.
 Both of these are available in most "modern" browser versions. The author has
 only tried running on FireFox and Chrome, though recent Safari, Opera and IE10+
 *should* work too - YMMV. It might be possible to polyfill for older browsers
@@ -21,11 +21,10 @@ bindings to Proton are somewhat differen
 because of the restrictions of the execution environment. In particular it is
 very important to note that the JavaScript bindings by default use a WebSocket
 transport and not a TCP transport, so whilst it's possible to create Server style
-applications that clients can connect to (e.g. recv.js and send.js) it is very
-important to note that:
+applications that clients can connect to (e.g. recv.js and send.js) note that:
 
 JavaScript clients cannot *directly* talk to "normal" AMQP applications such as
-qpidd or the Java Broker because they use the traditional TCP transport.
+qpidd or (by default) the Java Broker because they use a standard TCP transport.
 
 This is a slightly irksome issue, but there's no getting away from it because
 it's a security restriction imposed by the browser environment.
@@ -38,14 +37,14 @@ also be possible to use native TCP for C
 only on the TODO list so if you want to talk to a "normal" AMQP application you
 must live with the WebSocket constraints.
 
-Option 1. proxy from WebSockets to TCP sockets
+Option 1. proxy from WebSockets to TCP sockets. The application
 <proton>/examples/messenger/javascript/proxy.js
-is a simple Node.js WebSocket<->TCP Socket proxy, simple doing:
+is a simple Node.js WebSocket<->TCP Socket proxy, simply doing:
 
 node proxy.js
 
 will stand up a proxy listening by default on WebSocket port 5673 and forwarding
-to TCP port 5672 (this is configurable for options do: node proxy.js -h)
+to TCP port 5672 (this is configurable, for options do: node proxy.js -h)
 
 Rather than using a stand-alone proxy it is possible to have applications stand
 up their own proxy (where lport = listen port, thost = target host and
@@ -124,7 +123,7 @@ emscripten itself depends upon.
 
 http://kripken.github.io/emscripten-site/docs/building_from_source/index.html#installing-from-source
 http://kripken.github.io/emscripten-site/docs/building_from_source/toolchain_what_is_needed.html
-provides instructions for installing emscripten and the "fastcomp" LLVM backend.
+provide instructions for installing emscripten and the "fastcomp" LLVM backend.
 This approach lets users use the "bleeding edge" version of emscripten on the
 "incoming" branch (pretty much analogous to building qpid/proton off svn trunk).
 This is the approach that the author of the JavaScript Bindings tends to use.
@@ -182,7 +181,7 @@ point for doing so.
 Documentation
 =============
 
-When you've successfully got a successful build do:
+When you've successfully got a working build do:
 
   make docs
 
@@ -208,12 +207,12 @@ It's important to realise that most of t
 the runtime uses a "virtual heap" to support the underlying malloc/free. This is
 implemented internally as an ArrayBuffer with a default size of 16777216.
 
-To allocate a larger heap an application must set the PROTON_HEAP_SIZE global.
+To allocate a larger heap an application must set the PROTON_TOTAL_MEMORY global.
 In Node.js this would look like (see send.js):
-PROTON_HEAP_SIZE = 50000000; // Note no var - it needs to be global.
+PROTON_TOTAL_MEMORY = 50000000; // Note no var - it needs to be global.
 
 In a browser it would look like (see send.html):
-<script type="text/javascript">PROTON_HEAP_SIZE = 50000000;</script>
+<script type="text/javascript">PROTON_TOTAL_MEMORY = 50000000;</script>
 
 2. Load the library and create a message and messenger.
 In Node.js this would look like (see send.js):
@@ -235,6 +234,7 @@ messenger.on('error', <error callback>);
 messenger.on('work', <work callback>);
 messenger.on('subscription', <subscription callback>);
 
+
 The work callback is triggered on WebSocket events, so in general you would use
 this to send and receive messages, for example in recv.js we have:
 
@@ -282,7 +282,7 @@ message.setSubject('UK.NEWS');
 message.body = ['Rod', 'Jane', 'Freddy', {cat: true, donkey: 'hee haw'}];
 
 
-The main things to bear in mind is that (particularly for sending messages) we
+The main thing to bear in mind is that (particularly for sending messages) we
 may need to use "adapters" to make sure values are correctly interpreted and
 encoded to the correct type in the AMQP type system. This is especially important
 when interoperating with a peer written in a strongly typed language (C/C++/Java).
@@ -295,7 +295,7 @@ message.body = new proton.Data.Uuid();
 // AMQP Symbol
 message.body = new proton.Data.Symbol("My Symbol");
 
-// Binary data (created from a String in this case).
+// Binary data (created from a gibberish String in this case).
 message.body = new proton.Data.Binary("Monkey Bathпогромзхцвбнм");
 
 // Binary data (Get a Uint8Array view of the data and directly access that).
@@ -313,7 +313,7 @@ message.body = new proton.Data.Binary([6
 Note that the implementation of proton.Data.Binary tries to minimise copying so
 it accesses the internal emscripten heap *directly* this requires memory management
 which is mostly handled transparently, but users need to be aware that the
-underlying memory is "owned" by the Message Object so if Binary data needs to
+underlying memory is "owned" by the Message Object, so if Binary data needs to
 be maintained after the next call to messenger.get(message); it must be
 *explicitly* copied. For more detail do "make docs" and see:
 <proton>/build/proton-c/bindings/javascript/html/proton.Data.Binary.html
@@ -356,14 +356,14 @@ message.body = ['Rod', 'Jane', 'Freddy',
 // primitives it is necessary to either use braces or use a "double dot" so that
 // the interpreter can disambiguate from a simple decimal point. The binding will
 // attempt to use the correct type such that message.body = 2147483647; would be
-// sent as an AMQP integer but because of the way JavaScript coerces integers
+// sent as an AMQP integer, but because of the way JavaScript coerces integers
 // message.body = 2147483647.0; would also be sent as an AMQP integer because
-// 2147483647.0 gets transparently conveted to 2147483647 by the interpreter so
+// 2147483647.0 gets transparently conveted to 2147483647 by the interpreter, so
 // to explicitly send this as an AMQP float we'd need to do:
 // message.body = 2147483647.0.float();
 
 // Some more number examples:
-message.body = 66..char();  // char
+message.body = 66..char();  // char - note double dot. (66).char(); works too.
 message.body = 2147483647;  // int
 message.body = -2147483649; // long
 message.body = 12147483649; // long

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/messenger.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/messenger.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/messenger.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/messenger.js Sat Sep 27 10:13:43 2014
@@ -431,8 +431,15 @@ _Messenger_['subscribe'] = function(sour
         this._check(Module['Error']['ERR']);
     }
 
-    subscription = new Subscription(subscription)
-    this._pendingSubscriptions.push(subscription);
+    // For peer subscriptions to this Messenger emit a subscription event
+    // immediately otherwise defer until the address is resolved remotely.
+    if (source.indexOf('~') !== -1) {
+        subscription = new Subscription(subscription, source);
+        this._emit('subscription', subscription);
+    } else {
+        subscription = new Subscription(subscription)
+        this._pendingSubscriptions.push(subscription);
+    }
     return subscription;
 };
 

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/module.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/module.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/module.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/module.js Sat Sep 27 10:13:43 2014
@@ -56,29 +56,43 @@
  * changed subsequently (the default size is 16*1024*1024 = 16777216).
  * <p>
  * Applications can specify the size of virtual heap that they require via the
- * global variable PROTON_HEAP_SIZE, this must be set <b>before</b> the library is
+ * global variable PROTON_TOTAL_MEMORY, this must be set <b>before</b> the library is
  * loaded e.g. in Node.js an application would do:
  * <pre>
- * PROTON_HEAP_SIZE = 50000000; // Note no var - it needs to be global.
+ * PROTON_TOTAL_MEMORY = 50000000; // Note no var - it needs to be global.
  * var proton = require('qpid-proton');
  * ...
  * </pre>
  * A browser based application would do:
  * <pre>
- * &lt;script type="text/javascript"&gt;PROTON_HEAP_SIZE = 50000000;&lt;/script&gt;
+ * &lt;script type="text/javascript"&gt;PROTON_TOTAL_MEMORY = 50000000;&lt;/script&gt;
  * &lt;script type="text/javascript" src="proton.js">&lt;/script&gt;
  * </pre>
+ * The global variable PROTON_TOTAL_STACK may be used in a similar way to increase
+ * the stack size from its default of 5*1024*1024 = 5242880. It is worth noting
+ * that Strings are allocated on the stack, so you may need this if you end up
+ * wanting to send very large strings.
  * @namespace proton
  */
 var Module = {};
 
-// If the global variable PROTON_HEAP_SIZE has been set by the application this
+// If the global variable PROTON_TOTAL_MEMORY has been set by the application this
 // will result in the emscripten heap getting set to the next multiple of
-// 16777216 above PROTON_HEAP_SIZE.
-if (typeof process === 'object' && typeof require === 'function' && global['PROTON_HEAP_SIZE']) {
-    Module['TOTAL_MEMORY'] = global['PROTON_HEAP_SIZE'];
-} else if (typeof window === 'object' && window['PROTON_HEAP_SIZE']) {
-    Module['TOTAL_MEMORY'] = window['PROTON_HEAP_SIZE'];
+// 16777216 above PROTON_TOTAL_MEMORY.
+if (typeof process === 'object' && typeof require === 'function') {
+    if (global['PROTON_TOTAL_MEMORY']) {
+        Module['TOTAL_MEMORY'] = global['PROTON_TOTAL_MEMORY'];
+    }
+    if (global['PROTON_TOTAL_STACK']) {
+        Module['TOTAL_STACK'] = global['PROTON_TOTAL_STACK'];
+    }
+} else if (typeof window === 'object') {
+    if (window['PROTON_TOTAL_MEMORY']) {
+        Module['TOTAL_MEMORY'] = window['PROTON_TOTAL_MEMORY'];
+    }
+    if (window['PROTON_TOTAL_STACK']) {
+        Module['TOTAL_STACK'] = window['PROTON_TOTAL_STACK'];
+    }
 }
 
 /*****************************************************************************/

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/subscription.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/subscription.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/subscription.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/subscription.js Sat Sep 27 10:13:43 2014
@@ -30,10 +30,13 @@
  * Subscriptions should never be *directly* instantiated by client code only via
  * Messenger.subscribe() or Messenger.incomingSubscription(), so we declare the
  * constructor in the scope of the package and don't export it via Module.
- * @constructor Subscription                                                              
+ * @constructor Subscription
+ * @param {number} subscription a pointer to the underlying subscription object.
+ * @param {string} address if the address is already known it can be (optionally) specified.
  */
-var Subscription = function(subscription) { // Subscription Constructor.
+var Subscription = function(subscription, address) { // Subscription Constructor.
     this._subscription = subscription;
+    this._address = address;
 };
 
 /**
@@ -62,6 +65,9 @@ Subscription.prototype['setContext'] = f
  * @returns the Subscription's Address.
  */
 Subscription.prototype['getAddress'] = function() {
+    if (this._address) {
+        return this._address;
+    }
     return Pointer_stringify(_pn_subscription_address(this._subscription));
 };
 

Modified: qpid/proton/branches/fadams-javascript-binding/tests/javascript/codec.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/tests/javascript/codec.js?rev=1627942&r1=1627941&r2=1627942&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/tests/javascript/codec.js (original)
+++ qpid/proton/branches/fadams-javascript-binding/tests/javascript/codec.js Sat Sep 27 10:13:43 2014
@@ -28,524 +28,542 @@
  */
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("codec.js should be run in Node.js");
-    return;
-}
-
-var unittest = require("./unittest.js");
-var assert = require("assert");
-var proton = require("qpid-proton");
-
-// Extend TestCase by creating a prototype instance and adding test methods as properties.
-var DataTest = new unittest.TestCase();
-
-DataTest.setUp = function() {
-    this.data = new proton.Data();
-};
-
-DataTest.tearDown = function() {
-    this.data.free();
-    this.data = null;
-};
-
-DataTest.testTopLevelNext = function() {
-    console.log("testTopLevelNext");
-    assert(this.data.next() === null);
-    this.data.putNULL();
-    this.data.putBOOL(false);
-    this.data.putINT(0);
-    assert(this.data.next() === null);
-    this.data.rewind();
-    assert(this.data.next() === proton.Data.NULL);
-    assert(this.data.next() === proton.Data.BOOL);
-    assert(this.data.next() === proton.Data.INT);
-    assert(this.data.next() === null);
-    console.log("OK\n");
-};
-
-DataTest.testNestedNext = function() {
-    console.log("testNestedNext");
-    assert(this.data.next() === null);
-    this.data.putNULL();
-    assert(this.data.next() === null);
-    this.data.putLISTNODE();
-    assert(this.data.next() === null);
-    this.data.putBOOL(false);
-    assert(this.data.next() === null);
-    this.data.rewind();
-    assert(this.data.next() === proton.Data.NULL);
-    assert(this.data.next() === proton.Data.LIST);
-    this.data.enter();
-    assert(this.data.next() === null);
-    this.data.putUBYTE(0);
-    assert(this.data.next() === null);
-    this.data.putUINT(0);
-    assert(this.data.next() === null);
-    this.data.putINT(0);
-    assert(this.data.next() === null);
-    this.data.exit();
-    assert(this.data.next() === proton.Data.BOOL);
-    assert(this.data.next() === null);
-
-    this.data.rewind();
-    assert(this.data.next() === proton.Data.NULL);
-    assert(this.data.next() === proton.Data.LIST);
-    assert(this.data.enter());
-    assert(this.data.next() === proton.Data.UBYTE);
-    assert(this.data.next() === proton.Data.UINT);
-    assert(this.data.next() === proton.Data.INT);
-    assert(this.data.next() === null);
-    assert(this.data.exit());
-    assert(this.data.next() === proton.Data.BOOL);
-    assert(this.data.next() === null);
-    console.log("OK\n");
-};
-
-DataTest.testEnterExit = function() {
-    console.log("testEnterExit");
-    assert(this.data.next() === null);
-    assert(!this.data.enter());
-    this.data.putLISTNODE();
-    assert(this.data.enter());
-    assert(this.data.next() === null);
-    this.data.putLISTNODE();
-    assert(this.data.enter());
-    this.data.putLISTNODE();
-    assert(this.data.enter());
-    assert(this.data.exit());
-    assert(this.data.getLISTNODE() === 0);
-    assert(this.data.exit());
-    assert(this.data.getLISTNODE() === 1);
-    assert(this.data.exit());
-    assert(this.data.getLISTNODE() === 1);
-    assert(!this.data.exit());
-    assert(this.data.getLISTNODE() === 1);
-    assert(this.data.next() === null);
-
-    this.data.rewind();
-    assert(this.data.next() === proton.Data.LIST);
-    assert(this.data.getLISTNODE() === 1);
-    assert(this.data.enter());
-    assert(this.data.next() === proton.Data.LIST);
-    assert(this.data.getLISTNODE() === 1);
-    assert(this.data.enter());
-    assert(this.data.next() === proton.Data.LIST);
-    assert(this.data.getLISTNODE() === 0);
-    assert(this.data.enter());
-    assert(this.data.next() === null);
-    assert(this.data.exit());
-    assert(this.data.getLISTNODE() === 0);
-    assert(this.data.exit());
-    assert(this.data.getLISTNODE() === 1);
-    assert(this.data.exit());
-    assert(this.data.getLISTNODE() === 1);
-    assert(!this.data.exit());
-    console.log("OK\n");
-};
-
-/**
- * This tests the "low level" putARRAYNODE/getARRAYNODE methods.
- * In general though applications would create a proton.Data.Array and use the
- * higher level putARRAY/getARRAY
- */
-DataTest._testArray = function(dtype, descriptor, atype, values) {
-    var values = Array.prototype.slice.apply(arguments, [3]);
-    dtype = (dtype == null) ? null : dtype.toUpperCase();
-    atype = atype.toUpperCase();
-
-    // Create an array node, enter it and put the descriptor (if present) and values.
-    this.data.putARRAYNODE(dtype != null, proton.Data[atype]);
-    this.data.enter();
-    if (dtype != null) {
+if (typeof process === 'object' && typeof require === 'function') {
+    var unittest = require("./unittest.js");
+    var assert = require("assert");
+
+    // Increase the virtual heap available to the emscripten compiled C runtime.
+    // This allows us to test a really big string.
+    PROTON_TOTAL_MEMORY = 140000000;
+    PROTON_TOTAL_STACK = 25000000; // Needs to be bigger than the biggest string.
+    var proton = require("qpid-proton");
+
+    // Extend TestCase by creating a prototype instance and adding test methods as properties.
+    var DataTest = new unittest.TestCase();
+
+    DataTest.setUp = function() {
+        this.data = new proton.Data();
+    };
+
+    DataTest.tearDown = function() {
+        this.data.free();
+        this.data = null;
+    };
+    
+    DataTest.testTopLevelNext = function() {
+        console.log("testTopLevelNext");
+        assert(this.data.next() === null);
+        this.data.putNULL();
+        this.data.putBOOL(false);
+        this.data.putINT(0);
+        assert(this.data.next() === null);
+        this.data.rewind();
+        assert(this.data.next() === proton.Data.NULL);
+        assert(this.data.next() === proton.Data.BOOL);
+        assert(this.data.next() === proton.Data.INT);
+        assert(this.data.next() === null);
+        console.log("OK\n");
+    };
+    
+    DataTest.testNestedNext = function() {
+        console.log("testNestedNext");
+        assert(this.data.next() === null);
+        this.data.putNULL();
+        assert(this.data.next() === null);
+        this.data.putLISTNODE();
+        assert(this.data.next() === null);
+        this.data.putBOOL(false);
+        assert(this.data.next() === null);
+        this.data.rewind();
+        assert(this.data.next() === proton.Data.NULL);
+        assert(this.data.next() === proton.Data.LIST);
+        this.data.enter();
+        assert(this.data.next() === null);
+        this.data.putUBYTE(0);
+        assert(this.data.next() === null);
+        this.data.putUINT(0);
+        assert(this.data.next() === null);
+        this.data.putINT(0);
+        assert(this.data.next() === null);
+        this.data.exit();
+        assert(this.data.next() === proton.Data.BOOL);
+        assert(this.data.next() === null);
+    
+        this.data.rewind();
+        assert(this.data.next() === proton.Data.NULL);
+        assert(this.data.next() === proton.Data.LIST);
+        assert(this.data.enter());
+        assert(this.data.next() === proton.Data.UBYTE);
+        assert(this.data.next() === proton.Data.UINT);
+        assert(this.data.next() === proton.Data.INT);
+        assert(this.data.next() === null);
+        assert(this.data.exit());
+        assert(this.data.next() === proton.Data.BOOL);
+        assert(this.data.next() === null);
+        console.log("OK\n");
+    };
+    
+    DataTest.testEnterExit = function() {
+        console.log("testEnterExit");
+        assert(this.data.next() === null);
+        assert(!this.data.enter());
+        this.data.putLISTNODE();
+        assert(this.data.enter());
+        assert(this.data.next() === null);
+        this.data.putLISTNODE();
+        assert(this.data.enter());
+        this.data.putLISTNODE();
+        assert(this.data.enter());
+        assert(this.data.exit());
+        assert(this.data.getLISTNODE() === 0);
+        assert(this.data.exit());
+        assert(this.data.getLISTNODE() === 1);
+        assert(this.data.exit());
+        assert(this.data.getLISTNODE() === 1);
+        assert(!this.data.exit());
+        assert(this.data.getLISTNODE() === 1);
+        assert(this.data.next() === null);
+    
+        this.data.rewind();
+        assert(this.data.next() === proton.Data.LIST);
+        assert(this.data.getLISTNODE() === 1);
+        assert(this.data.enter());
+        assert(this.data.next() === proton.Data.LIST);
+        assert(this.data.getLISTNODE() === 1);
+        assert(this.data.enter());
+        assert(this.data.next() === proton.Data.LIST);
+        assert(this.data.getLISTNODE() === 0);
+        assert(this.data.enter());
+        assert(this.data.next() === null);
+        assert(this.data.exit());
+        assert(this.data.getLISTNODE() === 0);
+        assert(this.data.exit());
+        assert(this.data.getLISTNODE() === 1);
+        assert(this.data.exit());
+        assert(this.data.getLISTNODE() === 1);
+        assert(!this.data.exit());
+        console.log("OK\n");
+    };
+    
+    /**
+     * This tests the "low level" putARRAYNODE/getARRAYNODE methods.
+     * In general though applications would create a proton.Data.Array and use the
+     * higher level putARRAY/getARRAY
+     */
+    DataTest._testArray = function(dtype, descriptor, atype, values) {
+        var values = Array.prototype.slice.apply(arguments, [3]);
+        dtype = (dtype == null) ? null : dtype.toUpperCase();
+        atype = atype.toUpperCase();
+    
+        // Create an array node, enter it and put the descriptor (if present) and values.
+        this.data.putARRAYNODE(dtype != null, proton.Data[atype]);
+        this.data.enter();
+        if (dtype != null) {
+            var putter = 'put' + dtype;
+            this.data[putter](descriptor);
+        }
+        var putter = 'put' + atype;
+        for (var i = 0; i < values.length; i++) {
+            this.data[putter](values[i]);
+        }
+        this.data.exit();
+    
+        // Check that we did indeed add an Array node
+        this.data.rewind();
+        assert(this.data.next() === proton.Data.ARRAY);
+    
+        // Get the count, described and type metadata from the array node and compare
+        // with the values we passed to putARRAYNODE.
+        var metadata = this.data.getARRAYNODE();
+        var count = metadata.count;
+        var described = metadata.described;
+        var type = metadata.type;
+    
+        assert(count === values.length);
+        if (dtype == null) {
+            assert(described === false);
+        } else {
+            assert(described === true);
+        }
+        assert(type === proton.Data[atype]);
+    
+        // Enter the array node and compare the descriptor and values with those that
+        // we put into the array.
+        assert(this.data.enter());
+        if (described) {
+            assert(this.data.next() === proton.Data[dtype]);
+            var getter = 'get' + dtype;
+            var gotten = this.data[getter]();
+            assert(gotten.toString() === descriptor.toString());
+        }
+        var getter = 'get' + atype;
+        for (var i = 0; i < values.length; i++) {
+            assert(this.data.next() === proton.Data[atype]);
+            var gotten = this.data[getter]();
+            assert(gotten.toString() === values[i].toString());
+        }
+        assert(this.data.next() === null);
+        assert(this.data.exit());
+    };
+    
+    DataTest.testStringArray = function() {
+        console.log("testStringArray");
+        this._testArray(null, null, "string", "one", "two", "three");
+    
+        // Now try using the proton.Data.Array class.
+        this.data.clear();
+        var put = new proton.Data.Array("STRING", ["four", "five", "six"]);
+        this.data.putARRAY(put);
+        var get = this.data.getARRAY();
+        assert(get.equals(put));
+        console.log("OK\n");
+    };
+    
+    DataTest.testDescribedStringArray = function() {
+        console.log("testDescribedStringArray");
+        this._testArray("symbol", "url", "string", "one", "two", "three");
+    
+        // Now try using the proton.Data.Array class.
+        this.data.clear();
+        var put = new proton.Data.Array("STRING", ["four", "five", "six"], new proton.Data.Symbol("url"));
+        this.data.putARRAY(put);
+        var get = this.data.getARRAY();
+        assert(get.equals(put));
+        console.log("OK\n");
+    };
+    
+    DataTest.testIntArray = function() {
+        console.log("testIntArray");
+        this._testArray(null, null, "int", 1, 2, 3);
+    
+        // Now try using the proton.Data.Array class.
+        this.data.clear();
+        var put = new proton.Data.Array("INT", [4, 5, 6]);
+        this.data.putARRAY(put);
+        var get = this.data.getARRAY();
+        assert(get.equals(put));
+        console.log("OK\n");
+    };
+    
+    DataTest.testUUIDArray = function() {
+        console.log("testUUIDArray");
+        this._testArray(null, null, "uuid", new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid());
+    
+        // Now try using the proton.Data.Array class.
+        this.data.clear();
+        var put = new proton.Data.Array("UUID", [new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid()]);
+        this.data.putARRAY(put);
+        var get = this.data.getARRAY();
+        assert(get.equals(put));
+        console.log("OK\n");
+    };
+
+    DataTest.testEmptyArray = function() {
+        console.log("testEmptyArray");
+        this._testArray(null, null, "null");
+
+        // Now try using the proton.Data.Array class.
+        this.data.clear();
+        var put = new proton.Data.Array();
+        this.data.putARRAY(put);
+        var get = this.data.getARRAY();
+        assert(get.equals(put));
+        console.log("OK\n");
+    };
+
+    DataTest.testDescribedEmptyArray = function() {
+        console.log("testDescribedEmptyArray");
+        this._testArray("long", 0, "null");
+    
+        // Now try using the proton.Data.Array class.
+        this.data.clear();
+        var put = new proton.Data.Array((0).long());
+        this.data.putARRAY(put);
+        var get = this.data.getARRAY();
+        assert(get.equals(put));
+        console.log("OK\n");
+    };  
+
+    DataTest._test = function(dtype, values) {
+        var values = Array.prototype.slice.apply(arguments, [1]);
+        var lastValue = values[values.length - 1];
+
+        // Default equality function. Note that we use valueOf because some of the
+        // types we are trying to compare (Symbol, Timestamp, Uuid etc.) are object
+        // types and we want to compare their value not whether they are the same object.
+        var eq = function(x, y) {return x.valueOf() === y.valueOf();};
+    
+        if (typeof lastValue === 'function') {
+            eq = values.pop();
+        }
+    
+        dtype = dtype.toUpperCase();
+        var ntype = proton.Data[dtype];
         var putter = 'put' + dtype;
-        this.data[putter](descriptor);
-    }
-    var putter = 'put' + atype;
-    for (var i = 0; i < values.length; i++) {
-        this.data[putter](values[i]);
-    }
-    this.data.exit();
-
-    // Check that we did indeed add an Array node
-    this.data.rewind();
-    assert(this.data.next() === proton.Data.ARRAY);
-
-    // Get the count, described and type metadata from the array node and compare
-    // with the values we passed to putARRAYNODE.
-    var metadata = this.data.getARRAYNODE();
-    var count = metadata.count;
-    var described = metadata.described;
-    var type = metadata.type;
-
-    assert(count === values.length);
-    if (dtype == null) {
-        assert(described === false);
-    } else {
-        assert(described === true);
-    }
-    assert(type === proton.Data[atype]);
-
-    // Enter the array node and compare the descriptor and values with those that
-    // we put into the array.
-    assert(this.data.enter());
-    if (described) {
-        assert(this.data.next() === proton.Data[dtype]);
         var getter = 'get' + dtype;
-        var gotten = this.data[getter]();
-        assert(gotten.toString() === descriptor.toString());
-    }
-    var getter = 'get' + atype;
-    for (var i = 0; i < values.length; i++) {
-        assert(this.data.next() === proton.Data[atype]);
-        var gotten = this.data[getter]();
-        assert(gotten.toString() === values[i].toString());
-    }
-    assert(this.data.next() === null);
-    assert(this.data.exit());
-};
-
-DataTest.testStringArray = function() {
-    console.log("testStringArray");
-    this._testArray(null, null, "string", "one", "two", "three");
-
-    // Now try using the proton.Data.Array class.
-    this.data.clear();
-    var put = new proton.Data.Array("STRING", ["four", "five", "six"]);
-    this.data.putARRAY(put);
-    var get = this.data.getARRAY();
-    assert(get.equals(put));
-    console.log("OK\n");
-};
-
-DataTest.testDescribedStringArray = function() {
-    console.log("testDescribedStringArray");
-    this._testArray("symbol", "url", "string", "one", "two", "three");
-
-    // Now try using the proton.Data.Array class.
-    this.data.clear();
-    var put = new proton.Data.Array("STRING", ["four", "five", "six"], new proton.Data.Symbol("url"));
-    this.data.putARRAY(put);
-    var get = this.data.getARRAY();
-    assert(get.equals(put));
-    console.log("OK\n");
-};
-
-DataTest.testIntArray = function() {
-    console.log("testIntArray");
-    this._testArray(null, null, "int", 1, 2, 3);
-
-    // Now try using the proton.Data.Array class.
-    this.data.clear();
-    var put = new proton.Data.Array("INT", [4, 5, 6]);
-    this.data.putARRAY(put);
-    var get = this.data.getARRAY();
-    assert(get.equals(put));
-    console.log("OK\n");
-};
-
-DataTest.testUUIDArray = function() {
-    console.log("testUUIDArray");
-    this._testArray(null, null, "uuid", new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid());
-
-    // Now try using the proton.Data.Array class.
-    this.data.clear();
-    var put = new proton.Data.Array("UUID", [new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid()]);
-    this.data.putARRAY(put);
-    var get = this.data.getARRAY();
-    assert(get.equals(put));
-    console.log("OK\n");
-};
-
-DataTest.testEmptyArray = function() {
-    console.log("testEmptyArray");
-    this._testArray(null, null, "null");
-
-    // Now try using the proton.Data.Array class.
-    this.data.clear();
-    var put = new proton.Data.Array();
-    this.data.putARRAY(put);
-    var get = this.data.getARRAY();
-    assert(get.equals(put));
-    console.log("OK\n");
-};
-
-DataTest.testDescribedEmptyArray = function() {
-    console.log("testDescribedEmptyArray");
-    this._testArray("long", 0, "null");
-
-    // Now try using the proton.Data.Array class.
-    this.data.clear();
-    var put = new proton.Data.Array((0).long());
-    this.data.putARRAY(put);
-    var get = this.data.getARRAY();
-    assert(get.equals(put));
-    console.log("OK\n");
-};
-
-DataTest._test = function(dtype, values) {
-    var values = Array.prototype.slice.apply(arguments, [1]);
-    var lastValue = values[values.length - 1];
-
-    // Default equality function. Note that we use valueOf because some of the
-    // types we are trying to compare (Symbol, Timestamp, Uuid etc.) are object
-    // types and we want to compare their value not whether they are the same object.
-    var eq = function(x, y) {return x.valueOf() === y.valueOf();};
-
-    if (typeof lastValue === 'function') {
-        eq = values.pop();
-    }
-
-    dtype = dtype.toUpperCase();
-    var ntype = proton.Data[dtype];
-    var putter = 'put' + dtype;
-    var getter = 'get' + dtype;
-
-    for (var i = 0; i < values.length; i++) {
-        var v = values[i];
-        /*
-         * Replace the array element with its value. We do this to make testing
-         * simpler for Binary elements. In the case of Binary putBINARY "consumes"
-         * the data, in other words ownership of the underlying raw data transfers
-         * to the Data object so the v object becomes "empty" after calling the
-         * putter. Calling its valueOf() happens to call its toString() which
-         * provides a stringified version of the Binary whilst also working for
-         * the other data types we want to test too.
-         */
-        values[i] = v.valueOf();
-        this.data[putter](v);
-        var gotten = this.data[getter]();
-        assert(eq(gotten, values[i]));
-    }
-
-    this.data.rewind();
-
-    for (var i = 0; i < values.length; i++) {
-        var v = values[i];
-        var vtype = this.data.next();
-        assert(vtype === ntype);
-        var gotten = this.data[getter]();
-        assert(eq(gotten, v));
-    }
-
-    // Test encode and decode methods.
-    var encoded = this.data.encode();
-    var copy = new proton.Data();
-    while (encoded) {
-        encoded = copy.decode(encoded);
-    }
-    copy.rewind();
-
-    for (var i = 0; i < values.length; i++) {
-        var v = values[i];
-        var vtype = copy.next();
-        assert(vtype === ntype);
-        var gotten = copy[getter]();
-        assert(eq(gotten, v));
-    }
-    copy.free();
-};
-
-DataTest.testInt = function() {
-    console.log("testInt");
-    this._test("int", 1, 2, 3, -1, -2, -3);
-    console.log("OK\n");
-
-};
-
-DataTest.testString = function() {
-    console.log("testString");
-    this._test("string", "one", "two", "three", "this is a test", "");
-    console.log("OK\n");
-};
-
-DataTest.testBigString = function() {
-    // Try a 2MB string, this is about as big as we can cope with using the default
-    // emscripten heap size. TODO add run-time mechanism to increase heap size.
-    console.log("testBigString");
-    var data = "";
-    for (var i = 0; i < 2000000; i++) {
-        data += "*";
-    }
-    var string = "start\n" + data + "\nfinish\n";
-    this._test("string", string);
-    console.log("OK\n");
-};
-
-DataTest.testFloat = function() {
-    console.log("testFloat");
-    // We have to use a special comparison here because JavaScript internally
-    // only uses doubles and converting between floats and doubles is imprecise.
-    this._test("float", 0, 1, 2, 3, 0.1, 0.2, 0.3, -1, -2, -3, -0.1, -0.2, -0.3,
-               function(x, y) {return (x - y < 0.000001);});
-    console.log("OK\n");
-};
-
-DataTest.testDouble = function() {
-    console.log("testDouble");
-    this._test("double", 0, 1, 2, 3, 0.1, 0.2, 0.3, -1, -2, -3, -0.1, -0.2, -0.3);
-    console.log("OK\n");
-};
-
-DataTest.testBinary = function() {
-    console.log("testBinary");
-    this._test("binary", new proton.Data.Binary(["t".char(), "h".char(), "i".char(), "s".char()]),
-               new proton.Data.Binary("is"), new proton.Data.Binary("a"), new proton.Data.Binary("test"),
-               new proton.Data.Binary("of"), new proton.Data.Binary("двоичные данные"));
-    console.log("OK\n");
-};
-
-DataTest.testSymbol = function() {
-    console.log("testSymbol");
-    this._test("symbol", new proton.Data.Symbol("this is a symbol test"),
-                         new proton.Data.Symbol("bleh"), new proton.Data.Symbol("blah"));
-    console.log("OK\n");
-};
-
-DataTest.testTimestamp = function() {
-    console.log("testTimestamp");
-    this._test("timestamp", new Date(0), new Date(12345), new Date(1000000));
-    console.log("OK\n");
-};
-
-DataTest.testChar = function() {
-    console.log("testChar");
-    this._test("char", 'a', 'b', 'c', '\u1234');
-    console.log("OK\n");
-};
-
-DataTest.testUUID = function() {
-    console.log("testUUID");
-    this._test("uuid", new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid());
-    console.log("OK\n");
-};
-
-/* TODO
-DataTest.testDecimal32 = function() {
-    console.log("testDecimal32");
-    //this._test("decimal32", 0, 1, 2, 3, 4, Math.pow(2, 30));
-};
-
-DataTest.testDecimal64 = function() {
-    console.log("testDecimal64");
-    //this._test("decimal64", 0, 1, 2, 3, 4, Math.pow(2, 60));
-};
-
-DataTest.testDecimal128 = function() {
-    console.log("testDecimal128");
-    // TODO
-};
+    
+        for (var i = 0; i < values.length; i++) {
+            var v = values[i];
+            /*
+             * Replace the array element with its value. We do this to make testing
+             * simpler for Binary elements. In the case of Binary putBINARY "consumes"
+             * the data, in other words ownership of the underlying raw data transfers
+             * to the Data object so the v object becomes "empty" after calling the
+             * putter. Calling its valueOf() happens to call its toString() which
+             * provides a stringified version of the Binary whilst also working for
+             * the other data types we want to test too.
+             */
+            values[i] = v.valueOf();
+            this.data[putter](v);
+            var gotten = this.data[getter]();
+            assert(eq(gotten, values[i]));
+        }
+    
+        this.data.rewind();
+    
+        for (var i = 0; i < values.length; i++) {
+            var v = values[i];
+            var vtype = this.data.next();
+            assert(vtype === ntype);
+            var gotten = this.data[getter]();
+            assert(eq(gotten, v));
+        }
+    
+        // Test encode and decode methods.
+        var encoded = this.data.encode();
+        var copy = new proton.Data();
+        while (encoded) {
+            encoded = copy.decode(encoded);
+        }
+        copy.rewind();
+    
+        for (var i = 0; i < values.length; i++) {
+            var v = values[i];
+            var vtype = copy.next();
+            assert(vtype === ntype);
+            var gotten = copy[getter]();
+            assert(eq(gotten, v));
+        }
+        copy.free();
+    };  
+    
+    DataTest.testInt = function() {
+        console.log("testInt");
+        this._test("int", 1, 2, 3, -1, -2, -3);
+        console.log("OK\n");
+    
+    };  
+
+    DataTest.testString = function() {
+        console.log("testString");
+        this._test("string", "one", "two", "three", "this is a test", "");
+        console.log("OK\n");
+    };  
+
+    DataTest.testBigString = function() {
+        // Try a 2MB string, this is about as big as we can cope with using the default
+        // emscripten heap size.
+        console.log("testBigString");
+        var data = "";
+        for (var i = 0; i < 2000000; i++) {
+            data += "*";
+        }
+        var string = "start\n" + data + "\nfinish\n";
+        this._test("string", string);
+        console.log("OK\n");
+    };  
+
+/* TODO - currently emscripten isn't respecting Module['TOTAL_STACK'] so setting PROTON_TOTAL_STACK doesn't actually increase the stack size.
+    DataTest.testReallyBigString = function() {
+        // Try a 20MB string, this needs a bigger emscripten heap size and more stack
+        // as the default stack is 5MB and strings are allocated on the stack.
+        console.log("testReallyBigString");
+        var data = "";
+        for (var i = 0; i < 20000000; i++) {
+            data += "*";
+        }
+        var string = "start\n" + data + "\nfinish\n";
+        this._test("string", string);
+        console.log("OK\n");
+    };
 */
 
-DataTest.testCopy = function() {
-    console.log("testCopy");
-    this.data.putDESCRIBEDNODE();
-    this.data.enter();
-    this.data.putULONG(123);
-    this.data.putMAPNODE();
-    this.data.enter();
-    this.data.putSTRING("pi");
-    this.data.putDOUBLE(3.14159265359);
-    this.data.exit();
-    this.data.exit();
-
-    var dst = this.data.copy();
-    var copy = dst.format();
-    var orig = this.data.format();
-    assert(copy === orig);
-    dst.free();
-    console.log("OK\n");
-};
-
-DataTest.testCopyNested = function() {
-    console.log("testCopyNested");
-    var nested = [1, 2, 3, [4, 5, 6], 7, 8, 9];
-    this.data.putObject(nested);
-    var dst = this.data.copy();
-    assert(dst.format() === this.data.format());
-    dst.free();
-    console.log("OK\n");
-};
-
-DataTest.testCopyNestedArray = function() {
-    console.log("testCopyNestedArray");
-    var nested = [new proton.Data.Array("LIST", [
-                    ["first",  [new proton.Data.Array("INT", [1, 2, 3]), "this"]],
-                    ["second", [new proton.Data.Array("INT", [1, 2, 3]), "is"]],
-                    ["third",  [new proton.Data.Array("INT", [1, 2, 3]), "fun"]]
-                    ]),
-                "end"];
-    this.data.putObject(nested);
-    var dst = this.data.copy();
-    assert(dst.format() === this.data.format());
-    dst.free();
-    console.log("OK\n");
-};
-
-DataTest.testRoundTrip = function() {
-    console.log("testRoundTrip");
-    var obj = {key: new Date(1234),
-               123: "blah",
-               c: "bleh",
-               desc: new proton.Data.Described("http://example.org", new proton.Data.Symbol("url")),
-               array: new proton.Data.Array("INT", [1, 2, 3]),
-               list: [1, 2, 3, null, 4],
-               boolean: true};
-    // Serialise obj into this.data.
-    this.data.putObject(obj);
-
-    // Encode this.data into a Binary representation.
-    var enc = this.data.encode();
-
-    // Create a new Data instance and decode from the Binary representation
-    // consuming the Binary contents in the process.
-    var data = new proton.Data();
-    data.decode(enc);
-
-    assert(data.format() === this.data.format());
-
-    // Deserialise from the copied Data instance into a new JavaScript Object.
-    data.rewind();
-    assert(data.next());
-    var copy = data.getObject();
-
-    // Create yet another Data instance and serialise the new Object into that.
-    var data1 = new proton.Data();
-    data1.putObject(copy);
-
-    // Compare the round tripped Data with the original one.
-    assert(data1.format() === this.data.format());
-
-    data.free();
-    data1.free();
-    console.log("OK\n");
-};
-
-DataTest.testLookup = function() {
-    console.log("testLookup");
-    var obj = {key: "value",
-               pi: 3.14159,
-               list: [1, 2, 3, 4]};
-    // Serialise obj into this.data.
-    this.data.putObject(obj);
-    this.data.rewind();
-    this.data.next();
-    this.data.enter();
-    this.data.narrow();
-    assert(this.data.lookup("pi"));
-    assert(this.data.getObject() === 3.14159);
-    this.data.rewind();
-    assert(this.data.lookup("key"));
-    assert(this.data.getObject() === "value");
-    this.data.rewind();
-    assert(this.data.lookup("list"));
-    assert(this.data.getObject().toString() === "1,2,3,4");
-    this.data.widen();
-    this.data.rewind();
-    assert(!this.data.lookup("pi"));
-    console.log("OK\n");
-};
-
-DataTest.run();
+    DataTest.testFloat = function() {
+        console.log("testFloat");
+        // We have to use a special comparison here because JavaScript internally
+        // only uses doubles and converting between floats and doubles is imprecise.
+        this._test("float", 0, 1, 2, 3, 0.1, 0.2, 0.3, -1, -2, -3, -0.1, -0.2, -0.3,
+                   function(x, y) {return (x - y < 0.000001);});
+        console.log("OK\n");
+    };  
+
+    DataTest.testDouble = function() {
+        console.log("testDouble");
+        this._test("double", 0, 1, 2, 3, 0.1, 0.2, 0.3, -1, -2, -3, -0.1, -0.2, -0.3);
+        console.log("OK\n");
+    };  
+
+    DataTest.testBinary = function() {
+        console.log("testBinary");
+        this._test("binary", new proton.Data.Binary(["t".char(), "h".char(), "i".char(), "s".char()]),
+                   new proton.Data.Binary("is"), new proton.Data.Binary("a"), new proton.Data.Binary("test"),
+                   new proton.Data.Binary("of"), new proton.Data.Binary("двоичные данные"));
+        console.log("OK\n");
+    };  
+
+    DataTest.testSymbol = function() {
+        console.log("testSymbol");
+        this._test("symbol", new proton.Data.Symbol("this is a symbol test"),
+                             new proton.Data.Symbol("bleh"), new proton.Data.Symbol("blah"));
+        console.log("OK\n");
+    };
+
+    DataTest.testTimestamp = function() {
+        console.log("testTimestamp");
+        this._test("timestamp", new Date(0), new Date(12345), new Date(1000000));
+        console.log("OK\n");
+    };  
+
+    DataTest.testChar = function() {
+        console.log("testChar");
+        this._test("char", 'a', 'b', 'c', '\u1234');
+        console.log("OK\n");
+    };  
+
+    DataTest.testUUID = function() {
+        console.log("testUUID");
+        this._test("uuid", new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid());
+        console.log("OK\n");
+    };
+
+    /* TODO
+    DataTest.testDecimal32 = function() {
+        console.log("testDecimal32");
+        //this._test("decimal32", 0, 1, 2, 3, 4, Math.pow(2, 30));
+    };
+
+    DataTest.testDecimal64 = function() {
+        console.log("testDecimal64");
+        //this._test("decimal64", 0, 1, 2, 3, 4, Math.pow(2, 60));
+    };  
+
+    DataTest.testDecimal128 = function() {
+        console.log("testDecimal128");
+        // TODO
+    };
+    */
+
+    DataTest.testCopy = function() {
+        console.log("testCopy");
+        this.data.putDESCRIBEDNODE();
+        this.data.enter();
+        this.data.putULONG(123);
+        this.data.putMAPNODE();
+        this.data.enter();
+        this.data.putSTRING("pi");
+        this.data.putDOUBLE(3.14159265359);
+        this.data.exit();
+        this.data.exit();
+    
+        var dst = this.data.copy();
+        var copy = dst.format();
+        var orig = this.data.format();
+        assert(copy === orig);
+        dst.free();
+        console.log("OK\n");
+    };  
+
+    DataTest.testCopyNested = function() {
+        console.log("testCopyNested");
+        var nested = [1, 2, 3, [4, 5, 6], 7, 8, 9];
+        this.data.putObject(nested);
+        var dst = this.data.copy();
+        assert(dst.format() === this.data.format());
+        dst.free();
+        console.log("OK\n");
+    };  
+
+    DataTest.testCopyNestedArray = function() {
+        console.log("testCopyNestedArray");
+        var nested = [new proton.Data.Array("LIST", [
+                        ["first",  [new proton.Data.Array("INT", [1, 2, 3]), "this"]],
+                        ["second", [new proton.Data.Array("INT", [1, 2, 3]), "is"]],
+                        ["third",  [new proton.Data.Array("INT", [1, 2, 3]), "fun"]]
+                        ]),
+                    "end"];
+        this.data.putObject(nested);
+        var dst = this.data.copy();
+        assert(dst.format() === this.data.format());
+        dst.free();
+        console.log("OK\n");
+    };
+
+    DataTest.testRoundTrip = function() {
+        console.log("testRoundTrip");
+        var obj = {key: new Date(1234),
+                   123: "blah",
+                   c: "bleh",
+                   desc: new proton.Data.Described("http://example.org", new proton.Data.Symbol("url")),
+                   array: new proton.Data.Array("INT", [1, 2, 3]),
+                   list: [1, 2, 3, null, 4],
+                   boolean: true};
+        // Serialise obj into this.data.
+        this.data.putObject(obj);
+    
+        // Encode this.data into a Binary representation.
+        var enc = this.data.encode();
+    
+        // Create a new Data instance and decode from the Binary representation
+        // consuming the Binary contents in the process.
+        var data = new proton.Data();
+        data.decode(enc);
+    
+        assert(data.format() === this.data.format());
+    
+        // Deserialise from the copied Data instance into a new JavaScript Object.
+        data.rewind();
+        assert(data.next());
+        var copy = data.getObject();
+    
+        // Create yet another Data instance and serialise the new Object into that.
+        var data1 = new proton.Data();
+        data1.putObject(copy);
+    
+        // Compare the round tripped Data with the original one.
+        assert(data1.format() === this.data.format());
+    
+        data.free();
+        data1.free();
+        console.log("OK\n");
+    };
+
+    DataTest.testLookup = function() {
+        console.log("testLookup");
+        var obj = {key: "value",
+                   pi: 3.14159,
+                   list: [1, 2, 3, 4]};
+        // Serialise obj into this.data.
+        this.data.putObject(obj);
+        this.data.rewind();
+        this.data.next();
+        this.data.enter();
+        this.data.narrow();
+        assert(this.data.lookup("pi"));
+        assert(this.data.getObject() === 3.14159);
+        this.data.rewind();
+        assert(this.data.lookup("key"));
+        assert(this.data.getObject() === "value");
+        this.data.rewind();
+        assert(this.data.lookup("list"));
+        assert(this.data.getObject().toString() === "1,2,3,4");
+        this.data.widen();
+        this.data.rewind();
+        assert(!this.data.lookup("pi"));
+        console.log("OK\n");
+    };  
 
+    DataTest.run();
+} else {
+    console.error("codec.js should be run in Node.js");
+}
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org