From 103014db72d4fb6448c52052addc2b1a6c1332d4 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Tue, 6 Feb 2024 00:24:11 +1300 Subject: [PATCH] Update version and set lower bound on base --- ghcjs-base.cabal | 39 +- jsbits-old/animationFrame.js | 18 - jsbits-old/array.js | 40 -- jsbits-old/export.js | 26 - jsbits-old/foreign.js | 8 - jsbits-old/json.js | 4 - jsbits-old/jsstring.js | 1181 ---------------------------------- jsbits-old/jsstringRaw.js | 21 - jsbits-old/object.js | 2 - jsbits-old/text.js | 53 -- jsbits-old/utils.js | 93 --- jsbits-old/websocket.js | 58 -- jsbits-old/xhr.js | 16 - 13 files changed, 13 insertions(+), 1546 deletions(-) delete mode 100644 jsbits-old/animationFrame.js delete mode 100644 jsbits-old/array.js delete mode 100644 jsbits-old/export.js delete mode 100644 jsbits-old/foreign.js delete mode 100644 jsbits-old/json.js delete mode 100644 jsbits-old/jsstring.js delete mode 100644 jsbits-old/jsstringRaw.js delete mode 100644 jsbits-old/object.js delete mode 100644 jsbits-old/text.js delete mode 100644 jsbits-old/utils.js delete mode 100644 jsbits-old/websocket.js delete mode 100644 jsbits-old/xhr.js diff --git a/ghcjs-base.cabal b/ghcjs-base.cabal index c6da100..165e15c 100644 --- a/ghcjs-base.cabal +++ b/ghcjs-base.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: ghcjs-base -version: 0.2.1.0 +version: 1.0.0.0 synopsis: base library for GHCJS homepage: http://github.com/ghcjs/ghcjs-base license: MIT @@ -15,33 +15,20 @@ source-repository head location: https://github.com/ghcjs/ghcjs-base library - if impl(ghc >= 8.10.1) - js-sources: jsbits/array.js - jsbits/animationFrame.js - jsbits/buffer.js - jsbits/export.js - jsbits/jsstring.js - jsbits/jsstringRaw.js - jsbits/foreign.js - jsbits/text.js - jsbits/utils.js - jsbits/xhr.js - jsbits/websocket.js - else - js-sources: jsbits-old/array.js - jsbits-old/animationFrame.js - jsbits-old/export.js - jsbits-old/jsstring.js - jsbits-old/jsstringRaw.js - jsbits-old/foreign.js - jsbits-old/text.js - jsbits-old/utils.js - jsbits-old/xhr.js - jsbits-old/websocket.js + js-sources: jsbits/array.js + jsbits/animationFrame.js + jsbits/buffer.js + jsbits/export.js + jsbits/jsstring.js + jsbits/jsstringRaw.js + jsbits/foreign.js + jsbits/text.js + jsbits/utils.js + jsbits/xhr.js + jsbits/websocket.js other-extensions: DeriveDataTypeable DeriveGeneric ForeignFunctionInterface --- JavaScriptFFI GHCForeignImportPrim MagicHash UnboxedTuples @@ -139,7 +126,7 @@ library JavaScript.TypedArray.Internal.Types JavaScript.TypedArray.ArrayBuffer.Internal JavaScript.TypedArray.DataView.Internal - build-depends: base >= 4.7 && < 5, + build-depends: base >= 4.18 && < 5, ghc-prim, binary >= 0.8 && < 0.11, bytestring >= 0.10 && < 0.13, diff --git a/jsbits-old/animationFrame.js b/jsbits-old/animationFrame.js deleted file mode 100644 index 7a3e942..0000000 --- a/jsbits-old/animationFrame.js +++ /dev/null @@ -1,18 +0,0 @@ -function h$animationFrameCancel(h) { - if(h.handle) window.cancelAnimationFrame(h.handle); - if(h.callback) { - h$release(h.callback) - h.callback = null; - } -} - -function h$animationFrameRequest(h) { - h.handle = window.requestAnimationFrame(function(ts) { - var cb = h.callback; - if(cb) { - h$release(cb); - h.callback = null; - cb(ts); - } - }); -} diff --git a/jsbits-old/array.js b/jsbits-old/array.js deleted file mode 100644 index 8230cdf..0000000 --- a/jsbits-old/array.js +++ /dev/null @@ -1,40 +0,0 @@ -#include - -/* - convert an array to a Haskell list, wrapping each element in a - JSVal constructor - */ -function h$fromArray(a) { - var r = HS_NIL; - for(var i=a.length-1;i>=0;i--) r = MK_CONS(MK_JSVAL(a[i]), r); - return a; -} - -/* - convert an array to a Haskell list. No additional wrapping of the - elements is performed. Only use this when the elements are directly - usable as Haskell heap objects (numbers, boolean) or when the - array elements have already been appropriately wrapped - */ -function h$fromArrayNoWrap(a) { - var r = HS_NIL; - for(var i=a.length-1;i>=0;i--) r = MK_CONS(a[i], r); - return a; -} - -/* - convert a list of JSVal to an array. the list must have been fully forced, - not just the spine. - */ -function h$listToArray(xs) { - var a = [], i = 0; - while(IS_CONS(xs)) { - a[i++] = JSVAL_VAL(CONS_HEAD(xs)); - xs = CONS_TAIL(xs); - } - return a; -} - -function h$listToArrayWrap(xs) { - return MK_JSVAL(h$listToArray(xs)); -} diff --git a/jsbits-old/export.js b/jsbits-old/export.js deleted file mode 100644 index cc3043a..0000000 --- a/jsbits-old/export.js +++ /dev/null @@ -1,26 +0,0 @@ -function h$exportValue(fp1a,fp1b,fp2a,fp2b,o) { - var e = { fp1a: fp1a - , fp1b: fp1b - , fp2a: fp2a - , fp2b: fp2b - , released: false - , root: o - , _key: -1 - }; - h$retain(e); - return e; -} - -function h$derefExport(fp1a,fp1b,fp2a,fp2b,e) { - if(!e || typeof e !== 'object') return null; - if(e.released) return null; - if(fp1a !== e.fp1a || fp1b !== e.fp1b || - fp2a !== e.fp2a || fp2b !== e.fp2b) return null; - return e.root; -} - -function h$releaseExport(e) { - h$release(e); - e.released = true; - e.root = null; -} diff --git a/jsbits-old/foreign.js b/jsbits-old/foreign.js deleted file mode 100644 index a4e4cf0..0000000 --- a/jsbits-old/foreign.js +++ /dev/null @@ -1,8 +0,0 @@ -function h$foreignListProps(o) { - var r = HS_NIL; - if(typeof o === 'undefined' || o === null) return null; - throw "h$foreignListProps"; -/* for(var p in o) { - - } */ -} diff --git a/jsbits-old/json.js b/jsbits-old/json.js deleted file mode 100644 index 15d2ee3..0000000 --- a/jsbits-old/json.js +++ /dev/null @@ -1,4 +0,0 @@ -#include - - - diff --git a/jsbits-old/jsstring.js b/jsbits-old/jsstring.js deleted file mode 100644 index e8a4ef9..0000000 --- a/jsbits-old/jsstring.js +++ /dev/null @@ -1,1181 +0,0 @@ -#include - -/* - * Support code for the Data.JSString module. This code presents a JSString - * as a sequence of code points and hides the underlying encoding ugliness of - * the JavaScript strings. - * - * Use Data.JSString.Raw for direct access to the JSThis makes the operations more expen - */ - -/* - * Some workarounds here for JS engines that do not support proper - * code point access - */ - -#ifdef GHCJS_TRACE_JSSTRING -#define TRACE_JSSTRING(args...) h$log("jsstring: ", args); -#else -#define TRACE_JSSTRING(args...) -#endif - -#define IS_ASTRAL(cp) ((cp)>=0x10000) -#define IS_HI_SURR(cp) ((cp|1023)===0xDBFF) -#define IS_LO_SURR(cp) ((cp|1023)===0xDFFF) -#define FROM_SURR(hi,lo) ((((hi)-0xD800)<<10)+(lo)-0xDC00+0x10000) -#define HI_SURR(cp) ((((cp)-0x10000)>>>10)+0xDC00) -#define LO_SURR(cp) (((cp)&0x3FF)+0xD800) - -var h$jsstringEmpty = MK_JSVAL(''); - -var h$jsstringHead, h$jsstringTail, h$jsstringCons, - h$jsstringSingleton, h$jsstringSnoc, h$jsstringUncons, - h$jsstringIndex, h$jsstringUncheckedIndex; - -var h$fromCodePoint; - -if(String.prototype.fromCodePoint) { - h$fromCodePoint = String.fromCodePoint; -} else { - // polyfill from https://github.com/mathiasbynens/String.fromCodePoint (MIT-license) - h$fromCodePoint = - (function() { - var stringFromCharCode = String.fromCharCode; - var floor = Math.floor; - return function(_) { - var MAX_SIZE = 0x4000; - var codeUnits = []; - var highSurrogate; - var lowSurrogate; - var index = -1; - var length = arguments.length; - if (!length) { - return ''; - } - var result = ''; - while (++index < length) { - var codePoint = Number(arguments[index]); - if ( - !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` - codePoint < 0 || // not a valid Unicode code point - codePoint > 0x10FFFF || // not a valid Unicode code point - floor(codePoint) != codePoint // not an integer - ) { - throw RangeError('Invalid code point: ' + codePoint); - } - if (codePoint <= 0xFFFF) { // BMP code point - codeUnits.push(codePoint); - } else { // Astral code point; split in surrogate halves - // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - codePoint -= 0x10000; - highSurrogate = (codePoint >> 10) + 0xD800; - lowSurrogate = (codePoint % 0x400) + 0xDC00; - codeUnits.push(highSurrogate, lowSurrogate); - } - if (index + 1 == length || codeUnits.length > MAX_SIZE) { - result += stringFromCharCode.apply(null, codeUnits); - codeUnits.length = 0; - } - } - return result; - } - })(); -} - -if(String.prototype.codePointAt) { - h$jsstringSingleton = function(ch) { - TRACE_JSSTRING("(codePointAt) singleton: " + ch); - return String.fromCodePoint(ch); - } - h$jsstringHead = function(str) { - TRACE_JSSTRING("(codePointAt) head: " + str); - var cp = str.codePointAt(0); - return (cp === undefined) ? -1 : (cp|0); - } - h$jsstringTail = function(str) { - TRACE_JSSTRING("(codePointAt) tail: " + str); - var l = str.length; - if(l===0) return null; - var ch = str.codePointAt(0); - if(ch === undefined) return null; - // string length is at least two if ch comes from a surrogate pair - return str.substr(IS_ASTRAL(ch)?2:1); - } - h$jsstringCons = function(ch, str) { - TRACE_JSSTRING("(codePointAt) cons: " + ch + " '" + str + "'"); - return String.fromCodePoint(ch)+str; - } - h$jsstringSnoc = function(str, ch) { - TRACE_JSSTRING("(codePointAt) snoc: '" + str + "' " + ch); - return str+String.fromCodePoint(ch); - } - h$jsstringUncons = function(str) { - TRACE_JSSTRING("(codePointAt) uncons: '" + str + "'"); - var l = str.length; - if(l===0) { - RETURN_UBX_TUP2(-1, null); - } - var ch = str.codePointAt(0); - if(ch === undefined) { - RETURN_UBX_TUP2(-1, null); - } - RETURN_UBX_TUP2(ch, str.substr(IS_ASTRAL(ch)?2:1)); - } - // index is the first part of the character - h$jsstringIndex = function(i, str) { - TRACE_JSSTRING("(codePointAt) index: " + i + " '" + str + "'"); - var ch = str.codePointAt(i); - if(ch === undefined) return -1; - return ch; - } - h$jsstringUncheckedIndex = function(i, str) { - TRACE_JSSTRING("(codePointAt) uncheckedIndex: " + i + " '" + str.length + "'"); - return str.codePointAt(i); - } -} else { - h$jsstringSingleton = function(ch) { - TRACE_JSSTRING("(no codePointAt) singleton: " + ch); - return (IS_ASTRAL(ch)) ? String.fromCharCode(HI_SURR(ch), LO_SURR(ch)) - : String.fromCharCode(ch); - } - h$jsstringHead = function(str) { - TRACE_JSSTRING("(no codePointAt) head: " + str); - var l = str.length; - if(l===0) return -1; - var ch = str.charCodeAt(0); - if(IS_HI_SURR(ch)) { - return (l>1) ? FROM_SURR(ch, str.charCodeAt(1)) : -1; - } else { - return ch; - } - } - h$jsstringTail = function(str) { - TRACE_JSSTRING("(no codePointAt) tail: " + str); - var l = str.length; - if(l===0) return null; - var ch = str.charCodeAt(0); - if(IS_HI_SURR(ch)) { - return (l>1)?str.substr(2):null; - } else return str.substr(1); - } - h$jsstringCons = function(ch, str) { - TRACE_JSSTRING("(no codePointAt) cons: " + ch + " '" + str + "'"); - return ((IS_ASTRAL(ch)) ? String.fromCharCode(HI_SURR(ch), LO_SURR(ch)) - : String.fromCharCode(ch)) - + str; - } - h$jsstringSnoc = function(str, ch) { - TRACE_JSSTRING("(no codePointAt) snoc: '" + str + "' " + ch); - return str + ((IS_ASTRAL(ch)) ? String.fromCharCode(HI_SURR(ch), LO_SURR(ch)) - : String.fromCharCode(ch)); - } - h$jsstringUncons = function(str) { - TRACE_JSSTRING("(no codePointAt) uncons: '" + str + "'"); - var l = str.length; - if(l===0) { - RETURN_UBX_TUP2(-1, null); - } - var ch = str.charCodeAt(0); - if(IS_HI_SURR(ch)) { - if(l > 1) { - RETURN_UBX_TUP2(FROM_SURR(ch, str.charCodeAt(1)), str.substr(2)); - } else { - RETURN_UBX_TUP2(-1, null); - } - } else { - RETURN_UBX_TUP2(ch, str.substr(1)); - } - } - // index is the first part of the character - h$jsstringIndex = function(i, str) { - // TRACE_JSSTRING("(no codePointAt) index: " + i + " '" + str + "'"); - var ch = str.charCodeAt(i); - if(ch != ch) return -1; // NaN test - return (IS_HI_SURR(ch)) ? FROM_SURR(ch, str.charCodeAt(i+1)) : ch; - } - h$jsstringUncheckedIndex = function(i, str) { - TRACE_JSSTRING("(no codePointAt) uncheckedIndex: " + i + " '" + str.length + "'"); - var ch = str.charCodeAt(i); - return (IS_HI_SURR(ch)) ? FROM_SURR(ch, str.charCodeAt(i+1)) : ch; - } -} - -function h$jsstringUnsnoc(str) { - TRACE_JSSTRING("unsnoc: '" + str + "'"); - var l = str.length; - if(l===0) { - RETURN_UBX_TUP2(-1, null); - } - var ch = str.charCodeAt(l-1); - if(IS_LO_SURR(ch)) { - if(l !== 1) { - RETURN_UBX_TUP2(FROM_SURR(str.charCodeAt(l-2),ch), str.substr(0,l-2)); - } else { - RETURN_UBX_TUP2(-1, null); - } - } else { - RETURN_UBX_TUP2(ch, str.substr(0,l-1)); - } -} - - -function h$jsstringPack(xs) { - var r = '', i = 0, a = [], c; - while(IS_CONS(xs)) { - c = CONS_HEAD(xs); - a[i++] = UNWRAP_NUMBER(c); - if(i >= 60000) { - r += h$fromCodePoint.apply(null, a); - a = []; - i = 0; - } - xs = CONS_TAIL(xs); - } - if(i > 0) r += h$fromCodePoint.apply(null, a); - TRACE_JSSTRING("pack: '" + r + "'"); - return r; -} - -function h$jsstringPackReverse(xs) { - var a = [], i = 0, c; - while(IS_CONS(xs)) { - c = CONS_HEAD(xs); - a[i++] = UNWRAP_NUMBER(c); - xs = CONS_TAIL(xs); - } - if(i===0) return ''; - var r = h$jsstringConvertArray(a.reverse()); - TRACE_JSSTRING("packReverse: '" + r + "'"); - return r; -} - -function h$jsstringPackArray(arr) { - TRACE_JSSTRING("pack array: " + arr); - return h$jsstringConvertArray(arr); -} - -function h$jsstringPackArrayReverse(arr) { - TRACE_JSSTRING("pack array reverse: " + arr); - return h$jsstringConvertArray(arr.reverse()); -} - -function h$jsstringConvertArray(arr) { - if(arr.length < 60000) { - return h$fromCodePoint.apply(null, arr); - } else { - var r = ''; - for(var i=0; i1) ? FROM_SURR(str.charCodeAt(l-2), ch) : -1; - - } else return ch; -} - -// index is the last part of the character -function h$jsstringIndexR(i, str) { - TRACE_JSSTRING("indexR: " + i + " '" + str + "'"); - if(i < 0 || i > str.length) return -1; - var ch = str.charCodeAt(i); - return (IS_LO_SURR(ch)) ? FROM_SURR(str.charCodeAt(i-1), ch) : ch; -} - -function h$jsstringNextIndex(i, str) { - TRACE_JSSTRING("nextIndex: " + i + " '" + str + "'"); - return i + (IS_HI_SURR(str.charCodeAt(i))?2:1); -} - -function h$jsstringTake(n, str) { - TRACE_JSSTRING("take: " + n + " '" + str + "'"); - if(n <= 0) return ''; - var i = 0, l = str.length, ch; - if(n >= l) return str; - while(n--) { - ch = str.charCodeAt(i++); - if(IS_HI_SURR(ch)) i++; - if(i >= l) return str; - } - return str.substr(0,i); -} - -function h$jsstringDrop(n, str) { - TRACE_JSSTRING("drop: " + n + " '" + str + "'"); - if(n <= 0) return str; - var i = 0, l = str.length, ch; - if(n >= l) return ''; - while(n--) { - ch = str.charCodeAt(i++); - if(IS_HI_SURR(ch)) i++; - if(i >= l) return ''; - } - return str.substr(i); -} - -function h$jsstringSplitAt(n, str) { - TRACE_JSSTRING("splitAt: " + n + " '" + str + "'"); - if(n <= 0) { - RETURN_UBX_TUP2("", str); - } else if(n >= str.length) { - RETURN_UBX_TUP2(str, ""); - } - var i = 0, l = str.length, ch; - while(n--) { - ch = str.charCodeAt(i++); - if(IS_HI_SURR(ch)) i++; - if(i >= l) { - RETURN_UBX_TUP2(str, ""); - } - } - RETURN_UBX_TUP2(str.substr(0,i),str.substr(i)); -} - -function h$jsstringTakeEnd(n, str) { - TRACE_JSSTRING("takeEnd: " + n + " '" + str + "'"); - if(n <= 0) return ''; - var l = str.length, i = l-1, ch; - if(n >= l) return str; - while(n-- && i > 0) { - ch = str.charCodeAt(i--); - if(IS_LO_SURR(ch)) i--; - } - return (i<0) ? str : str.substr(i+1); -} - -function h$jsstringDropEnd(n, str) { - TRACE_JSSTRING("dropEnd: " + n + " '" + str + "'"); - if(n <= 0) return str; - var l = str.length, i = l-1, ch; - if(n >= l) return ''; - while(n-- && i > 0) { - ch = str.charCodeAt(i--); - if(IS_LO_SURR(ch)) i--; - } - return (i<0) ? '' : str.substr(0,i+1); -} - -function h$jsstringIntercalate(x, ys) { - TRACE_JSSTRING("intercalate: '" + x + "'"); - var a = [], i = 0; - while(IS_CONS(ys)) { - if(i) a[i++] = x; - a[i++] = JSVAL_VAL(CONS_HEAD(ys)); - ys = CONS_TAIL(ys); - } - return a.join(''); -} - -function h$jsstringIntersperse(ch, ys) { - TRACE_JSSTRING("intersperse: " + ch + " '" + ys + "'"); - var i = 0, l = ys.length, j = 0, a = [], ych; - if(IS_ASTRAL(ch)) { - while(j < l) { - if(i) a[i++] = ch; - ych = ys.charCodeAt(j++); - a[i++] = ych; - if(IS_HI_SURR(ych)) a[i++] = ys.charCodeAt(j++); - } - } else { - while(j < l) { - if(i) a[i++] = ch; - ych = ys.charCodeAt(j++); - a[i++] = ych; - if(IS_HI_SURR(ych)) a[i++] = ys.charCodeAt(j++); - } - } - return h$jsstringConvertArray(a); -} - -function h$jsstringConcat(xs) { - TRACE_JSSTRING("concat"); - var a = [], i = 0; - while(IS_CONS(xs)) { - a[i++] = JSVAL_VAL(CONS_HEAD(xs)); - xs = CONS_TAIL(xs); - } - return a.join(''); -} - -var h$jsstringStripPrefix, h$jsstringStripSuffix, - h$jsstringIsPrefixOf, h$jsstringIsSuffixOf, - h$jsstringIsInfixOf; -if(String.prototype.startsWith) { - h$jsstringStripPrefix = function(p, x) { - TRACE_JSSTRING("(startsWith) stripPrefix: '" + p + "' '" + x + "'"); - if(x.startsWith(p)) { - return MK_JUST(MK_JSVAL(x.substr(p.length))); - } else { - return HS_NOTHING; - } - } - - h$jsstringIsPrefixOf = function(p, x) { - TRACE_JSSTRING("(startsWith) isPrefixOf: '" + p + "' '" + x + "'"); - return x.startsWith(p); - } - -} else { - h$jsstringStripPrefix = function(p, x) { - TRACE_JSSTRING("(no startsWith) stripPrefix: '" + p + "' '" + x + "'"); - if(x.indexOf(p) === 0) { // this has worse complexity than it should - return MK_JUST(MK_JSVAL(x.substr(p.length))); - } else { - return HS_NOTHING; - } - } - - h$jsstringIsPrefixOf = function(p, x) { - TRACE_JSSTRING("(no startsWith) isPrefixOf: '" + p + "' '" + x + "'"); - return x.indexOf(p) === 0; // this has worse complexity than it should - } -} - -if(String.prototype.endsWith) { - h$jsstringStripSuffix = function(s, x) { - TRACE_JSSTRING("(endsWith) stripSuffix: '" + s + "' '" + x + "'"); - if(x.endsWith(s)) { - return MK_JUST(MK_JSVAL(x.substr(0,x.length-s.length))); - } else { - return HS_NOTHING; - } - } - - h$jsstringIsSuffixOf = function(s, x) { - TRACE_JSSTRING("(endsWith) isSuffixOf: '" + s + "' '" + x + "'"); - return x.endsWith(s); - } -} else { - h$jsstringStripSuffix = function(s, x) { - TRACE_JSSTRING("(no endsWith) stripSuffix: '" + s + "' '" + x + "'"); - var i = x.lastIndexOf(s); // this has worse complexity than it should - var l = x.length - s.length; - if(i !== -1 && i === l) { - return MK_JUST(MK_JSVAL(x.substr(0,l))); - } else { - return HS_NOTHING; - } - } - - h$jsstringIsSuffixOf = function(s, x) { - TRACE_JSSTRING("(no endsWith) isSuffixOf: '" + s + "' '" + x + "'"); - var i = x.lastIndexOf(s); // this has worse complexity than it should - return i !== -1 && i === x.length - s.length; - } -} - -if(String.prototype.includes) { - h$jsstringIsInfixOf = function(i, x) { - TRACE_JSSTRING("(includes) isInfixOf: '" + i + "' '" + x + "'"); - return x.includes(i); - } -} else { - h$jsstringIsInfixOf = function(i, x) { - TRACE_JSSTRING("(no includes) isInfixOf: '" + i + "' '" + x + "'"); - return x.indexOf(i) !== -1; // this has worse complexity than it should - } -} - -function h$jsstringCommonPrefixes(x, y) { - TRACE_JSSTRING("commonPrefixes: '" + x + "' '" + y + "'"); - var lx = x.length, ly = y.length, i = 0, cx; - var l = lx <= ly ? lx : ly; - if(lx === 0 || ly === 0 || x.charCodeAt(0) !== y.charCodeAt(0)) { - return HS_NOTHING; - } - while(++i= 0) r = MK_CONS(a[i], r); - return r; -} - -function h$jsstringSplitOn1(n, p, x) { - TRACE_JSSTRING("splitOn1: " + n + " '" + p + "' '" + x + "'"); - var i = x.indexOf(p, n); - if(i === -1) { - RETURN_UBX_TUP2(-1, null); - } - var r1 = (i==n) ? "" : x.substr(n, i-n); - RETURN_UBX_TUP2(i + p.length, r1); -} - -function h$jsstringSplitOn(p, x) { - TRACE_JSSTRING("splitOn: '" + p + "' '" + x + "'"); - var a = x.split(p); - var r = HS_NIL, i = a.length; - while(--i>=0) r = MK_CONS(MK_JSVAL(a[i]), r); - return r; -} - -// returns -1 for end of input, start of next token otherwise -// word in h$ret1 -// this function assumes that there are no whitespace characters >= 0x10000 -function h$jsstringWords1(n, x) { - TRACE_JSSTRING("words1: " + n + " '" + x + "'"); - var m = n, s = n, l = x.length; - if(m >= l) return -1; - // skip leading spaces - do { - if(m >= l) return -1; - } while(h$isSpace(x.charCodeAt(m++))); - // found start of word - s = m - 1; - while(m < l) { - if(h$isSpace(x.charCodeAt(m++))) { - // found end of word - var r1 = (m-s<=1) ? "" : x.substr(s,m-s-1); - RETURN_UBX_TUP2(m, r1); - } - } - // end of string - if(s < l) { - var r1 = s === 0 ? x : x.substr(s); - RETURN_UBX_TUP2(m, r1); - } - RETURN_UBX_TUP2(-1, null); -} - -function h$jsstringWords(x) { - TRACE_JSSTRING("words: '" + x + "'"); - var a = null, i = 0, n, s = -1, m = 0, w, l = x.length, r = HS_NIL; - outer: - while(m < l) { - // skip leading spaces - do { - if(m >= l) { s = m; break outer; } - } while(h$isSpace(x.charCodeAt(m++))); - // found start of word - s = m - 1; - while(m < l) { - if(h$isSpace(x.charCodeAt(m++))) { - // found end of word - w = (m-s<=1) ? h$jsstringEmpty - : MK_JSVAL(x.substr(s,m-s-1)); - if(i) a[i++] = w; else { a = [w]; i = 1; } - s = m; - break; - } - } - } - // end of string - if(s !== -1 && s < l) { - w = MK_JSVAL(s === 0 ? x : x.substr(s)); - if(i) a[i++] = w; else { a = [w]; i = 1; } - } - // build resulting list - while(--i>=0) r = MK_CONS(a[i], r); - return r; -} - -// returns -1 for end of input, start of next token otherwise -// line in h$ret1 -function h$jsstringLines1(n, x) { - TRACE_JSSTRING("lines1: " + n + " '" + x + "'"); - var m = n, l = x.length; - if(n >= l) return -1; - while(m < l) { - if(x.charCodeAt(m++) === 10) { - // found newline - if(n > 0 && n === l-1) return -1; // it was the last character - var r1 = (m-n<=1) ? "" : x.substr(n,m-n-1); - RETURN_UBX_TUP2(m, r1); - } - } - // end of string - RETURN_UBX_TUP2(m, x.substr(n)); -} - -function h$jsstringLines(x) { - TRACE_JSSTRING("lines: '" + x + "'"); - var a = null, m = 0, i = 0, l = x.length, s = 0, r = HS_NIL, w; - if(l === 0) return HS_NIL; - outer: - while(true) { - s = m; - do { - if(m >= l) break outer; - } while(x.charCodeAt(m++) !== 10); - w = (m-s<=1) ? h$jsstringEmpty : MK_JSVAL(x.substr(s,m-s-1)); - if(i) a[i++] = w; else { a = [w]; i = 1; } - } - if(s < l) { - w = MK_JSVAL(x.substr(s)); - if(i) a[i++] = w; else { a = [w]; i = 1; } - } - while(--i>=0) r = MK_CONS(a[i], r); - return r; -} - -function h$jsstringGroup(x) { - TRACE_JSSTRING("group: '" + x + "'"); - var xl = x.length; - if(xl === 0) return HS_NIL; - var i = xl-1, si, ch, s=xl, r=HS_NIL; - var tch = x.charCodeAt(i--); - if(IS_LO_SURR(tch)) tch = FROM_SURR(x.charCodeAt(i--), tch); - while(i >= 0) { - si = i; - ch = x.charCodeAt(i--); - if(IS_LO_SURR(ch)) { - ch = FROM_SURR(x.charCodeAt(i--), ch); - } - if(ch != tch) { - tch = ch; - r = MK_CONS(MK_JSVAL(x.substr(si+1,s-si)), r); - s = si; - } - } - return MK_CONS(MK_JSVAL(x.substr(0,s+1)), r); -} - -function h$jsstringChunksOf1(n, s, x) { - TRACE_JSSTRING("chunksOf1: " + n + " " + s + " '" + x + "'"); - var m = s, c = 0, l = x.length, ch; - if(n <= 0 || l === 0 || s >= l) return -1 - while(++m < l) { - ch = x.charCodeAt(m - 1); - if(IS_HI_SURR(ch)) ++m; - if(++c >= n) break; - } - var r1 = (m >= l && s === c) ? x : x.substr(s,m-s); - RETURN_UBX_TUP2(m, r1); -} - -function h$jsstringChunksOf(n, x) { - TRACE_JSSTRING("chunksOf: " + n + " '" + x + "'"); - var l = x.length; - if(l===0 || n <= 0) return HS_NIL; - if(l <= n) return MK_CONS(MK_JSVAL(x), HS_NIL); - var a = [], i = 0, s = 0, ch, m = 0, c, r = HS_NIL; - while(m < l) { - s = m; - c = 0; - while(m < l && ++c <= n) { - ch = x.charCodeAt(m++); - if(IS_HI_SURR(ch)) ++m; - } - if(c) a[i++] = x.substr(s, m-s); - } - while(--i>=0) r = MK_CONS(MK_JSVAL(a[i]), r); - return r; -} - -function h$jsstringCount(pat, src) { - TRACE_JSSTRING("count: '" + pat + "' '" + src + "'"); - var i = 0, n = 0, pl = pat.length, sl = src.length; - while(i>= 1; - } while(n > 1); - return r+str; -} - -// this does not deal with combining diacritics, Data.Text does not either -var h$jsstringReverse; -if(Array.from) { - h$jsstringReverse = function(str) { - TRACE_JSSTRING("(Array.from) reverse: '" + str + "'"); - return Array.from(str).reverse().join(''); - } -} else { - h$jsstringReverse = function(str) { - TRACE_JSSTRING("(no Array.from) reverse: '" + str + "'"); - var l = str.length, a = [], o = 0, i = 0, c, c1, s = ''; - while(i < l) { - c = str.charCodeAt(i); - if(IS_HI_SURR(c)) { - a[i] = str.charCodeAt(i+1); - a[i+1] = c; - i += 2; - } else a[i++] = c; - if(i-o > 60000) { - s = String.fromCharCode.apply(null, a.reverse()) + s; - o = -i; - a = []; - } - } - return (i===0) ? s : String.fromCharCode.apply(null,a.reverse()) + s; - } -} - -function h$jsstringUnpack(str) { - TRACE_JSSTRING("unpack: '" + str + "'"); - var r = HS_NIL, i = str.length-1, c; - while(i >= 0) { - c = str.charCodeAt(i--); - if(IS_LO_SURR(c)) c = FROM_SURR(str.charCodeAt(i--), c) - r = MK_CONS(c, r); - } - return r; -} - - - -#if __GLASGOW_HASKELL__ >= 800 -function h$jsstringDecInteger(val) { - TRACE_JSSTRING("decInteger"); - if(IS_INTEGER_S(val)) { - return '' + INTEGER_S_DATA(val); - } else if(IS_INTEGER_Jp(val)) { - return h$ghcjsbn_showBase(INTEGER_J_DATA(val), 10); - } else { - return '-' + h$ghcjsbn_showBase(INTEGER_J_DATA(val), 10); - } -} -#else -function h$jsstringDecInteger(val) { - TRACE_JSSTRING("decInteger"); - if(IS_INTEGER_S(val)) { - return '' + INTEGER_S_DATA(val); - } else { - return INTEGER_J_DATA(val).toString(); - } -} -#endif - -function h$jsstringDecI64(hi,lo) { - TRACE_JSSTRING("decI64: " + hi + " " + lo); - var lo0 = (lo < 0) ? lo+4294967296:lo; - if(hi < 0) { - if(hi === -1) return ''+(lo0-4294967296); - lo0 = 4294967296 - lo0; - var hi0 = -1 - hi; - var x0 = hi0 * 967296; - var x1 = (lo0 + x0) % 1000000; - var x2 = hi0*4294+Math.floor((x0+lo0-x1)/1000000); - return '-' + x2 + h$jsstringDecIPadded6(x1); - } else { - if(hi === 0) return ''+lo0; - var x0 = hi * 967296; - var x1 = (lo0 + x0) % 1000000; - var x2 = hi*4294+Math.floor((x0+lo0-x1)/1000000); - return '' + x2 + h$jsstringDecIPadded6(x1); - } -} - -function h$jsstringDecW64(hi,lo) { - TRACE_JSSTRING("decW64: " + hi + " " + lo); - var lo0 = (lo < 0) ? lo+4294967296 : lo; - if(hi === 0) return ''+lo0; - var hi0 = (hi < 0) ? hi+4294967296 : hi; - var x0 = hi0 * 967296; - var x1 = (lo0 + x0) % 1000000; - var x2 = hi0*4294+Math.floor((x0+lo0-x1)/1000000); - return '' + x2 + h$jsstringDecIPadded6(x1); -} - -#if __GLASGOW_HASKELL__ >= 800 -function h$jsstringHexInteger(val) { - TRACE_JSSTRING("hexInteger"); - if(IS_INTEGER_S(val)) { - return '' + INTEGER_S_DATA(val); - } else { - // we assume it's nonnegative. this condition is checked by the Haskell code - return h$ghcjsbn_showBase(INTEGER_J_DATA(val), 16); - } -} -#else -function h$jsstringHexInteger(val) { - TRACE_JSSTRING("hexInteger"); - if(IS_INTEGER_S(val)) { - return '' + INTEGER_S_DATA(val); - } else { - return INTEGER_J_DATA(val).toRadix(16); - } -} -#endif - -function h$jsstringHexI64(hi,lo) { - var lo0 = lo<0 ? lo+4294967296 : lo; - if(hi === 0) return lo0.toString(16); - return ((hi<0)?hi+4294967296:hi).toString(16) + h$jsstringHexIPadded8(lo0); -} - -function h$jsstringHexW64(hi,lo) { - var lo0 = lo<0 ? lo+4294967296 : lo; - if(hi === 0) return lo0.toString(16); - return ((hi<0)?hi+4294967296:hi).toString(16) + h$jsstringHexIPadded8(lo0); -} - -// n in [0, 1000000000) -function h$jsstringDecIPadded9(n) { - TRACE_JSSTRING("decIPadded9: " + n); - if(n === 0) return '000000000'; - var pad = (n>=100000000)?'': - (n>=10000000)?'0': - (n>=1000000)?'00': - (n>=100000)?'000': - (n>=10000)?'0000': - (n>=1000)?'00000': - (n>=100)?'000000': - (n>=10)?'0000000': - '00000000'; - return pad+n; -} - -// n in [0, 1000000) -function h$jsstringDecIPadded6(n) { - TRACE_JSSTRING("decIPadded6: " + n); - if(n === 0) return '000000'; - var pad = (n>=100000)?'': - (n>=10000)?'0': - (n>=1000)?'00': - (n>=100)?'000': - (n>=10)?'0000': - '00000'; - return pad+n; -} - -// n in [0, 2147483648) -function h$jsstringHexIPadded8(n) { - TRACE_JSSTRING("hexIPadded8: " + n); - if(n === 0) return '00000000'; - var pad = (n>=0x10000000)?'': - (n>=0x1000000)?'0': - (n>=0x100000)?'00': - (n>=0x10000)?'000': - (n>=0x1000)?'0000': - (n>=0x100)?'00000': - (n>=0x10)?'000000': - '0000000'; - return pad+n.toString(16); -} - -function h$jsstringZeroes(n) { - var r; - switch(n&7) { - case 0: r = ''; break; - case 1: r = '0'; break; - case 2: r = '00'; break; - case 3: r = '000'; break; - case 4: r = '0000'; break; - case 5: r = '00000'; break; - case 6: r = '000000'; break; - case 7: r = '0000000'; - } - for(var i=n>>3;i>0;i--) r = r + '00000000'; - return r; -} - -function h$jsstringDoubleToFixed(decs, d) { - if(decs >= 0) { - if(Math.abs(d) < 1e21) { - var r = d.toFixed(Math.min(20,decs)); - if(decs > 20) r = r + h$jsstringZeroes(decs-20); - return r; - } else { - var r = d.toExponential(); - var ei = r.indexOf('e'); - var di = r.indexOf('.'); - var e = parseInt(r.substr(ei+1)); - return r.substring(0,di) + r.substring(di,ei) + h$jsstringZeroes(di-ei+e) + - ((decs > 0) ? ('.' + h$jsstringZeroes(decs)) : ''); - } - } - var r = Math.abs(d).toExponential(); - var ei = r.indexOf('e'); - var e = parseInt(r.substr(ei+1)); - var m = d < 0 ? '-' : ''; - r = r.substr(0,1) + r.substring(2,ei); - if(e >= 0) { - return (e > r.length) ? m + r + h$jsstringZeroes(r.length-e-1) + '.0' - : m + r.substr(0,e+1) + '.' + r.substr(e+1); - } else { - return m + '0.' + h$jsstringZeroes(-e-1) + r; - } -} - -function h$jsstringDoubleToExponent(decs, d) { - var r; - if(decs ===-1) { - r = d.toExponential().replace('+',''); - } else { - r = d.toExponential(Math.max(1, Math.min(20,decs))).replace('+',''); - } - if(r.indexOf('.') === -1) { - r = r.replace('e', '.0e'); - } - if(decs > 20) r = r.replace('e', h$jsstringZeroes(decs-20)+'e'); - return r; -} - -function h$jsstringDoubleGeneric(decs, d) { - var r; - if(decs === -1) { - r = d.toString(10).replace('+',''); - } else { - r = d.toPrecision(Math.max(decs+1,1)).replace('+',''); - } - if(decs !== 0 && r.indexOf('.') === -1) { - if(r.indexOf('e') !== -1) { - r = r.replace('e', '.0e'); - } else { - r = r + '.0'; - } - } - return r; -} - -function h$jsstringAppend(x, y) { - TRACE_JSSTRING("append: '" + x + "' '" + y + "'"); - return x+y; -} - -function h$jsstringCompare(x, y) { - TRACE_JSSTRING("compare: '" + x + "' '" + y + "'"); - return (xy)?1:0); -} - -function h$jsstringUnlines(xs) { - var r = ''; - while(IS_CONS(xs)) { - r = r + JSVAL_VAL(CONS_HEAD(xs)) + '\n'; - xs = CONS_TAIL(xs); - } - return r; -} - -function h$jsstringUnwords(xs) { - if(IS_NIL(xs)) return ''; - var r = JSVAL_VAL(CONS_HEAD(xs)); - xs = CONS_TAIL(xs); - while(IS_CONS(xs)) { - r = r + ' ' + JSVAL_VAL(CONS_HEAD(xs)); - xs = CONS_TAIL(xs); - } - return r; -} - -function h$jsstringReplace(pat, rep, src) { - TRACE_JSSTRING("replace: '" + pat + "' '" + rep + "' '" + src + "'"); - var r = src.replace(pat, rep, 'g'); - // the 'g' flag is not supported everywhere, check and fall back if necessary - if(r.indexOf(pat) !== -1) { - r = src.split(pat).join(rep); - } - return r; -} - -function h$jsstringReplicateChar(n, ch) { - TRACE_JSSTRING("replicateChar: " + n + " " + ch); - return h$jsstringReplicate(n, h$jsstringSingleton(ch)); -} - -function h$jsstringIsInteger(str) { - return /^-?\d+$/.test(str); -} - -function h$jsstringIsNatural(str) { - return /^\d+$/.test(str); -} - -function h$jsstringReadInt(str) { - if(!/^-?\d+/.test(str)) return null; - var x = parseInt(str, 10); - var x0 = x|0; - return (x===x0) ? x0 : null; -} - -function h$jsstringLenientReadInt(str) { - var x = parseInt(str, 10); - var x0 = x|0; - return (x===x0) ? x0 : null; -} - -function h$jsstringReadWord(str) { - if(!/^\d+/.test(str)) return null; - var x = parseInt(str, 10); - var x0 = x|0; - if(x0<0) return (x===x0+2147483648) ? x0 : null; - else return (x===x0) ? x0 : null; -} - -function h$jsstringReadDouble(str) { - return parseFloat(str, 10); -} - -function h$jsstringLenientReadDouble(str) { - return parseFloat(str, 10); -} - -function h$jsstringReadInteger(str) { - TRACE_JSSTRING("readInteger: " + str); - if(!/^(-)?\d+$/.test(str)) { - return null; - } else if(str.length <= 9) { - return MK_INTEGER_S(parseInt(str, 10)); - } else { -#if __GLASGOW_HASKELL__ >= 800 - return h$ghcjsbn_readInteger(str); -#else - return MK_INTEGER_J(new BigInteger(str, 10)); -#endif - } -} - -function h$jsstringReadInt64(str) { - if(!/^(-)?\d+$/.test(str)) { - RETURN_UBX_TUP3(0, 0, 0); - } - if(str.charCodeAt(0) === 45) { // '-' - return h$jsstringReadValue64(str, 1, true); - } else { - return h$jsstringReadValue64(str, 0, false); - } -} - -function h$jsstringReadWord64(str) { - if(!/^\d+$/.test(str)) { - RETURN_UBX_TUP3(0, 0, 0); - } - return h$jsstringReadValue64(str, 0, false); -} - -var h$jsstringLongs = null; - -function h$jsstringReadValue64(str, start, negate) { - var l = str.length, i = start; - while(i < l) { - if(str.charCodeAt(i) !== 48) break; - i++; - } - if(i >= l) RETURN_UBX_TUP3(1, 0, 0); // only zeroes - if(h$jsstringLongs === null) { - h$jsstringLongs = []; - for(var t=10; t<=1000000000; t*=10) { - h$jsstringLongs.push(goog.math.Long.fromInt(t)); - } - } - var li = l-i; - if(li < 10 && !negate) { - RETURN_UBX_TUP3(1, 0, parseInt(str.substr(i), 10)); - } - var r = goog.math.Long.fromInt(parseInt(str.substr(li,9),10)); - li += 9; - while(li < l) { - r = r.multiply(h$jsstringLongs[Math.min(l-li-1,8)]) - .add(goog.math.Long.fromInt(parseInt(str.substr(li,9), 10))); - li += 9; - } - if(negate) { - r = r.negate(); - } - RETURN_UBX_TUP3(1, r.getHighBits(), r.getLowBits()); -} - -function h$jsstringExecRE(i, str, re) { - re.lastIndex = i; - var m = re.exec(str); - if(m === null) return -1; - var a = [], x, j = 1, r = HS_NIL; - while(true) { - x = m[j]; - if(typeof x === 'undefined') break; - a[j-1] = x; - j++; - } - j-=1; - while(--j>=0) r = MK_CONS(MK_JSVAL(a[j]), r); - RETURN_UBX_TUP3(m.index, m[0], r); -} - -function h$jsstringReplaceRE(pat, replacement, str) { - return str.replace(pat, replacement); -} - -function h$jsstringSplitRE(limit, re, str) { - re.lastIndex = i; - var s = (limit < 0) ? str.split(re) : str.split(re, limit); - var i = s.length, r = HS_NIL; - while(--i>=0) r = MK_CONS(MK_JSVAL(a[i]), r); - return r; -} diff --git a/jsbits-old/jsstringRaw.js b/jsbits-old/jsstringRaw.js deleted file mode 100644 index 4d31c3c..0000000 --- a/jsbits-old/jsstringRaw.js +++ /dev/null @@ -1,21 +0,0 @@ -#include - -/* - * Functions that directly access JavaScript strings, ignoring character - * widths and surrogate pairs. - */ - -function h$jsstringRawChunksOf(k, x) { - var l = x.length; - if(l === 0) return HS_NIL; - if(l <= k) return MK_CONS(MK_JSVAL(x), HS_NIL); - var r=HS_NIL; - for(var i=ls-k;i>=0;i-=k) r = MK_CONS(MK_JSVAL(x.substr(i,i+k)),r); - return r; -} - -function h$jsstringRawSplitAt(k, x) { - if(k === 0) return MK_TUP2(h$jsstringEmpty, MK_JSVAL(x)); - if(k >= x.length) return MK_TUP2(MK_JSVAL(x), h$jsstringEmpty); - return MK_TUP2(MK_JSVAL(x.substr(0,k)), MK_JSVAL(x.substr(k))); -} diff --git a/jsbits-old/object.js b/jsbits-old/object.js deleted file mode 100644 index 44e0ca3..0000000 --- a/jsbits-old/object.js +++ /dev/null @@ -1,2 +0,0 @@ -// object manipulation - diff --git a/jsbits-old/text.js b/jsbits-old/text.js deleted file mode 100644 index 7046d36..0000000 --- a/jsbits-old/text.js +++ /dev/null @@ -1,53 +0,0 @@ -// conversion between JavaScript string and Data.Text -#include - - -/* - convert a Data.Text buffer with offset/length to a JavaScript string - */ -function h$textToString(arr, off, len) { - var a = []; - var end = off+len; - var k = 0; - var u1 = arr.u1; - var s = ''; - for(var i=off;i=0;i--) u1[i] = s.charCodeAt(i); - RETURN_UBX_TUP2(b, l); -} - -function h$lazyTextToString(txt) { - var s = ''; - while(LAZY_TEXT_IS_CHUNK(txt)) { - var head = LAZY_TEXT_CHUNK_HEAD(txt); - s += h$textToString(DATA_TEXT_ARRAY(head), DATA_TEXT_OFFSET(head), DATA_TEXT_LENGTH(head)); - txt = LAZY_TEXT_CHUNK_TAIL(txt); - } - return s; -} - -function h$safeTextFromString(x) { - if(typeof x !== 'string') { - RETURN_UBX_TUP2(null, 0); - } - return h$textFromString(x); -} diff --git a/jsbits-old/utils.js b/jsbits-old/utils.js deleted file mode 100644 index 722b793..0000000 --- a/jsbits-old/utils.js +++ /dev/null @@ -1,93 +0,0 @@ -#include - -function h$allProps(o) { - var a = [], i = 0; - for(var p in o) a[i++] = p; - return a; -} - -function h$listProps(o) { - var r = HS_NIL; - for(var p in o) { r = MK_CONS(MK_JSVAL(p), r); } - return r; -} - -function h$listAssocs(o) { - var r = HS_NIL; - for(var p in o) { r = MK_CONS(MK_TUP2(MK_JSVAL(p), MK_JSVAL(o[p])), r); } - return r; -} - -function h$isNumber(o) { - return typeof(o) === 'number'; -} - -// returns true for null, but not for functions and host objects -function h$isObject(o) { - return typeof(o) === 'object'; -} - -function h$isString(o) { - return typeof(o) === 'string'; -} - -function h$isSymbol(o) { - return typeof(o) === 'symbol'; -} - -function h$isBoolean(o) { - return typeof(o) === 'boolean'; -} - -function h$isFunction(o) { - return typeof(o) === 'function'; -} - -function h$jsTypeOf(o) { - var t = typeof(o); - if(t === 'undefined') return 0; - if(t === 'object') return 1; - if(t === 'boolean') return 2; - if(t === 'number') return 3; - if(t === 'string') return 4; - if(t === 'symbol') return 5; - if(t === 'function') return 6; - return 7; // other, host object etc -} - -/* - -- 0 - null, 1 - integer, - -- 2 - float, 3 - bool, - -- 4 - string, 5 - array - -- 6 - object -*/ -function h$jsonTypeOf(o) { - if (!(o instanceof Object)) { - if (o == null) { - return 0; - } else if (typeof o == 'number') { - if (h$isInteger(o)) { - return 1; - } else { - return 2; - } - } else if (typeof o == 'boolean') { - return 3; - } else { - return 4; - } - } else { - if (Object.prototype.toString.call(o) == '[object Array]') { - // it's an array - return 5; - } else if (!o) { - // null - return 0; - } else { - // it's an object - return 6; - } - } - -} - diff --git a/jsbits-old/websocket.js b/jsbits-old/websocket.js deleted file mode 100644 index 25df07b..0000000 --- a/jsbits-old/websocket.js +++ /dev/null @@ -1,58 +0,0 @@ -#include - -function h$createWebSocket(url, protocols) { - return new WebSocket(url, protocols); -} - -/* - this must be called before the websocket has connected, - typically synchronously after creating the socket - */ -function h$openWebSocket(ws, mcb, ccb, c) { - if(ws.readyState !== 0) { - throw new Error("h$openWebSocket: unexpected readyState, socket must be CONNECTING"); - } - ws.lastError = null; - ws.onopen = function() { - if(mcb) { - ws.onmessage = mcb; - } - if(ccb || mcb) { - ws.onclose = function(ce) { - if(ws.onmessage) { - h$release(ws.onmessage); - ws.onmessage = null; - } - if(ccb) { - h$release(ccb); - ccb(ce); - } - }; - }; - ws.onerror = function(err) { - ws.lastError = err; - if(ws.onmessage) { - h$release(ws.onmessage); - ws.onmessage = null; - } - ws.close(); - }; - c(null); - }; - ws.onerror = function(err) { - if(ccb) h$release(ccb); - if(mcb) h$release(mcb); - ws.onmessage = null; - ws.close(); - c(err); - }; -} - -function h$closeWebSocket(status, reason, ws) { - ws.onerror = null; - if(ws.onmessage) { - h$release(ws.onmessage); - ws.onmessage = null; - } - ws.close(status, reason); -} diff --git a/jsbits-old/xhr.js b/jsbits-old/xhr.js deleted file mode 100644 index 419cfe7..0000000 --- a/jsbits-old/xhr.js +++ /dev/null @@ -1,16 +0,0 @@ -function h$sendXHR(xhr, d, cont) { - xhr.addEventListener('error', function () { - cont(2); - }); - xhr.addEventListener('abort', function() { - cont(1); - }); - xhr.addEventListener('load', function() { - cont(0); - }); - if(d) { - xhr.send(d); - } else { - xhr.send(); - } -}