diff --git a/dist/hprose.js b/dist/hprose.js index 1c0fe53..a29307a 100644 --- a/dist/hprose.js +++ b/dist/hprose.js @@ -4,4 +4,4 @@ // For all details and documentation: // https://github.com/hprose/hprose-wx -var hprose=Object.create(null);function TimeoutError(e){Error.call(this),this.message=e,this.name=TimeoutError.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,TimeoutError)}!function(e){"use strict";function o(t){if("function"!=typeof t)throw new TypeError(t+" is not a function");return function(e){return t.apply(e,Array.prototype.slice.call(arguments,1))}}function t(e,t){for(var r=e.prototype,n=0,i=t.length;n>15,i=new Array(r?n+1:n),a=0;a>>24&255,e[t++]=r>>>16&255,e[t++]=r>>>8&255,e[t++]=255&r,t}function n(e,t,r){return e[t++]=255&r,e[t++]=r>>>8&255,e[t++]=r>>>16&255,e[t++]=r>>>24&255,t}function i(e,t){return(t===o||null===t||t<0)&&(t=e.length),0===t?["",0]:t<65535?function(e,t){for(var r=new Array(t),n=0,i=0,a=e.length;n>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:r[n]=u;break;case 12:case 13:if(i>10&1023|55296,r[n]=1023&o|56320;break}throw new Error("Character outside valid Unicode range: 0x"+o.toString(16))}throw new Error("Unfinished UTF-8 octet sequence");default:throw new Error("Bad UTF-8 encoding 0x"+u.toString(16))}}return n>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:n[i]=o;break;case 12:case 13:if(a>10&1023|55296,n[i]=1023&s|56320;break}throw new Error("Character outside valid Unicode range: 0x"+s.toString(16))}throw new Error("Unfinished UTF-8 octet sequence");default:throw new Error("Bad UTF-8 encoding 0x"+o.toString(16))}if(32766<=i){var c=i+1;n.length=c,r.push(String.fromCharCode.apply(String,n)),t-=c,i=-1}}return 0>1,t|=t>>2,t|=t>>4,t|=t>>8,1+(t|=t>>16));if(r){if((i*=2)>r.length){var a=new Uint8Array(i);a.set(r),this._bytes=a}}else i=Math.max(i,1024),this._bytes=new Uint8Array(i)}},length:{get:function(){return this._length}},capacity:{get:function(){return this._bytes?this._bytes.length:0}},position:{get:function(){return this._off}},bytes:{get:function(){return null===this._bytes?s:this._bytes.subarray(0,this._length)}},buffer:{get:function(){if(null===this._bytes)return s.buffer;if(this._bytes.buffer.slice)return this._bytes.buffer.slice(0,this._length);var e=new Uint8Array(this._length);return e.set(this._bytes.subarray(0,this._length)),e.buffer}},mark:{value:function(){this._wmark=this._length,this._rmark=this._off}},reset:{value:function(){this._length=this._wmark,this._off=this._rmark}},clear:{value:function(){this._bytes=null,this._length=0,this._wmark=0,this._off=0,this._rmark=0}},writeByte:{value:function(e){this._grow(1),this._bytes[this._length++]=e}},writeInt32BE:{value:function(e){if(e===(0|e)&&e<=2147483647)return this._grow(4),void(this._length=r(this._bytes,this._length,e));throw new TypeError("value is out of bounds")}},writeUInt32BE:{value:function(e){if(2147483648+(2147483647&e)===e&&0<=e)return this._grow(4),void(this._length=r(this._bytes,this._length,0|e));throw new TypeError("value is out of bounds")}},writeInt32LE:{value:function(e){if(e===(0|e)&&e<=2147483647)return this._grow(4),void(this._length=n(this._bytes,this._length,e));throw new TypeError("value is out of bounds")}},writeUInt32LE:{value:function(e){if(2147483648+(2147483647&e)===e&&0<=e)return this._grow(4),void(this._length=n(this._bytes,this._length,0|e));throw new TypeError("value is out of bounds")}},write:{value:function(e){var t=e.byteLength||e.length;if(0!==t){this._grow(t);var r=this._bytes,n=this._length;switch(e.constructor){case ArrayBuffer:r.set(new Uint8Array(e),n);break;case Uint8Array:r.set(e,n);break;case a:r.set(e.bytes,n);break;default:for(var i=0;i>6,e[t++]=128|63&a;else{if(!(a<55296||57343>18,e[t++]=128|o>>12&63,e[t++]=128|o>>6&63,e[t++]=128|63&o,++i;continue}}throw new Error("Malformed string")}e[t++]=224|a>>12,e[t++]=128|a>>6&63,e[t++]=128|63&a}}return t}(this._bytes,this._length,e))}},readByte:{value:function(){return this._offthis._length&&(e=this._length-this._off),0===e?s:this._bytes.subarray(this._off,this._off+=e)}},skip:{value:function(e){return this._off+e>this._length?(e=this._length-this._off,this._off=this._length):this._off+=e,e}},readBytes:{value:function(e){var t,r=Array.indexOf(this._bytes,e,this._off);return-1===r?(t=this._bytes.subarray(this._off,this._length),this._off=this._length):(t=this._bytes.subarray(this._off,r+1),this._off=r+1),t}},readUntil:{value:function(e){var t=Array.indexOf(this._bytes,e,this._off),r="";return t===this._off?this._off++:-1===t?(r=i(this._bytes.subarray(this._off,this._length))[0],this._off=this._length):(r=i(this._bytes.subarray(this._off,t))[0],this._off=t+1),r}},readAsciiString:{value:function(e){return this._off+e>this._length&&(e=this._length-this._off),0===e?"":t(this._bytes.subarray(this._off,this._off+=e))}},readStringAsBytes:{value:function(e){var t=function(e,t){if(t===o&&(t=e.length),0===t)return[s,0];for(var r=0,n=0,i=e.length;r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:break;case 12:case 13:if(n=ce.Raw&&(a=new fe),i===se.TagResult){if(o===ce.Serialized?a=n.readRaw():o>=ce.Raw?(a.writeByte(se.TagResult),a.write(n.readRaw())):(n.useHarmonyMap=f[t].context.useHarmonyMap,n.reset(),a=n.unserialize()),(i=r.readByte())===se.TagArgument){if(o>=ce.Raw)a.writeByte(se.TagArgument),a.write(n.readRaw());else n.reset(),D(n.readList(),f[t].args);i=r.readByte()}}else i===se.TagError&&(o>=ce.Raw?(a.writeByte(se.TagError),a.write(n.readRaw())):(n.reset(),u=new Error(n.readString())),i=r.readByte());if([se.TagEnd,se.TagResult,se.TagError].indexOf(i)<0)return void c(new Error("Wrong Response:\r\n"+fe.toString(e)));o>=ce.Raw?(o===ce.RawWithEndTag&&a.writeByte(se.TagEnd),f[t].result=a.bytes):f[t].result=a,f[t].error=u}}catch(e){return void c(e)}s(f)}},c)})}function K(r){if(r=r||{},b=!1,c)return ge.promise(function(e,t){f.push({batch:!0,settings:r,resolve:e,reject:t})});if(0===m.length)return ge.value([]);var n=function(e){var t={timeout:v,retry:y,retried:0,idempotent:p,failswitch:w,oneway:!1,sync:!1,client:x,userdata:{}};for(var r in e)r in t&&(t[r]=e[r]);return t}(r);n.sync&&(c=!0);var i=m;m=[];var e=ge.promise(function(t,e){j(i,n).then(function(e){e.forEach(function(t){if(t.error)G(t.name,t.error,t.context,t.reject);else try{if(t.context.onsuccess)try{t.context.onsuccess(t.result,t.args)}catch(e){t.context.onerror&&t.context.onerror(t.name,e),t.reject(e)}t.resolve(t.result)}catch(e){t.reject(e)}delete t.context,delete t.resolve,delete t.reject}),t(e)},function(t){i.forEach(function(e){"reject"in e&&G(e.name,t,e.context,e.reject)}),e(t)})});return e.whenComplete(Y(n.sync)),e}function V(e){if(typeof e===de)a=[e];else{if(!Array.isArray(e))return;(a=e.slice(0)).sort(function(){return Math.random()-.5})}i=a[u=0]}function X(e){e&&"function"==typeof e.inputFilter&&"function"==typeof e.outputFilter&&T.push(e)}function Z(e,t,r){r===ue&&(typeof t===we&&(r=t,t=!1),t||(typeof e===we?(r=e,e=!1):(e&&e.constructor===Object||Array.isArray(e))&&(t=e,e=!1)));var n=x;return r&&(n={}),e||i?(e&&(i=e),(typeof t===de||t&&t.constructor===Object)&&(t=[t]),Array.isArray(t)?("undefined"==typeof Proxy?L(n,t):n=new Proxy({},new _e(N)),_.resolve(n),n):(oe(P,n),_)):new Error("You should set server uri first!")}function ee(e,t){if(B[e]){var r=B[e];if(r[t])return r[t]}return null}function te(e,t,r){if(e)if(typeof r===be){var n=e[t];if(n){var i=n.callbacks,a=i.indexOf(r);0<=a&&(i[a]=i[i.length-1],i.length--),0===i.length&&delete e[t]}}else delete e[t]}function re(){return null===S&&(S=q(x,"#",[],!1)),S}re.sync=!0,re.idempotent=!0,re.failswitch=!0;var ne=Object.create(null,{begin:{value:function(){b=!0}},end:{value:K},use:{value:function(e){var t;return t=e,k.push(t),j=k.reduceRight(function(r,n){return function(e,t){return ge.toPromise(n(e,t,r))}},$),ne}}}),ie=Object.create(null,{use:{value:function(e){var t;return t=e,R.push(t),E=R.reduceRight(function(r,n){return function(e,t){return ge.toPromise(n(e,t,r))}},I),ie}}}),ae=Object.create(null,{use:{value:function(e){var t;return t=e,U.push(t),A=U.reduceRight(function(r,n){return function(e,t){return ge.toPromise(n(e,t,r))}},M),ae}}});Object.defineProperties(this,{"#":{value:re},onerror:{get:function(){return s},set:function(e){typeof e===be&&(s=e)}},onfailswitch:{get:function(){return l},set:function(e){typeof e===be&&(l=e)}},uri:{get:function(){return i}},uriList:{get:function(){return a},set:V},id:{get:function(){return S}},failswitch:{get:function(){return w},set:function(e){w=!!e}},failround:{get:function(){return o}},timeout:{get:function(){return v},set:function(e){v="number"==typeof e?0|e:0}},retry:{get:function(){return y},set:function(e){y="number"==typeof e?0|e:0}},idempotent:{get:function(){return p},set:function(e){p=!!e}},keepAlive:{get:function(){return n},set:function(e){n=!!e}},byref:{get:function(){return h},set:function(e){h=!!e}},simple:{get:function(){return g},set:function(e){g=!!e}},useHarmonyMap:{get:function(){return d},set:function(e){d=!!e}},filter:{get:function(){return 0===T.length?null:1===T.length?T[0]:T.slice()},set:function(e){T.length=0,Array.isArray(e)?e.forEach(function(e){X(e)}):X(e)}},addFilter:{value:X},removeFilter:{value:function(e){var t=T.indexOf(e);return-1!==t&&(T.splice(t,1),!0)}},filters:{get:function(){return T}},useService:{value:Z},invoke:{value:function(e,t,r){var n=arguments.length;if(n<1||typeof e!==de)throw new Error("name must be a string");if(1===n&&(t=[]),2===n&&!Array.isArray(t)){var i=[];typeof t!==be&&i.push(pe),i.push(t),t=i}if(2>15,i=new Array(r?n+1:n),a=0;a>>24&255,e[t++]=r>>>16&255,e[t++]=r>>>8&255,e[t++]=255&r,t}function n(e,t,r){return e[t++]=255&r,e[t++]=r>>>8&255,e[t++]=r>>>16&255,e[t++]=r>>>24&255,t}function i(e,t){return(t===o||null===t||t<0)&&(t=e.length),0===t?["",0]:t<65535?function(e,t){for(var r=new Array(t),n=0,i=0,a=e.length;n>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:r[n]=u;break;case 12:case 13:if(i>10&1023|55296,r[n]=1023&o|56320;break}throw new Error("Character outside valid Unicode range: 0x"+o.toString(16))}throw new Error("Unfinished UTF-8 octet sequence");default:throw new Error("Bad UTF-8 encoding 0x"+u.toString(16))}}return n>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:n[i]=o;break;case 12:case 13:if(a>10&1023|55296,n[i]=1023&s|56320;break}throw new Error("Character outside valid Unicode range: 0x"+s.toString(16))}throw new Error("Unfinished UTF-8 octet sequence");default:throw new Error("Bad UTF-8 encoding 0x"+o.toString(16))}if(32766<=i){var c=i+1;n.length=c,r.push(String.fromCharCode.apply(String,n)),t-=c,i=-1}}return 0>1,t|=t>>2,t|=t>>4,t|=t>>8,1+(t|=t>>16));if(r){if((i*=2)>r.length){var a=new Uint8Array(i);a.set(r),this._bytes=a}}else i=Math.max(i,1024),this._bytes=new Uint8Array(i)}},length:{get:function(){return this._length}},capacity:{get:function(){return this._bytes?this._bytes.length:0}},position:{get:function(){return this._off}},bytes:{get:function(){return null===this._bytes?s:this._bytes.subarray(0,this._length)}},buffer:{get:function(){if(null===this._bytes)return s.buffer;if(this._bytes.buffer.slice)return this._bytes.buffer.slice(0,this._length);var e=new Uint8Array(this._length);return e.set(this._bytes.subarray(0,this._length)),e.buffer}},mark:{value:function(){this._wmark=this._length,this._rmark=this._off}},reset:{value:function(){this._length=this._wmark,this._off=this._rmark}},clear:{value:function(){this._bytes=null,this._length=0,this._wmark=0,this._off=0,this._rmark=0}},writeByte:{value:function(e){this._grow(1),this._bytes[this._length++]=e}},writeInt32BE:{value:function(e){if(e===(0|e)&&e<=2147483647)return this._grow(4),void(this._length=r(this._bytes,this._length,e));throw new TypeError("value is out of bounds")}},writeUInt32BE:{value:function(e){if(2147483648+(2147483647&e)===e&&0<=e)return this._grow(4),void(this._length=r(this._bytes,this._length,0|e));throw new TypeError("value is out of bounds")}},writeInt32LE:{value:function(e){if(e===(0|e)&&e<=2147483647)return this._grow(4),void(this._length=n(this._bytes,this._length,e));throw new TypeError("value is out of bounds")}},writeUInt32LE:{value:function(e){if(2147483648+(2147483647&e)===e&&0<=e)return this._grow(4),void(this._length=n(this._bytes,this._length,0|e));throw new TypeError("value is out of bounds")}},write:{value:function(e){var t=e.byteLength||e.length;if(0!==t){this._grow(t);var r=this._bytes,n=this._length;switch(e.constructor){case ArrayBuffer:r.set(new Uint8Array(e),n);break;case Uint8Array:r.set(e,n);break;case a:r.set(e.bytes,n);break;default:for(var i=0;i>6,e[t++]=128|63&a;else{if(!(a<55296||57343>18,e[t++]=128|o>>12&63,e[t++]=128|o>>6&63,e[t++]=128|63&o,++i;continue}}throw new Error("Malformed string")}e[t++]=224|a>>12,e[t++]=128|a>>6&63,e[t++]=128|63&a}}return t}(this._bytes,this._length,e))}},readByte:{value:function(){return this._offthis._length&&(e=this._length-this._off),0===e?s:this._bytes.subarray(this._off,this._off+=e)}},skip:{value:function(e){return this._off+e>this._length?(e=this._length-this._off,this._off=this._length):this._off+=e,e}},readBytes:{value:function(e){var t,r=Array.indexOf(this._bytes,e,this._off);return-1===r?(t=this._bytes.subarray(this._off,this._length),this._off=this._length):(t=this._bytes.subarray(this._off,r+1),this._off=r+1),t}},readUntil:{value:function(e){var t=Array.indexOf(this._bytes,e,this._off),r="";return t===this._off?this._off++:-1===t?(r=i(this._bytes.subarray(this._off,this._length))[0],this._off=this._length):(r=i(this._bytes.subarray(this._off,t))[0],this._off=t+1),r}},readAsciiString:{value:function(e){return this._off+e>this._length&&(e=this._length-this._off),0===e?"":t(this._bytes.subarray(this._off,this._off+=e))}},readStringAsBytes:{value:function(e){var t=function(e,t){if(t===o&&(t=e.length),0===t)return[s,0];for(var r=0,n=0,i=e.length;r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:break;case 12:case 13:if(n=ce.Raw&&(a=new fe),i===se.TagResult){if(o===ce.Serialized?a=n.readRaw():o>=ce.Raw?(a.writeByte(se.TagResult),a.write(n.readRaw())):(n.useHarmonyMap=f[t].context.useHarmonyMap,n.reset(),a=n.unserialize()),(i=r.readByte())===se.TagArgument){if(o>=ce.Raw)a.writeByte(se.TagArgument),a.write(n.readRaw());else n.reset(),D(n.readList(),f[t].args);i=r.readByte()}}else i===se.TagError&&(o>=ce.Raw?(a.writeByte(se.TagError),a.write(n.readRaw())):(n.reset(),u=new Error(n.readString())),i=r.readByte());if([se.TagEnd,se.TagResult,se.TagError].indexOf(i)<0)return void c(new Error("Wrong Response:\r\n"+fe.toString(e)));o>=ce.Raw?(o===ce.RawWithEndTag&&a.writeByte(se.TagEnd),f[t].result=a.bytes):f[t].result=a,f[t].error=u}}catch(e){return void c(e)}s(f)}},c)})}function K(r){if(r=r||{},b=!1,c)return ge.promise(function(e,t){f.push({batch:!0,settings:r,resolve:e,reject:t})});if(0===m.length)return ge.value([]);var n=function(e){var t={timeout:v,retry:y,retried:0,idempotent:p,failswitch:w,oneway:!1,sync:!1,client:x,userdata:{}};for(var r in e)r in t&&(t[r]=e[r]);return t}(r);n.sync&&(c=!0);var i=m;m=[];var e=ge.promise(function(t,e){j(i,n).then(function(e){e.forEach(function(t){if(t.error)G(t.name,t.error,t.context,t.reject);else try{if(t.context.onsuccess)try{t.context.onsuccess(t.result,t.args)}catch(e){t.context.onerror&&t.context.onerror(t.name,e),t.reject(e)}t.resolve(t.result)}catch(e){t.reject(e)}delete t.context,delete t.resolve,delete t.reject}),t(e)},function(t){i.forEach(function(e){"reject"in e&&G(e.name,t,e.context,e.reject)}),e(t)})});return e.whenComplete(Y(n.sync)),e}function V(e){if(typeof e===de)a=[e];else{if(!Array.isArray(e))return;(a=e.slice(0)).sort(function(){return Math.random()-.5})}i=a[u=0]}function X(e){e&&"function"==typeof e.inputFilter&&"function"==typeof e.outputFilter&&T.push(e)}function Z(e,t,r){r===ue&&(typeof t===we&&(r=t,t=!1),t||(typeof e===we?(r=e,e=!1):(e&&e.constructor===Object||Array.isArray(e))&&(t=e,e=!1)));var n=x;if(r&&(n={}),!e&&!i)return new Error("You should set server uri first!");if(e&&(i=e),(typeof t===de||t&&t.constructor===Object)&&(t=[t]),Array.isArray(t))L(n,t);else{if("undefined"==typeof Proxy)return oe(P,n),_;n=new Proxy({},new _e(N))}return _.resolve(n),n}function ee(e,t){if(B[e]){var r=B[e];if(r[t])return r[t]}return null}function te(e,t,r){if(e)if(typeof r===be){var n=e[t];if(n){var i=n.callbacks,a=i.indexOf(r);0<=a&&(i[a]=i[i.length-1],i.length--),0===i.length&&delete e[t]}}else delete e[t]}function re(){return null===S&&(S=q(x,"#",[],!1)),S}re.sync=!0,re.idempotent=!0,re.failswitch=!0;var ne=Object.create(null,{begin:{value:function(){b=!0}},end:{value:K},use:{value:function(e){var t;return t=e,k.push(t),j=k.reduceRight(function(r,n){return function(e,t){return ge.toPromise(n(e,t,r))}},$),ne}}}),ie=Object.create(null,{use:{value:function(e){var t;return t=e,R.push(t),E=R.reduceRight(function(r,n){return function(e,t){return ge.toPromise(n(e,t,r))}},I),ie}}}),ae=Object.create(null,{use:{value:function(e){var t;return t=e,U.push(t),A=U.reduceRight(function(r,n){return function(e,t){return ge.toPromise(n(e,t,r))}},M),ae}}});Object.defineProperties(this,{"#":{value:re},onerror:{get:function(){return s},set:function(e){typeof e===be&&(s=e)}},onfailswitch:{get:function(){return l},set:function(e){typeof e===be&&(l=e)}},uri:{get:function(){return i}},uriList:{get:function(){return a},set:V},id:{get:function(){return S}},failswitch:{get:function(){return w},set:function(e){w=!!e}},failround:{get:function(){return o}},timeout:{get:function(){return v},set:function(e){v="number"==typeof e?0|e:0}},retry:{get:function(){return y},set:function(e){y="number"==typeof e?0|e:0}},idempotent:{get:function(){return p},set:function(e){p=!!e}},keepAlive:{get:function(){return n},set:function(e){n=!!e}},byref:{get:function(){return h},set:function(e){h=!!e}},simple:{get:function(){return g},set:function(e){g=!!e}},useHarmonyMap:{get:function(){return d},set:function(e){d=!!e}},filter:{get:function(){return 0===T.length?null:1===T.length?T[0]:T.slice()},set:function(e){T.length=0,Array.isArray(e)?e.forEach(function(e){X(e)}):X(e)}},addFilter:{value:X},removeFilter:{value:function(e){var t=T.indexOf(e);return-1!==t&&(T.splice(t,1),!0)}},filters:{get:function(){return T}},useService:{value:Z},invoke:{value:function(e,t,r){var n=arguments.length;if(n<1||typeof e!==de)throw new Error("name must be a string");if(1===n&&(t=[]),2===n&&!Array.isArray(t)){var i=[];typeof t!==be&&i.push(pe),i.push(t),t=i}if(2