qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fad...@apache.org
Subject svn commit: r1624873 [1/3] - /qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/
Date Sun, 14 Sep 2014 16:57:10 GMT
Author: fadams
Date: Sun Sep 14 16:57:09 2014
New Revision: 1624873

URL: http://svn.apache.org/r1624873
Log:
Refactor JavaScript binding from a single ludicrously huge binding.js into a set of sub-modules that should hopefully make maintenance much simpler

Added:
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-array.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-binary.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-described.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-long.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-symbol.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-typed-number.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-uuid.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/error.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/message.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/messenger.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/module.js   (with props)
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/subscription.js   (with props)
Removed:
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/binding.js
Modified:
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt?rev=1624873&r1=1624872&r2=1624873&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt Sun Sep 14 16:57:09 2014
@@ -96,9 +96,7 @@ add_custom_command(
   DEPENDS ${PN_PATH}/src/protocol.h.py
   )
 
-# TODO put back -Werror once offending warnings get eliminated.
-#set(COMPILE_WARNING_FLAGS "-Werror -Wall -pedantic-errors -Wno-comment -Wno-warn-absolute-paths")
-set(COMPILE_WARNING_FLAGS "-Wall -pedantic-errors -Wno-comment -Wno-warn-absolute-paths")
+set(COMPILE_WARNING_FLAGS "-Werror -Wall -pedantic-errors -Wno-comment -Wno-warn-absolute-paths")
 
 # Explicitly set PLATFORM_DEFINITIONS to Linux ones for emscripten as we don't
 # want to inadvertently use Windows versions if we happen to be cross-compiling
@@ -223,7 +221,7 @@ set_target_properties(
   # fiddly with node.js packages. This behaviour might be reinstated if the
   # packaging mechanism improves.
 
-  LINK_FLAGS "-s \"EXPORT_NAME='proton'\" -s \"WEBSOCKET_SUBPROTOCOL='AMQPWSB10'\" ${EMSCRIPTEN_LINK_OPTIMISATIONS} --memory-init-file 0 --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/binding-open.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/binding.js --post-js ${CMAKE_CURRENT_SOURCE_DIR}/binding-close.js -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=\"[]\" -s EXPORTED_FUNCTIONS=\"['_pn_bytes', '_pn_error_text', '_pn_code', '_pn_messenger', '_pn_messenger_name', '_pn_messenger_set_blocking', '_pn_messenger_free', '_pn_messenger_errno', '_pn_messenger_error', '_pn_messenger_get_outgoing_window', '_pn_messenger_set_outgoing_window', '_pn_messenger_get_incoming_window', '_pn_messenger_set_incoming_window', '_pn_messenger_start', '_pn_messenger_stop', '_pn_messenger_stopped', '_pn_messenger_subscribe', '_pn_messenger_put', '_pn_messenger_status', '_pn_messenger_buffered', '_pn_messenger_settle', '_pn_messenger_outgoing_tracker', '_pn_messenger_work', '_pn_messenger_recv', '_pn_messenger_receiving', '_pn_messen
 ger_get', '_pn_messenger_incoming_tracker', '_pn_messenger_incoming_subscription', '_pn_messenger_accept', '_pn_messenger_reject', '_pn_messenger_outgoing', '_pn_messenger_incoming',  '_pn_messenger_route', '_pn_messenger_rewrite', '_pn_subscription_get_context', '_pn_subscription_set_context', '_pn_subscription_address', '_pn_message', '_pn_message_id', '_pn_message_correlation_id', '_pn_message_free', '_pn_message_errno', '_pn_message_error', '_pn_message_clear', '_pn_message_is_inferred', '_pn_message_set_inferred', '_pn_message_is_durable', '_pn_message_set_durable', '_pn_message_get_priority', '_pn_message_set_priority', '_pn_message_get_ttl', '_pn_message_set_ttl', '_pn_message_is_first_acquirer', '_pn_message_set_first_acquirer', '_pn_message_get_delivery_count', '_pn_message_set_delivery_count', '_pn_message_get_user_id', '_pn_message_set_user_id', '_pn_message_get_address', '_pn_message_set_address', '_pn_message_get_subject', '_pn_message_set_subject', '_pn_message_get_rep
 ly_to', '_pn_message_set_reply_to', '_pn_message_get_content_type', '_pn_message_set_content_type', '_pn_message_get_content_encoding', '_pn_message_set_content_encoding', '_pn_message_get_expiry_time', '_pn_message_set_expiry_time', '_pn_message_get_creation_time', '_pn_message_set_creation_time', '_pn_message_get_group_id', '_pn_message_set_group_id', '_pn_message_get_group_sequence', '_pn_message_set_group_sequence', '_pn_message_get_reply_to_group_id', '_pn_message_set_reply_to_group_id', '_pn_message_encode', '_pn_message_decode', '_pn_message_instructions', '_pn_message_annotations', '_pn_message_properties', '_pn_message_body', '_pn_data', '_pn_data_free', '_pn_data_error', '_pn_data_errno', '_pn_data_clear', '_pn_data_rewind', '_pn_data_next', '_pn_data_prev', '_pn_data_enter', '_pn_data_exit', '_pn_data_lookup', '_pn_data_narrow', '_pn_data_widen', '_pn_data_type', '_pn_data_encode', '_pn_data_decode', '_pn_data_put_list', '_pn_data_put_map', '_pn_data_put_array', '_pn_data
 _put_described', '_pn_data_put_null', '_pn_data_put_bool', '_pn_data_put_ubyte', '_pn_data_put_byte', '_pn_data_put_ushort', '_pn_data_put_short', '_pn_data_put_uint', '_pn_data_put_int', '_pn_data_put_char', '_pn_data_put_ulong', '_pn_data_put_long', '_pn_data_put_timestamp', '_pn_data_put_float', '_pn_data_put_double', '_pn_data_put_decimal32', '_pn_data_put_decimal64', '_pn_data_put_decimal128', '_pn_data_put_uuid', '_pn_data_put_binary', '_pn_data_put_string', '_pn_data_put_symbol', '_pn_data_get_list', '_pn_data_get_map', '_pn_data_get_array', '_pn_data_is_array_described', '_pn_data_get_array_type', '_pn_data_is_described', '_pn_data_is_null', '_pn_data_get_bool', '_pn_data_get_ubyte', '_pn_data_get_byte', '_pn_data_get_ushort', '_pn_data_get_short', '_pn_data_get_uint', '_pn_data_get_int', '_pn_data_get_char', '_pn_data_get_ulong', '_pn_data_get_long', '_pn_data_get_timestamp', '_pn_data_get_float', '_pn_data_get_double', '_pn_data_get_decimal32', '_pn_data_get_decimal64', '_
 pn_data_get_decimal128', '_pn_data_get_uuid', '_pn_data_get_binary', '_pn_data_get_string', '_pn_data_get_symbol', '_pn_data_copy', '_pn_data_format', '_pn_data_dump']\""
+  LINK_FLAGS "-s \"EXPORT_NAME='proton'\" -s \"WEBSOCKET_SUBPROTOCOL='AMQPWSB10'\" ${EMSCRIPTEN_LINK_OPTIMISATIONS} --memory-init-file 0 --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/binding-open.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/module.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/error.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/messenger.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/subscription.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/message.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-uuid.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-symbol.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-described.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-array.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-typed-number.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-long.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/data-binary.js --post-js ${CMAKE_CURRENT_SOURCE_DIR}/binding-close.js -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=\"[]\" -s EXPORTED_FUNCTIONS=\"['_pn_bytes', '_pn_error_tex
 t', '_pn_code', '_pn_messenger', '_pn_messenger_name', '_pn_messenger_set_blocking', '_pn_messenger_free', '_pn_messenger_errno', '_pn_messenger_error', '_pn_messenger_get_outgoing_window', '_pn_messenger_set_outgoing_window', '_pn_messenger_get_incoming_window', '_pn_messenger_set_incoming_window', '_pn_messenger_start', '_pn_messenger_stop', '_pn_messenger_stopped', '_pn_messenger_subscribe', '_pn_messenger_put', '_pn_messenger_status', '_pn_messenger_buffered', '_pn_messenger_settle', '_pn_messenger_outgoing_tracker', '_pn_messenger_work', '_pn_messenger_recv', '_pn_messenger_receiving', '_pn_messenger_get', '_pn_messenger_incoming_tracker', '_pn_messenger_incoming_subscription', '_pn_messenger_accept', '_pn_messenger_reject', '_pn_messenger_outgoing', '_pn_messenger_incoming',  '_pn_messenger_route', '_pn_messenger_rewrite', '_pn_subscription_get_context', '_pn_subscription_set_context', '_pn_subscription_address', '_pn_message', '_pn_message_id', '_pn_message_correlation_id', '
 _pn_message_free', '_pn_message_errno', '_pn_message_error', '_pn_message_clear', '_pn_message_is_inferred', '_pn_message_set_inferred', '_pn_message_is_durable', '_pn_message_set_durable', '_pn_message_get_priority', '_pn_message_set_priority', '_pn_message_get_ttl', '_pn_message_set_ttl', '_pn_message_is_first_acquirer', '_pn_message_set_first_acquirer', '_pn_message_get_delivery_count', '_pn_message_set_delivery_count', '_pn_message_get_user_id', '_pn_message_set_user_id', '_pn_message_get_address', '_pn_message_set_address', '_pn_message_get_subject', '_pn_message_set_subject', '_pn_message_get_reply_to', '_pn_message_set_reply_to', '_pn_message_get_content_type', '_pn_message_set_content_type', '_pn_message_get_content_encoding', '_pn_message_set_content_encoding', '_pn_message_get_expiry_time', '_pn_message_set_expiry_time', '_pn_message_get_creation_time', '_pn_message_set_creation_time', '_pn_message_get_group_id', '_pn_message_set_group_id', '_pn_message_get_group_sequence'
 , '_pn_message_set_group_sequence', '_pn_message_get_reply_to_group_id', '_pn_message_set_reply_to_group_id', '_pn_message_encode', '_pn_message_decode', '_pn_message_instructions', '_pn_message_annotations', '_pn_message_properties', '_pn_message_body', '_pn_data', '_pn_data_free', '_pn_data_error', '_pn_data_errno', '_pn_data_clear', '_pn_data_rewind', '_pn_data_next', '_pn_data_prev', '_pn_data_enter', '_pn_data_exit', '_pn_data_lookup', '_pn_data_narrow', '_pn_data_widen', '_pn_data_type', '_pn_data_encode', '_pn_data_decode', '_pn_data_put_list', '_pn_data_put_map', '_pn_data_put_array', '_pn_data_put_described', '_pn_data_put_null', '_pn_data_put_bool', '_pn_data_put_ubyte', '_pn_data_put_byte', '_pn_data_put_ushort', '_pn_data_put_short', '_pn_data_put_uint', '_pn_data_put_int', '_pn_data_put_char', '_pn_data_put_ulong', '_pn_data_put_long', '_pn_data_put_timestamp', '_pn_data_put_float', '_pn_data_put_double', '_pn_data_put_decimal32', '_pn_data_put_decimal64', '_pn_data_put
 _decimal128', '_pn_data_put_uuid', '_pn_data_put_binary', '_pn_data_put_string', '_pn_data_put_symbol', '_pn_data_get_list', '_pn_data_get_map', '_pn_data_get_array', '_pn_data_is_array_described', '_pn_data_get_array_type', '_pn_data_is_described', '_pn_data_is_null', '_pn_data_get_bool', '_pn_data_get_ubyte', '_pn_data_get_byte', '_pn_data_get_ushort', '_pn_data_get_short', '_pn_data_get_uint', '_pn_data_get_int', '_pn_data_get_char', '_pn_data_get_ulong', '_pn_data_get_long', '_pn_data_get_timestamp', '_pn_data_get_float', '_pn_data_get_double', '_pn_data_get_decimal32', '_pn_data_get_decimal64', '_pn_data_get_decimal128', '_pn_data_get_uuid', '_pn_data_get_binary', '_pn_data_get_string', '_pn_data_get_symbol', '_pn_data_copy', '_pn_data_format', '_pn_data_dump']\""
   )
 
 # This command packages up the compiled proton.js into a node.js package called
@@ -259,7 +257,19 @@ if (NODE_JSDOC_FOUND)
     message(STATUS "Documentation Enabled. Using ${JSDOC_EXE} to build JavaScript docs")
     add_custom_target(docs-js COMMAND ${JSDOC_EXE}
                       -d ${CMAKE_CURRENT_BINARY_DIR}/html
-                      ${CMAKE_CURRENT_SOURCE_DIR}/binding.js)
+                      ${CMAKE_CURRENT_SOURCE_DIR}/module.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/error.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/messenger.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/subscription.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/message.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-uuid.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-symbol.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-described.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-array.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-typed-number.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-long.js
+                      ${CMAKE_CURRENT_SOURCE_DIR}/data-binary.js)
     add_dependencies(docs docs-js)
 
 endif (NODE_JSDOC_FOUND)

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-array.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-array.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-array.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-array.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.Array                             */
+/*                                                                           */
+/*****************************************************************************/
+
+/**
+ * TODO make this behave more like a native JavaScript Array: http://www.bennadel.com/blog/2292-extending-javascript-arrays-while-keeping-native-bracket-notation-functionality.htm
+ * Create a proton.Data.Array.
+ * @classdesc
+ * This class represents an AMQP Array.
+ * @constructor proton.Data.Array
+ * @param {string|number} type the type of the Number either as a string or number.
+ *        Stored internally as a string corresponding to one of the TypeNames.       
+ * @param {Array|TypedArray} elements the Native JavaScript Array or TypedArray that we wish to serialise.
+ * @param {object} descriptor an optional object describing the type.
+ */
+Data['Array'] = function(type, elements, descriptor) { // Data.Array Constructor.
+    // This block caters for an empty Array or a Described empty Array.
+    if (arguments.length < 2) {
+        descriptor = type;
+        type = 'NULL';
+        elements = [];
+    }
+
+    this['type']  = (typeof type === 'number') ? Data['TypeNames'][type] : type;
+    this['elements'] = elements;
+    this['descriptor'] = descriptor;
+};
+
+/**
+ * @method toString
+ * @memberof! proton.Data.Array#
+ * @returns {string} the String form of a {@link proton.Data.Array}.
+ */
+Data['Array'].prototype.toString = function() {
+    var descriptor = (this['descriptor'] == null) ? '' : ':' + this['descriptor'];
+    return this['type'] + 'Array' + descriptor + '[' + this['elements'] + ']';
+};
+
+/**
+ * @method valueOf
+ * @memberof! proton.Data.Array#
+ * @returns {Array} the elements of the {@link proton.Data.Array}.
+ */
+Data['Array'].prototype.valueOf = function() {
+    return this['elements'];
+};
+
+/**
+ * Compare two instances of proton.Data.Array for equality. N.B. this method
+ * compares the value of every Array element so its performance is O(n).
+ * @method equals
+ * @memberof! proton.Data.Array#
+ * @param {proton.Data.Array} rhs the instance we wish to compare this instance with.
+ * @returns {boolean} true iff the two compared instances are equal.
+ */
+Data['Array'].prototype['equals'] = function(rhs) {
+    if (rhs instanceof Data['Array'] &&
+        // Check the string value of the descriptors.
+        (('' + this['descriptor']) === ('' + rhs['descriptor'])) &&
+        (this['type'] === rhs['type'])) {
+        var elements = this['elements'];
+        var relements = rhs['elements'];
+        var length = elements.length;
+        if (length === relements.length) {
+            for (var i = 0; i < length; i++) {
+                if (elements[i].valueOf() !== relements[i].valueOf()) {
+                    return false;
+                }
+            }
+            return true;
+        } else {
+            return false;
+        }
+    } else {
+        return false;
+    }
+};
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-array.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-binary.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-binary.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-binary.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-binary.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.Binary                            */
+/*                                                                           */
+/*****************************************************************************/
+
+/**
+ * Create a proton.Data.Binary. This constructor takes one or two parameters.
+ * The first parameter may serve different purposes depending on its type;
+ * If value is a number then it represents the size of the Binary data buffer,
+ * if it is a string then we copy the string to the buffer, if it is an Array
+ * or a TypedArray then we copy the data to the buffer. The optional second
+ * parameter is a pointer to the data in an internal data store. If start is
+ * not specified then the number of bytes specified in the first parameter
+ * will be allocated in the internal data store and start will point to the
+ * start of that block of data.
+ * @classdesc
+ * This class represents an AMQP Binary type. This class allows us to create and
+ * use raw binary data and map it efficiently between JavaScript client code and
+ * the underlying implementation, where all data is managed on a "virtual heap".
+ * <p>
+ * Client applications should generally not have to care about memory management
+ * as, for most common use cases, client applications would "transfer ownership"
+ * to a "container" which would then "own" the underlying data and free the data
+ * held by the {@link proton.Data.Binary}.
+ * <p>
+ * As an example one common use-case would be where client application creates a
+ * {@link proton.Data.Binary} specifying the required size. It would usually then
+ * call getBuffer() to access the underlying Uint8Array. At this point the client
+ * "owns" the data and so would have to call free() if it did nothing more with
+ * the Binary, however when {@link proton.Data.putBINARY} is called the ownership
+ * of the raw data on the virtual heap transfers from the Binary to the Data and
+ * the client no longer needs to call free() itself. In this case the putBINARY()
+ * call transfers ownership and can then safely call free() on the Binary.
+ * <p>
+ * Conversely a common use-case when receiving data is where a Binary may be
+ * created by {@link proton.Data#getBINARY}. In this case the Binary is simply a
+ * "view" onto the bytes owned by the Data instance. A client application can
+ * safely access the bytes from the view, but if it wishes to use the bytes beyond
+ * the scope of the Data instance (e.g. after the next {@link proton.Messenger#get}
+ * call then the client must explicitly *copy* the bytes into a new buffer, for
+ * example via copyBuffer().
+ * <p>
+ * Most of the {@link proton.Data} methods that take {@link proton.Data.Binary}
+ * as a parameter "consume" the underlying data and take responsibility for
+ * freeing it from the heap e.g. {@link proton.Data#putBINARY}, {@link proton.Data#decode}.
+ * For the methods that return a {@link proton.Data.Binary} the call to
+ * {@link proton.Data#getBINARY}, which is the most common case, returns a Binary
+ * that has a "view" of the underlying data that is actually owned by the Data
+ * instance and thus doesn't need to be explicitly freed on the Binary. The call
+ * to {@link proton.Data#encode} however returns a Binary that represents a *copy*
+ * of the underlying data, in this case (like a client calling new proton.Data.Binary)
+ * the client takes responsibility for freeing the data, unless of course it is
+ * subsequently passed to a method that will consume the data (putBINARY/decode).
+ * @constructor proton.Data.Binary
+ * @param {(number|string|Array|TypedArray)} value If value is a number then it 
+ *        represents the size of the Binary data buffer, if it is a string then
+ *        we copy the string to the buffer, if it is an Array or a TypedArray
+ *        then we copy the data to the buffer. N.B. although convenient do bear
+ *        in mind that using a mechanism other than constructing with a simple
+ *        size will result in some form of additional data copy.
+ * @param {number} start an optional pointer to the start of the Binary data buffer.
+ */
+Data['Binary'] = function(value, start) { // Data.Binary Constructor.
+    /**
+     * If the start pointer is specified then the underlying binary data is owned
+     * by another object, so we set the call to free to be a null function. If
+     * the start pointer is not passed then we allocate storage of the specified
+     * size on the emscripten heap and set the call to free to free the data from
+     * the emscripten heap.
+     */
+    var size = value;
+    if (start) {
+        this['free'] = function() {};
+    } else { // Create Binary from Array, ArrayBuffer or TypedArray.
+        var hasArrayBuffer = (typeof ArrayBuffer === 'function');
+        if (Data.isArray(value) ||
+            (hasArrayBuffer && value instanceof ArrayBuffer) || 
+            (value.buffer && hasArrayBuffer && value.buffer instanceof ArrayBuffer)) {
+            value = new Uint8Array(value);
+            size = value.length;
+            start = _malloc(size); // Allocate storage from emscripten heap.
+            Module['HEAPU8'].set(value, start); // Copy the data to the emscripten heap.
+        } else if (Data.isString(value)) { // Create Binary from native string
+            value = unescape(encodeURIComponent(value)); // Create a C-like UTF representation.
+            size = value.length;
+            start = _malloc(size); // Allocate storage from emscripten heap.
+            for (var i = 0; i < size; i++) {
+                setValue(start + i, value.charCodeAt(i), 'i8', 1);
+            }
+        } else { // Create unpopulated Binary of specified size.
+            // If the type is not a number by this point then an unrecognised data
+            // type has been passed so we create a zero length Binary.
+            size = Data.isNumber(size) ? size : 0;
+            start = _malloc(size); // Allocate storage from emscripten heap.
+        }
+        this['free'] = function() {
+            _free(this.start);
+            this.size = 0;
+            this.start = 0;
+            // Set free to a null function to prevent possibility of a "double free".
+            this['free'] = function() {};
+        };
+    }
+
+    this.size = size;
+    this.start = start;
+};
+
+/**
+ * Get a Uint8Array view of the data. N.B. this is just a *view* of the data,
+ * which will go out of scope on the next call to {@link proton.Messenger.get}. If
+ * a client wants to retain the data then copy should be used to explicitly
+ * create a copy of the data which the client then owns to do with as it wishes.
+ * @method getBuffer
+ * @returns {Uint8Array} a new Uint8Array view of the data.
+ * @memberof! proton.Data.Binary#
+ */
+Data['Binary'].prototype['getBuffer'] = function() {
+    return new Uint8Array(HEAPU8.buffer, this.start, this.size);
+};
+
+/**
+ * Explicitly create a *copy* of the Binary, copying the underlying binary data too.
+ * @method copy
+ * @param {number} offset an optional offset into the underlying buffer from
+ *        where we want to copy the data, default is zero.
+ * @param {number} n an optional number of bytes to copy, default is this.size - offset.
+ * @returns {proton.Data.Binary} a new {@link proton.Data.Binary} created by copying the underlying binary data.
+ * @memberof! proton.Data.Binary#
+ */
+Data['Binary'].prototype['copy'] = function(offset, n) {
+    offset = offset | 0;
+    n = n ? n : (this.size - offset);
+
+    if (offset >= this.size) {
+        offset = 0;
+        n = 0;
+    } else if ((offset + n) > this.size) {
+        n = this.size - offset; // Clamp length
+    }
+
+    var start = _malloc(n); // Allocate storage from emscripten heap.
+    _memcpy(start, this.start + offset, n); // Copy the raw data to new buffer.
+
+    return new Data['Binary'](n, start);
+};
+
+/**
+ * Converts the {@link proton.Data.Binary} to a string. This is clearly most
+ * useful when the binary data is actually a binary representation of a string
+ * such as a C style ASCII string.
+ * @method toString
+ * @memberof! proton.Data.Binary#
+ * @returns {string} the String form of a {@link proton.Data.Binary}.
+ */
+Data['Binary'].prototype.toString = Data['Binary'].prototype.valueOf = function() {
+    // Create a native JavaScript String from the start/size information.
+    return Pointer_stringify(this.start, this.size);
+};
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-binary.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-described.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-described.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-described.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-described.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.Described                         */
+/*                                                                           */
+/*****************************************************************************/
+
+/**
+ * Create a proton.Data.Described.
+ * @classdesc
+ * This class represents an AMQP Described.
+ * @constructor proton.Data.Described
+ * @param {object} value the value of the described type.
+ * @param {string} descriptor an optional string describing the type.
+ * @property {object} value the actual value of the described type.
+ * @property {string} descriptor a string describing the type.
+ */
+Data['Described'] = function(value, descriptor) { // Data.Described Constructor.
+    this['value'] = value;
+    this['descriptor'] = descriptor;
+};
+
+/**
+ * @method toString
+ * @memberof! proton.Data.Described#
+ * @returns {string} the String form of a {@link proton.Data.Described}.
+ */
+Data['Described'].prototype.toString = function() {
+    return 'Described(' + this['value'] + ', ' + this['descriptor'] + ')';
+};
+
+/**
+ * @method valueOf
+ * @memberof! proton.Data.Described#
+ * @returns {object} the value of the {@link proton.Data.Described}.
+ */
+Data['Described'].prototype.valueOf = function() {
+    return this['value'];
+};
+
+/**
+ * Compare two instances of proton.Data.Described for equality.
+ * @method equals
+ * @memberof! proton.Data.Described#
+ * @param {proton.Data.Described} rhs the instance we wish to compare this instance with.
+ * @returns {boolean} true iff the two compared instances are equal.
+ */
+Data['Described'].prototype['equals'] = function(rhs) {
+    if (rhs instanceof Data['Described']) {
+        return ((this['descriptor'] === rhs['descriptor']) && (this['value'] === rhs['value']));
+    } else {
+        return false;
+    }
+};
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-described.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-long.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-long.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-long.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-long.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.Long                              */
+/*                                                                           */
+/*****************************************************************************/
+
+/**
+ * Create a proton.Data.Long.
+ * @classdesc
+ * This class represents a 64 bit Integer value. It is used primarily to pass and
+ * return 64 bit Integer values to and from the emscripten compiled proton-c library.
+ * This class is needed because JavaScript cannot natively represent 64 bit
+ * Integers with sufficient accuracy.
+ * @constructor proton.Data.Long
+ * @param {number} low the least significant word.
+ * @param {number} high the most significant word.
+ */
+// Use dot notation as it is a "protected" inner class not exported from the closure.
+Data.Long = function(low, high) { // Data.Long Constructor.
+    this.low  = low  | 0;  // force into 32 signed bits.
+    this.high = high | 0;  // force into 32 signed bits.
+};
+
+// proton.Data.Long constants.
+Data.Long.TWO_PWR_16_DBL_ = 1 << 16;
+Data.Long.TWO_PWR_32_DBL_ = Data.Long.TWO_PWR_16_DBL_ * Data.Long.TWO_PWR_16_DBL_;
+Data.Long.TWO_PWR_64_DBL_ = Data.Long.TWO_PWR_32_DBL_ * Data.Long.TWO_PWR_32_DBL_;
+Data.Long.TWO_PWR_63_DBL_ = Data.Long.TWO_PWR_64_DBL_ / 2;
+Data.Long.MAX_VALUE = new Data.Long(0xFFFFFFFF | 0, 0x7FFFFFFF | 0);
+Data.Long.MIN_VALUE = new Data.Long(0, 0x80000000 | 0);
+Data.Long.ZERO = new Data.Long(0, 0);
+Data.Long.ONE  = new Data.Long(1, 0);
+
+/**
+ * @method fromNumber
+ * @memberof! proton.Data.Long#
+ * @returns {proton.Data.Long} an instance of {@link proton.Data.Long} created
+ *          using a native JavaScript number.
+ */
+Data.Long.fromNumber = function(value) {
+    if (isNaN(value) || !isFinite(value)) {
+        return Data.Long.ZERO;
+    } else if (value <= -Data.Long.TWO_PWR_63_DBL_) {
+        return Data.Long.MIN_VALUE;
+    } else if (value + 1 >= Data.Long.TWO_PWR_63_DBL_) {
+        return Data.Long.MAX_VALUE;
+    } else if (value < 0) {
+        return Data.Long.fromNumber(-value).negate();
+    } else {
+      return new Data.Long(
+          (value % Data.Long.TWO_PWR_32_DBL_) | 0,
+          (value / Data.Long.TWO_PWR_32_DBL_) | 0);
+    }
+};
+
+/**
+ * Return the twos complement of this instance.
+ * @method negate
+ * @memberof! proton.Data.Long#
+ * @returns {proton.Data.Long} the twos complement of this instance.
+ */
+Data.Long.prototype.negate = function() {
+    if (this.equals(Data.Long.MIN_VALUE)) {
+        return Data.Long.MIN_VALUE;
+    } else {
+        return this.not().add(Data.Long.ONE);
+    }
+};
+
+/**
+ * Add two instances of {@link proton.Data.Long}.
+ * @method add
+ * @memberof! proton.Data.Long#
+ * @param {proton.Data.Long} rhs the instance we wish to add to this instance.
+ * @returns {proton.Data.Long} the sum of this value and the rhs.
+ */
+Data.Long.prototype.add = function(rhs) {
+    // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
+
+    var a48 = this.high >>> 16;
+    var a32 = this.high & 0xFFFF;
+    var a16 = this.low >>> 16;
+    var a00 = this.low & 0xFFFF;
+
+    var b48 = rhs.high >>> 16;
+    var b32 = rhs.high & 0xFFFF;
+    var b16 = rhs.low >>> 16;
+    var b00 = rhs.low & 0xFFFF;
+
+    var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
+    c00 += a00 + b00;
+    c16 += c00 >>> 16;
+    c00 &= 0xFFFF;
+    c16 += a16 + b16;
+    c32 += c16 >>> 16;
+    c16 &= 0xFFFF;
+    c32 += a32 + b32;
+    c48 += c32 >>> 16;
+    c32 &= 0xFFFF;
+    c48 += a48 + b48;
+    c48 &= 0xFFFF;
+    return new Data.Long((c16 << 16) | c00, (c48 << 16) | c32);
+};
+
+/**
+ * Return the complement of this instance.
+ * @method not
+ * @memberof! proton.Data.Long#
+ * @returns {proton.Data.Long} the complement of this instance.
+ */
+Data.Long.prototype.not = function() {
+    return new Data.Long(~this.low, ~this.high);
+};
+
+/**
+ * Compare two instances of {@link proton.Data.Long} for equality.
+ * @method equals
+ * @memberof! proton.Data.Long#
+ * @param {proton.Data.Long} rhs the instance we wish to compare this instance with.
+ * @returns {boolean} true iff the two compared instances are equal.
+ */
+Data.Long.prototype.equals = function(other) {
+    return (this.high == other.high) && (this.low == other.low);
+};
+
+/**
+ * @method getHighBits
+ * @memberof! proton.Data.Long#
+ * @returns {number} the most significant word of a {@link proton.Data.Long}.
+ */
+Data.Long.prototype.getHighBits = function() {
+    return this.high;
+};
+
+/**
+ * @method getLowBits
+ * @memberof! proton.Data.Long#
+ * @returns {number} the least significant word of a {@link proton.Data.Long}.
+ */
+Data.Long.prototype.getLowBits = function() {
+    return this.low;
+};
+
+/**
+ * @method getLowBitsUnsigned
+ * @memberof! proton.Data.Long#
+ * @returns {number} the least significant word of a {@link proton.Data.Long}
+ *          as an unsigned value.
+ */
+Data.Long.prototype.getLowBitsUnsigned = function() {
+    return (this.low >= 0) ? this.low : Data.Long.TWO_PWR_32_DBL_ + this.low;
+};
+
+/**
+ * @method toNumber
+ * @memberof! proton.Data.Long#
+ * @returns {number} a native JavaScript number (with possible loss of precision).
+ */
+Data.Long.prototype.toNumber = function() {
+    return (this.high * Data.Long.TWO_PWR_32_DBL_) + this.getLowBitsUnsigned();
+};
+
+/**
+ * @method toString
+ * @memberof! proton.Data.Long#
+ * @returns {string} the String form of a {@link proton.Data.Long}.
+ */
+Data.Long.prototype.toString = function() {
+    return this.high + ':' + this.getLowBitsUnsigned();
+};
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-long.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-symbol.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-symbol.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-symbol.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-symbol.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.Symbol                            */
+/*                                                                           */
+/*****************************************************************************/
+
+/**
+ * Create a proton.Data.Symbol.
+ * @classdesc
+ * This class represents an AMQP Symbol. This class is necessary primarily as a
+ * way to enable us to distinguish between a native String and a Symbol in the
+ * JavaScript type system.
+ * @constructor proton.Data.Symbol
+ * @param {string} s a symbol.
+ */
+Data['Symbol'] = function(s) { // Data.Symbol Constructor.
+    this.value = s;
+};
+
+/**
+ * @method toString
+ * @memberof! proton.Data.Symbol#
+ * @returns {string} the String form of a {@link proton.Data.Symbol}.
+ */
+Data['Symbol'].prototype.toString = Data['Symbol'].prototype.valueOf = function() {
+    return this.value;
+};
+
+/**
+ * Compare two instances of proton.Data.Symbol for equality.
+ * @method equals
+ * @memberof! proton.Data.Symbol#
+ * @param {proton.Data.Symbol} rhs the instance we wish to compare this instance with.
+ * @returns {boolean} true iff the two compared instances are equal.
+ */
+Data['Symbol'].prototype['equals'] = function(rhs) {
+    return this.toString() === rhs.toString();
+};
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-symbol.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-typed-number.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-typed-number.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-typed-number.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-typed-number.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.TypedNumber                       */
+/*                                                                           */
+/*****************************************************************************/
+
+// ---------------------- JavaScript Number Extensions ------------------------ 
+
+Number.prototype['ubyte'] = function() {
+    return new Data.TypedNumber('UBYTE', this);
+};
+
+Number.prototype['byte'] = function() {
+    return new Data.TypedNumber('BYTE', this);
+};
+
+Number.prototype['ushort'] = function() {
+    return new Data.TypedNumber('USHORT', this);
+};
+
+Number.prototype['short'] = function() {
+    return new Data.TypedNumber('SHORT', this);
+};
+
+Number.prototype['uint'] = function() {
+    return new Data.TypedNumber('UINT', this);
+};
+
+Number.prototype['int'] = function() {
+    return new Data.TypedNumber('INT', this);
+};
+
+Number.prototype['ulong'] = function() {
+    return new Data.TypedNumber('ULONG', this);
+};
+
+Number.prototype['long'] = function() {
+    return new Data.TypedNumber('LONG', this);
+};
+
+Number.prototype['float'] = function() {
+    return new Data.TypedNumber('FLOAT', this);
+};
+
+Number.prototype['double'] = function() {
+    return new Data.TypedNumber('DOUBLE', this);
+};
+
+Number.prototype['char'] = function() {
+    return new Data.TypedNumber('CHAR', this);
+};
+
+String.prototype['char'] = function() {
+    return new Data.TypedNumber('CHAR', this.charCodeAt(0));
+};
+
+// ------------------------- proton.Data.TypedNumber -------------------------- 
+/**
+ * Create a proton.Data.TypedNumber.
+ * @classdesc
+ * This class is a simple wrapper class that allows a "type" to be recorded for
+ * a number. The idea is that the JavaScript Number class is extended with extra
+ * methods to allow numbers to be "modified" to TypedNumbers, so for example
+ * 1.0.float() would modify 1.0 by returning a TypedNumber with type = FLOAT
+ * and value = 1. The strings used for type correspond to the names of the Data
+ * put* methods e.g. UBYTE, BYTE, USHORT, SHORT, UINT, INT, ULONG, LONG, FLOAT,
+ * DOUBLE, CHAR so that the correct method to call can be derived from the type.
+ * @constructor proton.Data.TypedNumber
+ * @param {(string|number)} type the type of the Number either as a string or number.
+ *        Stored internally as a string corresponding to one of the TypeNames.
+ * @param {number} value the value of the Number.
+ */
+// Use dot notation as it is a "protected" inner class not exported from the closure.
+Data.TypedNumber = function(type, value) { // Data.TypedNumber Constructor.
+    this.type  = (typeof type === 'number') ? Data['TypeNames'][type] : type;
+    this.value = value;
+};
+
+/**
+ * @method toString
+ * @memberof! proton.Data.TypedNumber#
+ * @returns {string} the String form of a {@link proton.Data.TypedNumber}.
+ */
+Data.TypedNumber.prototype.toString = Data.TypedNumber.prototype.valueOf = function() {
+    return +this.value;
+};
+
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-typed-number.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-uuid.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-uuid.js?rev=1624873&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-uuid.js (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-uuid.js Sun Sep 14 16:57:09 2014
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*****************************************************************************/
+/*                                                                           */
+/*                             proton.Data.Uuid                              */
+/*                                                                           */
+/*****************************************************************************/
+
+/**
+ * Create a proton.Data.Uuid which is a type 4 UUID.
+ * @classdesc
+ * This class represents a type 4 UUID, wich may use crypto libraries to generate
+ * the UUID if supported by the platform (e.g. node.js or a modern browser)
+ * @constructor proton.Data.Uuid
+ * @param {number|Array|string} u a UUID. If null a type 4 UUID is generated wich may use crypto if
+ *        supported by the platform. If u is an emscripten "pointer" we copy the
+ *        data from that. If u is a JavaScript Array we use it as-is. If u is a
+ *        String then we try to parse that as a UUID.
+ * @property {Array} uuid is the compact array form of the UUID.
+ */
+Data['Uuid'] = function(u) { // Data.Uuid Constructor.
+    // Helper to copy from emscriptem allocated storage into JavaScript Array.
+    function _p2a(p) {
+        var uuid = new Array(16);
+        for (var i = 0; i < 16; i++) {
+            uuid[i] = getValue(p + i, 'i8') & 0xFF; // & 0xFF converts to unsigned.
+        }
+        return uuid;
+    };
+
+    if (!u) { // Generate UUID using emscriptem's uuid_generate implementation.
+        var sp = Runtime.stackSave();
+        var p = allocate(16, 'i8', ALLOC_STACK); // Create temporary pointer storage.
+        _uuid_generate(p);      // Generate UUID into allocated pointer.
+        this['uuid'] = _p2a(p); // Copy from allocated storage into JavaScript Array.
+        Runtime.stackRestore(sp);
+    } else if (Data.isNumber(u)) { // Use pointer that has been passed in.
+        this['uuid'] = _p2a(u);    // Copy from allocated storage into JavaScript Array.
+    } else if (Data.isArray(u)) { // Use array that has been passed in.
+        this['uuid'] = u; // Just use the JavaScript Array.
+    } else if (Data.isString(u)) { // Parse String form UUID.
+        if (u.length === 36) {
+            var i = 0;
+            var uuid = new Array(16);
+            u.toLowerCase().replace(/[0-9a-f]{2}/g, function(byte) {
+                if (i < 16) {
+                    uuid[i++] = parseInt(byte, 16);
+                }
+            });
+            this['uuid'] = uuid;
+        }
+    }
+    this.string = null;
+};
+
+/**
+ * Returns the string representation of the proton.Data.Uuid.
+ * @method toString
+ * @memberof! proton.Data.Uuid#
+ * @returns {string} the String
+ *          /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/
+ *          form of a {@link proton.Data.Uuid}.
+ */
+Data['Uuid'].prototype.toString = Data['Uuid'].prototype.valueOf = function() {
+    if (!this.string) { // Check if we've cached the string version.
+        var i = 0;
+        var uu = this['uuid'];
+        var uuid = 'xxxx-xx-xx-xx-xxxxxx'.replace(/[x]/g, function(c) {
+            var r = uu[i].toString(16);
+            r = (r.length === 1) ? '0' + r : r; // Zero pad single digit hex values
+            i++;
+            return r;
+        });
+        this.string = uuid;
+    }
+    return this.string;
+};
+
+/**
+ * Compare two instances of proton.Data.Uuid for equality.
+ * @method equals
+ * @memberof! proton.Data.Uuid#
+ * @param {proton.Data.Uuid} rhs the instance we wish to compare this instance with.
+ * @returns {boolean} true iff the two compared instances are equal.
+ */
+Data['Uuid'].prototype['equals'] = function(rhs) {
+    return this.toString() === rhs.toString();
+};
+

Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/data-uuid.js
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message