From 08f09a1e6aa7adabdbf45cf8d3d6af6a8565703a Mon Sep 17 00:00:00 2001 From: Ravin Perera <33562092+ravinsp@users.noreply.github.com> Date: Mon, 21 Dec 2020 11:56:04 +0530 Subject: [PATCH] Minor library improvements. (#198) --- examples/c_contract/hotpocket_contract.h | 2 +- .../{browser-test.html => browser-example.html} | 0 examples/js_client/hp-client-lib.js | 16 ++++++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) rename examples/js_client/{browser-test.html => browser-example.html} (100%) diff --git a/examples/c_contract/hotpocket_contract.h b/examples/c_contract/hotpocket_contract.h index 02715770..80c58477 100644 --- a/examples/c_contract/hotpocket_contract.h +++ b/examples/c_contract/hotpocket_contract.h @@ -12,7 +12,7 @@ #include "json.h" #define __HP_MMAP_BLOCK_SIZE 4096 -#define __HP_MMAP_BLOCK_ALIGN(x) (((x) + ((typeof(x))(__HP_MMAP_BLOCK_SIZE)-1)) & ~((typeof(x))(__HP_MMAP_BLOCK_SIZE)-1)) +#define __HP_MMAP_BLOCK_ALIGN(x) (((x) + ((off_t)(__HP_MMAP_BLOCK_SIZE)-1)) & ~((off_t)(__HP_MMAP_BLOCK_SIZE)-1)) #define __HP_STREAM_MSG_HEADER_SIZE 4 #define __HP_SEQPKT_MAX_SIZE 131072 // 128KB to support SEQ_PACKET sockets. #define HP_PEER_MSG_MAX_SIZE __HP_SEQPKT_MAX_SIZE diff --git a/examples/js_client/browser-test.html b/examples/js_client/browser-example.html similarity index 100% rename from examples/js_client/browser-test.html rename to examples/js_client/browser-example.html diff --git a/examples/js_client/hp-client-lib.js b/examples/js_client/hp-client-lib.js index c22fee1d..51ef0089 100644 --- a/examples/js_client/hp-client-lib.js +++ b/examples/js_client/hp-client-lib.js @@ -674,9 +674,10 @@ // Set sodium reference. async function initSodium() { - if (sodium) // If already set, do nothing. + if (sodium) { // If already set, do nothing. return; - else if (isBrowser && window.sodium) { // If no parameter specified, try to get from window.sodium. + } + else if (isBrowser && window.sodium) { // browser (if sodium already loaded) sodium = window.sodium; } else if (isBrowser && !window.sodium) { // If sodium not yet loaded in browser, wait for sodium ready. @@ -693,26 +694,33 @@ sodium = require('libsodium-wrappers'); await sodium.ready; } + else { + throw "Sodium reference not found. Please include sodium js lib in browser scripts."; + } } // Set bson reference. function initBson() { if (bson) // If already set, do nothing. return; - else if (isBrowser && window.BSON) // If no parameter specified, try to get from window.BSON. + else if (isBrowser && window.BSON) // browser bson = window.BSON; else if (!isBrowser) // nodejs bson = require('bson'); + else + throw "BSON reference not found."; } // Set WebSocket reference. function initWebSocket() { if (WebSocket) // If already set, do nothing. return; - else if (isBrowser && window.WebSocket) // If no parameter specified, try to get from window.WebSocket. + else if (isBrowser && window.WebSocket) // browser WebSocket = window.WebSocket; else if (!isBrowser) // nodejs WebSocket = require('ws'); + else + throw "WebSocket reference not found."; } const hotPocketLib = {