quickjs-emscripten-sync 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +71 -44
- package/dist/index.d.ts +116 -23
- package/dist/quickjs-emscripten-sync.mjs +842 -0
- package/dist/quickjs-emscripten-sync.umd.js +64 -2
- package/package.json +22 -53
- package/src/default.ts +2 -2
- package/src/index.test.ts +223 -59
- package/src/index.ts +72 -66
- package/src/marshal/custom.test.ts +50 -0
- package/src/marshal/custom.ts +36 -0
- package/src/marshal/function.test.ts +64 -75
- package/src/marshal/function.ts +15 -18
- package/src/marshal/index.test.ts +122 -77
- package/src/marshal/index.ts +19 -15
- package/src/marshal/json.test.ts +37 -41
- package/src/marshal/json.ts +5 -7
- package/src/marshal/object.test.ts +59 -84
- package/src/marshal/object.ts +8 -15
- package/src/marshal/primitive.test.ts +18 -21
- package/src/marshal/primitive.ts +11 -10
- package/src/marshal/promise.test.ts +85 -0
- package/src/marshal/promise.ts +19 -0
- package/src/marshal/properties.test.ts +24 -27
- package/src/marshal/properties.ts +15 -17
- package/src/unmarshal/custom.test.ts +50 -0
- package/src/unmarshal/custom.ts +31 -0
- package/src/unmarshal/function.test.ts +63 -86
- package/src/unmarshal/function.ts +13 -22
- package/src/unmarshal/index.test.ts +114 -109
- package/src/unmarshal/index.ts +15 -14
- package/src/unmarshal/object.test.ts +42 -46
- package/src/unmarshal/object.ts +16 -20
- package/src/unmarshal/primitive.test.ts +17 -15
- package/src/unmarshal/primitive.ts +11 -18
- package/src/unmarshal/promise.test.ts +44 -0
- package/src/unmarshal/promise.ts +31 -0
- package/src/unmarshal/properties.test.ts +11 -9
- package/src/unmarshal/properties.ts +44 -45
- package/src/util.test.ts +14 -2
- package/src/util.ts +18 -8
- package/src/vmmap.test.ts +88 -82
- package/src/vmmap.ts +30 -44
- package/src/vmutil.test.ts +100 -75
- package/src/vmutil.ts +51 -34
- package/src/wrapper.test.ts +129 -167
- package/src/wrapper.ts +59 -62
- package/dist/default.d.ts +0 -4
- package/dist/marshal/function.d.ts +0 -2
- package/dist/marshal/index.d.ts +0 -11
- package/dist/marshal/json.d.ts +0 -2
- package/dist/marshal/object.d.ts +0 -2
- package/dist/marshal/primitive.d.ts +0 -2
- package/dist/marshal/properties.d.ts +0 -2
- package/dist/marshal/symbol.d.ts +0 -2
- package/dist/quickjs-emscripten-sync.cjs +0 -2
- package/dist/quickjs-emscripten-sync.cjs.map +0 -1
- package/dist/quickjs-emscripten-sync.modern.js +0 -2
- package/dist/quickjs-emscripten-sync.modern.js.map +0 -1
- package/dist/quickjs-emscripten-sync.module.js +0 -2
- package/dist/quickjs-emscripten-sync.module.js.map +0 -1
- package/dist/quickjs-emscripten-sync.umd.js.map +0 -1
- package/dist/unmarshal/function.d.ts +0 -2
- package/dist/unmarshal/index.d.ts +0 -9
- package/dist/unmarshal/object.d.ts +0 -2
- package/dist/unmarshal/primitive.d.ts +0 -2
- package/dist/unmarshal/properties.d.ts +0 -2
- package/dist/unmarshal/symbol.d.ts +0 -2
- package/dist/util.d.ts +0 -7
- package/dist/vmmap.d.ts +0 -35
- package/dist/vmutil.d.ts +0 -11
- package/dist/wrapper.d.ts +0 -11
- package/src/marshal/symbol.test.ts +0 -22
- package/src/marshal/symbol.ts +0 -20
- package/src/unmarshal/symbol.test.ts +0 -23
- package/src/unmarshal/symbol.ts +0 -12
|
@@ -1,2 +1,64 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).quickjsEmscriptenSync={})}(this,function(e){function t(e,n){return t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},t(e,n)}function n(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function r(e,o,i){return r=n()?Reflect.construct:function(e,n,r){var o=[null];o.push.apply(o,n);var i=new(Function.bind.apply(e,o));return r&&t(i,r.prototype),i},r.apply(null,arguments)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=function(e){function t(e){var t=this;this.vm=void 0,this._map1=new Map,this._map2=new Map,this._map3=new Map,this._map4=new Map,this._counterMap=new Map,this._disposables=new Set,this._mapGet=void 0,this._mapSet=void 0,this._mapDelete=void 0,this._mapClear=void 0,this._counter=0,this.vm=e;var n=e.unwrapResult(e.evalCode('() => {\n const mapSym = new Map();\n let map = new WeakMap();\n let map2 = new WeakMap();\n const isObj = o => typeof o === "object" && o !== null || typeof o === "function";\n return {\n get: key => mapSym.get(key) ?? map.get(key) ?? map2.get(key) ?? -1,\n set: (key, value, key2) => {\n if (typeof key === "symbol") mapSym.set(key, value);\n if (isObj(key)) map.set(key, value);\n if (isObj(key2)) map2.set(key2, value);\n },\n delete: (key, key2) => {\n mapSym.delete(key);\n map.delete(key);\n map2.delete(key2);\n },\n clear: () => {\n mapSym.clear();\n map = new WeakMap();\n map2 = new WeakMap();\n }\n };\n }')).consume(function(e){return t._call(e,void 0)});this._mapGet=e.getProp(n,"get"),this._mapSet=e.getProp(n,"set"),this._mapDelete=e.getProp(n,"delete"),this._mapClear=e.getProp(n,"clear"),n.dispose(),this._disposables.add(this._mapGet),this._disposables.add(this._mapSet),this._disposables.add(this._mapDelete),this._disposables.add(this._mapClear)}var n,r=t.prototype;return r.set=function(e,t,n,r){var o,i=this;if(!t.alive||r&&!r.alive)return!1;var a=null!=(o=this.get(e))?o:this.get(n);if(a)return a===t||a===r;var s=this._counter++;return this._map1.set(e,s),this._map3.set(s,t),this._counterMap.set(s,e),n&&(this._map2.set(n,s),r&&this._map4.set(s,r)),this.vm.newNumber(s).consume(function(e){i._call(i._mapSet,void 0,t,e,null!=r?r:i.vm.undefined)}),!0},r.merge=function(e){if(e)for(var t,n=i(e);!(t=n()).done;){var r=t.value;r&&r[1]&&this.set(r[0],r[1],r[2],r[3])}},r.get=function(e){var t,n=null!=(t=this._map1.get(e))?t:this._map2.get(e),r="number"==typeof n?this._map3.get(n):void 0;if(r){if(r.alive)return r;this.delete(e)}},r.getByHandle=function(e){if(e.alive)return this._counterMap.get(this.vm.getNumber(this._call(this._mapGet,void 0,e)))},r.has=function(e){return!!this.get(e)},r.hasHandle=function(e){return void 0!==this.getByHandle(e)},r.delete=function(e,t){var n,r=null!=(n=this._map1.get(e))?n:this._map2.get(e);if(void 0!==r){var o=this._map3.get(r),a=this._map4.get(r);this._call.apply(this,[this._mapDelete,void 0].concat([o,a].filter(function(e){return!(null==e||!e.alive)}))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(r),this._map4.delete(r);for(var s,u=i(this._map1);!(s=u()).done;){var l=s.value;if(l[1]===r){this._map1.delete(l[0]);break}}for(var p,c=i(this._map2);!(p=c()).done;){var f=p.value;if(f[1]===r){this._map2.delete(f[0]);break}}for(var d,v=i(this._counterMap);!(d=v()).done;){var y=d.value;if(y[1]===e){this._counterMap.delete(y[0]);break}}t&&(null!=o&&o.alive&&o.dispose(),null!=a&&a.alive&&a.dispose())}},r.deleteByHandle=function(e,t){var n=this.getByHandle(e);void 0!==n&&this.delete(n,t)},r.clear=function(){this._counter=0,this._map1.clear(),this._map2.clear(),this._map3.clear(),this._map4.clear(),this._counterMap.clear(),this._mapClear.alive&&this._call(this._mapClear,void 0)},r.dispose=function(){for(var e,t=i(this._disposables.values());!(e=t()).done;){var n=e.value;n.alive&&n.dispose()}for(var r,o=i(this._map3.values());!(r=o()).done;){var a=r.value;a.alive&&a.dispose()}for(var s,u=i(this._map4.values());!(s=u()).done;){var l=s.value;l.alive&&l.dispose()}this._disposables.clear(),this.clear()},r[e]=function(){var e=this,t=this._map1.keys();return{next:function(){for(;;){var n=t.next();if(n.done)return{value:void 0,done:!0};var r=e._map1.get(n.value);if(void 0!==r){var o=e._map3.get(r),i=e._map4.get(r);if(o){var a=e._get2(r);return{value:[n.value,o,a,i],done:!1}}}}}}},r._get2=function(e){for(var t,n=i(this._map2);!(t=n()).done;){var r=t.value;if(r[1]===e)return r[0]}},r._call=function(e,t){var n;return this.vm.unwrapResult((n=this.vm).callFunction.apply(n,[e,void 0===t?this.vm.undefined:t].concat([].slice.call(arguments,2))))},(n=[{key:"size",get:function(){return this._map1.size}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,n),t}(Symbol.iterator);function s(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}function u(e){return"function"==typeof e||"object"==typeof e&&null!==e}function l(e,t){var n=new Set;return function e(r){if(u(r)&&!n.has(r)&&!1!==(null==t?void 0:t(r,n)))if(n.add(r),Array.isArray(r))for(var o,a=i(r);!(o=a()).done;)e(o.value);else{if("object"==typeof r){var s=Object.getPrototypeOf(r);s&&s!==Object.prototype&&e(s)}for(var l=0,p=Object.values(Object.getOwnPropertyDescriptors(r));l<p.length;l++){var c=p[l];"value"in c&&e(c.value),"get"in c&&e(c.get),"set"in c&&e(c.set)}}}(e),n}function p(e,t,n){var r=[].slice.call(arguments,3);return e.unwrapResult(e.evalCode(t)).consume(function(t){return void 0===n&&0===r.length?t:e.unwrapResult(e.callFunction.apply(e,[t,null!=n?n:e.undefined].concat(r)))})}function c(e,t,n){return e.dump(p(e,"Object.is",void 0,t,n))}function f(e,t){return e.dump(p(e,'a => typeof a === "object" && a !== null || typeof a === "function"',void 0,t))}function d(e,t){var n=JSON.stringify(t);return n?p(e,"JSON.parse",void 0,e.newString(n)):e.undefined}function v(e,t){try{return t(e)}finally{for(var n,r=i(e);!(n=r()).done;){var o=n.value;o.alive&&o.dispose()}}}function y(e,t){try{return t.apply(void 0,e.map(function(e){return e[0]}))}finally{for(var n,r=i(e);!(n=r()).done;){var o=n.value;o[1]&&o[0].dispose()}}}function h(e,t,n,r){var o=e.newObject(),i=function(t,n){var i=r(t),a=void 0===n.value?void 0:r(n.value),s=void 0===n.get?void 0:r(n.get),u=void 0===n.set?void 0:r(n.set);e.newObject().consume(function(t){Object.entries(n).forEach(function(n){var r=n[0],o="value"===r?a:"get"===r?s:"set"===r?u:n[1]?e.true:e.false;o&&e.setProp(t,r,o)}),e.setProp(o,i,t)})},a=Object.getOwnPropertyDescriptors(t);Object.entries(a).forEach(function(e){return i(e[0],e[1])}),Object.getOwnPropertySymbols(a).forEach(function(e){return i(e,a[e])}),p(e,"Object.defineProperties",void 0,n,o).dispose(),o.dispose()}function m(e,t){var n,o,i,a=t.vm,l=t.unmarshal,c=t.isMarshalable,f=t.find,v=t.pre,y=function(e,t){switch(typeof t){case"undefined":return e.undefined;case"number":return e.newNumber(t);case"string":return e.newString(t);case"boolean":return t?e.true:e.false;case"object":return null===t?e.null:void 0}}(a,e);if(y)return y;var _=f(e);if(_)return _;var b=null==c?void 0:c(e);if(!1===b)return a.undefined;var g=function(e,t){return v(e,t,b)};if("json"===b)return function(e,t,n){var r,o=d(e,t);return null!=(r=n(t,o))?r:o}(a,e,g);var w=function(e){return m(e,t)};return null!=(n=null!=(o=null!=(i=function(e,t,n){var r;if("symbol"==typeof t){var o=p(e,"d => Symbol(d)",void 0,t.description?e.newString(t.description):e.undefined);return null!=(r=n(t,o))?r:o}}(a,e,g))?i:function(e,t,n,o,i,a){var l;if("function"==typeof t){var c=e.newFunction(t.name,function(){var i=this,l=o(this),p=[].slice.call(arguments).map(function(e){return o(e)});if(s(t)&&u(l)){var c=r(t,p);return Object.entries(c).forEach(function(t){e.setProp(i,t[0],n(t[1]))}),this}return n(a?a(t,l,p):t.apply(l,p))}).consume(function(t){return p(e,"Cls => {\n const fn = function(...args) { return Cls.apply(this, args); };\n fn.name = Cls.name;\n fn.length = Cls.length;\n return fn;\n }",void 0,t)}),f=null!=(l=i(t,c))?l:c;return h(e,t,c,n),f}}(a,e,w,l,g,t.preApply))?o:function(e,t,n,r){var o;if("object"==typeof t&&null!==t){var i=Array.isArray(t)?e.newArray():e.newObject(),a=null!=(o=r(t,i))?o:i,s=Object.getPrototypeOf(t),u=s&&s!==Object.prototype&&s!==Array.prototype?n(s):void 0;return u&&p(e,"Object.setPrototypeOf",void 0,a,u).dispose(),h(e,t,i,n),a}}(a,e,w,g))?n:a.undefined}function _(e,t,n,r){e.newFunction("",function(t,o){var i=r(t)[0];if("string"==typeof i||"number"==typeof i||"symbol"==typeof i){var a=[["value",!0],["get",!0],["set",!0],["configurable",!1],["enumerable",!1],["writable",!1]].reduce(function(t,n){var i=n[0],a=n[1],s=e.getProp(o,i),u=e.typeof(s);if("undefined"===u)return t;if(!a&&"boolean"===u)return t[i]=e.dump(e.getProp(o,i)),t;var l=r(s),p=l[0];return l[1]&&s.dispose(),t[i]=p,t},{});Object.defineProperty(n,i,a)}}).consume(function(n){p(e,"(o, fn) => {\n const descs = Object.getOwnPropertyDescriptors(o);\n Object.entries(descs).forEach(([k, v]) => fn(k, v));\n Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));\n }",void 0,t,n).dispose()})}function b(e,t){return g(e,t)[0]}function g(e,t){var n,r,o=t.vm,i=t.marshal,a=t.find,s=t.pre,u=function(e,t){var n=e.typeof(t);return"undefined"===n||"number"===n||"string"===n||"boolean"===n?[e.dump(t),!0]:"object"===n&&e.unwrapResult(e.evalCode("a => a === null")).consume(function(n){return e.dump(e.unwrapResult(e.callFunction(n,e.undefined,t)))})?[null,!0]:[void 0,!1]}(o,e);if(u[1])return[u[0],!1];var l=a(e);if(l)return[l,!0];var c=function(e){return g(e,t)},f=null!=(n=null!=(r=function(e,t,n){var r;if("symbol"===e.typeof(t)){var o=e.getString(e.getProp(t,"description")),i=Symbol(o);return null!=(r=n(i,t))?r:i}}(o,e,s))?r:function(e,t,n,r,o){var i;if("function"===e.typeof(t)){var a=function o(){var i=this instanceof o?this.constructor:void 0,a=this;return y([n(this)].concat([].slice.call(arguments).map(function(e){return n(e)})),function(n){var o=[].slice.call(arguments,1);if(i){var s=r(p.apply(void 0,[e,"(Cls, ...args) => new Cls(...args)",n,t].concat(o)));return Object.defineProperties(a,Object.getOwnPropertyDescriptors(s[0])),a}var u=e.unwrapResult(e.callFunction.apply(e,[t,n].concat(o))),l=r(u),c=l[0];return l[1]&&u.dispose(),c})},s=null!=(i=o(a,t))?i:a;return _(e,t,a,r),s}}(o,e,i,c,s))?n:function(e,t,n,r){var o;if("object"===e.typeof(t)&&!e.unwrapResult(e.evalCode("o => o === null")).consume(function(n){return e.dump(e.unwrapResult(e.callFunction(n,e.undefined,t)))})){var i=p(e,"Array.isArray",void 0,t).consume(function(t){return e.dump(t)})?[]:{},a=null!=(o=r(i,t))?o:i,s=p(e,"o => {\n const p = Object.getPrototypeOf(o);\n return !p || p === Object.prototype || p === Array.prototype ? undefined : p;\n }",void 0,t).consume(function(t){if("undefined"!==e.typeof(t))return n(t)[0]});return"object"==typeof s&&Object.setPrototypeOf(a,s),_(e,t,i,n),a}}(o,e,c,s);return[f,!1]}function w(e,t){var n;return u(e)&&null!=(n=e[t])?n:e}function j(e,t,n){return S(e,t,n)?[e.getProp(t,n),!0]:[t,!1]}function S(e,t,n){return!!e.dump(p(e,'(a, s) => (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',void 0,t,n))}var O=[[Symbol,"Symbol"],[Symbol.prototype,"Symbol.prototype"],[Object,"Object"],[Object.prototype,"Object.prototype"],[Function,"Function"],[Function.prototype,"Function.prototype"],[Boolean,"Boolean"],[Boolean.prototype,"Boolean.prototype"],[Array,"Array"],[Array.prototype,"Array.prototype"],[Error,"Error"],[Error.prototype,"Error.prototype"],[EvalError,"EvalError"],[EvalError.prototype,"EvalError.prototype"],[RangeError,"RangeError"],[RangeError.prototype,"RangeError.prototype"],[ReferenceError,"ReferenceError"],[ReferenceError.prototype,"ReferenceError.prototype"],[SyntaxError,"SyntaxError"],[SyntaxError.prototype,"SyntaxError.prototype"],[TypeError,"TypeError"],[TypeError.prototype,"TypeError.prototype"],[URIError,"URIError"],[URIError.prototype,"URIError.prototype"]].concat(Object.getOwnPropertyNames(Symbol).filter(function(e){return"symbol"==typeof Symbol[e]}).map(function(e){return[Symbol[e],"Symbol."+e]}));e.Arena=function(){function e(e,t){var n,r=this;this.vm=void 0,this._map=void 0,this._registeredMap=void 0,this._registeredMapDispose=new Set,this._sync=new Set,this._temporalSync=new Set,this._symbol=Symbol(),this._symbolHandle=void 0,this._options=void 0,this._isMarshalable=function(e){var t,n,o=null==(t=r._options)?void 0:t.isMarshalable;return null!=(n="function"==typeof o?o(r._unwrap(e)):o)?n:"json"},this._marshalFind=function(e){var t,n,o,i=r._unwrap(e);return null!=(t=null!=(n=null!=(o=r._registeredMap.get(e))?o:i!==e?r._registeredMap.get(i):void 0)?n:r._map.get(e))?t:i!==e?r._map.get(i):void 0},this._marshalPre=function(e,t,n){var o;if("json"!==n)return null==(o=r._register(e,t,r._map))?void 0:o[1]},this._marshalPreApply=function(e,t,n){var o=u(t)?r._unwrap(t):void 0;o&&r._temporalSync.add(o);try{return e.apply(t,n)}finally{o&&r._temporalSync.delete(o)}},this._marshal=function(e){var t,n=r._registeredMap.get(e);if(n)return[n,!1];var o=m(null!=(t=r._wrap(e))?t:e,{vm:r.vm,unmarshal:r._unmarshal,isMarshalable:r._isMarshalable,find:r._marshalFind,pre:r._marshalPre,preApply:r._marshalPreApply});return[o,!r._map.hasHandle(o)]},this._preUnmarshal=function(e,t){var n;return null==(n=r._register(e,t,void 0,!0))?void 0:n[0]},this._unmarshalFind=function(e){var t;return null!=(t=r._registeredMap.getByHandle(e))?t:r._map.getByHandle(e)},this._unmarshal=function(e){var t=r._registeredMap.getByHandle(e);if(void 0!==t)return t;var n=r._wrapHandle(e)[0];return b(null!=n?n:e,{vm:r.vm,marshal:r._marshal,find:r._unmarshalFind,pre:r._preUnmarshal})},this._syncMode=function(e){var t=r._unwrap(e);return r._sync.has(t)||r._temporalSync.has(t)?"both":void 0},this._unwrapIfNotSynced=function(e){var t=r._unwrap(e);return r._sync.has(t)?e:t},this.vm=e,this._options=t,this._symbolHandle=e.unwrapResult(e.evalCode("Symbol()")),this._map=new a(e),this._registeredMap=new a(e),this.registerAll(null!=(n=null==t?void 0:t.registeredObjects)?n:O)}var t=e.prototype;return t.dispose=function(){this._map.dispose(),this._registeredMap.dispose(),this._symbolHandle.dispose()},t.evalCode=function(e){var t=this.vm.evalCode(e);return this._unwrapResultAndUnmarshal(t)},t.executePendingJobs=function(e){var t=this.vm.executePendingJobs(e);if("value"in t)return t.value;throw this._unwrapIfNotSynced(t.error.consume(this._unmarshal))},t.expose=function(e){for(var t=this,n=0,r=Object.entries(e);n<r.length;n++)i=(o=r[n])[0],function(e,n){var r=e[0],o=e[1];try{!function(e){t.vm.setProp(t.vm.global,i,e)}(r)}finally{o&&r.dispose()}}(t._marshal(o[1]));var o,i},t.sync=function(e){var t=this,n=this._wrap(e);return void 0===n?e:(l(n,function(e){t._sync.add(t._unwrap(e))}),n)},t.register=function(e,t){if(!this._registeredMap.has(e)){var n="string"==typeof t?this._unwrapResult(this.vm.evalCode(t)):t;c(this.vm,n,this.vm.undefined)||("string"==typeof t&&this._registeredMapDispose.add(e),this._registeredMap.set(e,n))}},t.registerAll=function(e){for(var t,n=i(e);!(t=n()).done;){var r=t.value;this.register(r[0],r[1])}},t.unregister=function(e,t){this._registeredMap.delete(e,this._registeredMapDispose.has(e)||t),this._registeredMapDispose.delete(e)},t.unregisterAll=function(e,t){for(var n,r=i(e);!(n=r()).done;)this.unregister(n.value,t)},t.startSync=function(e){u(e)&&this._sync.add(this._unwrap(e))},t.endSync=function(e){this._sync.delete(this._unwrap(e))},t._unwrapResult=function(e){if("value"in e)return e.value;throw this._unwrapIfNotSynced(e.error.consume(this._unmarshal))},t._unwrapResultAndUnmarshal=function(e){if(e)return this._unwrapIfNotSynced(this._unwrapResult(e).consume(this._unmarshal))},t._register=function(e,t,n,r){if(void 0===n&&(n=this._map),!this._registeredMap.has(e)&&!this._registeredMap.hasHandle(t)){var o=this._wrap(e),i=this._wrapHandle(t)[0];if(o&&i){var a=this._unwrap(e),s=this._unwrapHandle(t),u=s[0],l=s[1];if(!n.set(o,i,a,u))throw l&&u.dispose(),new Error("already registered");return r&&this._sync.add(a),[o,i]}}},t._wrap=function(e){return function(e,t,n,r,o,i){if(u(t)){if(s=n,u(a=t)&&a[s])return t;var a,s,l=new Proxy(t,{get:function(e,t){return t===n?e:Reflect.get(e,t)},set:function(t,a,s,u){var l,p=w(s,n),c=null!=(l=null==i?void 0:i(u))?l:"host";return"vm"!==c&&!Reflect.set(t,a,p,u)||"host"===c||!e.alive||y([o(u),o(a),o(p)],function(t,n,o){var i=j(e,t,r),a=i[0];i[1]?a.consume(function(t){return e.setProp(t,n,o)}):e.setProp(a,n,o)}),!0},deleteProperty:function(t,n){var a,s=null!=(a=null==i?void 0:i(l))?a:"host";return y([o(l),o(n)],function(o,i){var a=j(e,o,r),u=a[0],l=a[1];if("vm"===s||Reflect.deleteProperty(t,n)){if("host"===s||!e.alive)return!0;l?u.consume(function(t){return p(e,"(a, b) => delete a[b]",void 0,t,i)}):p(e,"(a, b) => delete a[b]",void 0,u,i)}return!0})}});return l}}(this.vm,e,this._symbol,this._symbolHandle,this._marshal,this._syncMode)},t._unwrap=function(e){return w(e,this._symbol)},t._wrapHandle=function(e){return function(e,t,n,r,o,i){return f(e,t)?S(e,t,r)?[t,!1]:v([e.newFunction("getSyncMode",function(t){var n=null==i?void 0:i(o(t));return"string"==typeof n?e.newString(n):e.undefined}),e.newFunction("setter",function(e,t,r){var i=o(e);if(i){var a=o(t);if("__proto__"!==a){var s=o(r);w(i,n)[a]=s}}}),e.newFunction("deleter",function(e,t){var r=o(e);if(r){var i=o(t);delete w(r,n)[i]}})],function(n){return[p.apply(void 0,[e,'(target, sym, getSyncMode, setter, deleter) => {\n const rec = new Proxy(target, {\n get(obj, key, receiver) {\n return key === sym ? obj : Reflect.get(obj, key, receiver)\n },\n set(obj, key, value, receiver) {\n const v = typeof value === "object" && value !== null || typeof value === "function"\n ? value[sym] ?? value\n : value;\n const sync = getSyncMode(receiver) ?? "vm";\n if (sync === "host" || Reflect.set(obj, key, v, receiver)) {\n if (sync !== "vm") {\n setter(receiver, key, v);\n }\n }\n return true;\n },\n deleteProperty(obj, key) {\n const sync = getSyncMode(rec) ?? "vm";\n if (sync === "host" || Reflect.deleteProperty(obj, key)) {\n if (sync !== "vm") {\n deleter(rec, key);\n }\n }\n return true;\n },\n });\n return rec;\n }',void 0,t,r].concat(n)),!0]}):[void 0,!1]}(this.vm,e,this._symbol,this._symbolHandle,this._unmarshal,this._syncMode)},t._unwrapHandle=function(e){return j(this.vm,e,this._symbolHandle)},e}(),e.VMMap=a,e.call=p,e.complexity=function(e,t){return l(e,t?function(e,n){return n.size<t}:void 0).size},e.consumeAll=v,e.defaultRegisteredObjects=O,e.eq=c,e.isES2015Class=s,e.isHandleObject=f,e.isObject=u,e.json=d,e.marshal=m,e.unmarshal=b,e.walkObject=l});
|
|
2
|
-
|
|
1
|
+
(function(h,w){typeof exports=="object"&&typeof module!="undefined"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(h=typeof globalThis!="undefined"?globalThis:h||self,w(h.QuickjsEmscriptenSync={}))})(this,function(h){"use strict";const w=[[Symbol,"Symbol"],[Symbol.prototype,"Symbol.prototype"],[Object,"Object"],[Object.prototype,"Object.prototype"],[Function,"Function"],[Function.prototype,"Function.prototype"],[Boolean,"Boolean"],[Boolean.prototype,"Boolean.prototype"],[Array,"Array"],[Array.prototype,"Array.prototype"],[Error,"Error"],[Error.prototype,"Error.prototype"],[EvalError,"EvalError"],[EvalError.prototype,"EvalError.prototype"],[RangeError,"RangeError"],[RangeError.prototype,"RangeError.prototype"],[ReferenceError,"ReferenceError"],[ReferenceError.prototype,"ReferenceError.prototype"],[SyntaxError,"SyntaxError"],[SyntaxError.prototype,"SyntaxError.prototype"],[TypeError,"TypeError"],[TypeError.prototype,"TypeError.prototype"],[URIError,"URIError"],[URIError.prototype,"URIError.prototype"],...Object.getOwnPropertyNames(Symbol).filter(t=>typeof Symbol[t]=="symbol").map(t=>[Symbol[t],`Symbol.${t}`])];function I(t,e){const r=t.unwrapResult(t.evalCode(e)),i=(n,...s)=>t.unwrapResult(t.callFunction(r,n!=null?n:t.undefined,...s));return i.dispose=()=>r.dispose(),i.alive=!0,Object.defineProperty(i,"alive",{get:()=>r.alive}),i}function d(t,e,r,...i){const n=I(t,e);try{return n(r,...i)}finally{n.dispose()}}function M(t,e,r){return t.dump(d(t,"Object.is",void 0,e,r))}function U(t,e,r){return t.dump(d(t,"(a, b) => a instanceof b",void 0,e,r))}function R(t,e){return t.dump(d(t,'a => typeof a === "object" && a !== null || typeof a === "function"',void 0,e))}function k(t,e){const r=JSON.stringify(e);return r?d(t,"JSON.parse",void 0,t.newString(r)):t.undefined}function H(t,e){try{return e(t)}finally{for(const r of t)r.alive&&r.dispose()}}function W([t,e],r){try{return r(t)}finally{e&&t.dispose()}}function j(t,e){try{return e(...t.map(r=>r[0]))}finally{for(const[r,i]of t)i&&r.dispose()}}function z(t){return"handle"in t}function $(t){return z(t)?t.handle:t}function G(t,e,r,i){var s;let n;for(const o of i)if(n=o(e,t),n)break;return n?(s=r(e,n))!=null?s:n:void 0}function q(t,e){return typeof t!="symbol"?void 0:d(e,"d => Symbol(d)",void 0,t.description?e.newString(t.description):e.undefined)}function Q(t,e){return t instanceof Date?d(e,"d => new Date(d)",void 0,e.newNumber(t.getTime())):void 0}const V=[q,Q];function C(t){return typeof t=="function"&&/^class\s/.test(Function.prototype.toString.call(t))}function v(t){return typeof t=="function"||typeof t=="object"&&t!==null}function P(t,e){const r=new Set,i=n=>{if(!(!v(n)||r.has(n)||(e==null?void 0:e(n,r))===!1)){if(r.add(n),Array.isArray(n)){for(const s of n)i(s);return}if(typeof n=="object"){const s=Object.getPrototypeOf(n);s&&s!==Object.prototype&&i(s)}for(const s of Object.values(Object.getOwnPropertyDescriptors(n)))"value"in s&&i(s.value),"get"in s&&i(s.get),"set"in s&&i(s.set)}};return i(t),r}function L(t,e){return P(t,e?(r,i)=>i.size<e:void 0).size}function X(){let t=()=>{},e=()=>{};return{promise:new Promise((i,n)=>{t=i,e=n}),resolve:t,reject:e}}function D(t,e,r,i){const n=t.newObject(),s=(u,a)=>{const p=i(u),l=typeof a.value=="undefined"?void 0:i(a.value),f=typeof a.get=="undefined"?void 0:i(a.get),c=typeof a.set=="undefined"?void 0:i(a.set);t.newObject().consume(m=>{Object.entries(a).forEach(([y,_])=>{const b=y==="value"?l:y==="get"?f:y==="set"?c:_?t.true:t.false;b&&t.setProp(m,y,b)}),t.setProp(n,p,m)})},o=Object.getOwnPropertyDescriptors(e);Object.entries(o).forEach(([u,a])=>s(u,a)),Object.getOwnPropertySymbols(o).forEach(u=>s(u,o[u])),d(t,"Object.defineProperties",void 0,r,n).dispose(),n.dispose()}function Y(t,e,r,i,n,s){var a;if(typeof e!="function")return;const o=t.newFunction(e.name,function(...p){const l=i(this),f=p.map(c=>i(c));if(C(e)&&v(l)){const c=new e(...f);return Object.entries(c).forEach(([m,y])=>{t.setProp(this,m,r(y))}),this}return r(s?s(e,l,f):e.apply(l,f))}).consume(p=>d(t,`Cls => {
|
|
2
|
+
const fn = function(...args) { return Cls.apply(this, args); };
|
|
3
|
+
fn.name = Cls.name;
|
|
4
|
+
fn.length = Cls.length;
|
|
5
|
+
return fn;
|
|
6
|
+
}`,void 0,p)),u=(a=n(e,o))!=null?a:o;return D(t,e,o,r),u}function Z(t,e,r){var s;const i=k(t,e);return(s=r(e,i))!=null?s:i}function K(t,e,r,i){var a;if(typeof e!="object"||e===null)return;const n=Array.isArray(e)?t.newArray():t.newObject(),s=(a=i(e,n))!=null?a:n,o=Object.getPrototypeOf(e),u=o&&o!==Object.prototype&&o!==Array.prototype?r(o):void 0;return u&&d(t,"Object.setPrototypeOf",void 0,s,u).dispose(),D(t,e,n,r),s}function x(t,e){switch(typeof e){case"undefined":return t.undefined;case"number":return t.newNumber(e);case"string":return t.newString(e);case"boolean":return e?t.true:t.false;case"object":return e===null?t.null:void 0}}function ee(t,e,r,i){var s;if(!(e instanceof Promise))return;const n=t.newPromise();return e.then(o=>n.resolve(r(o)),o=>n.reject(r(o))),(s=i(e,n))!=null?s:n.handle}function O(t,e){var l,f,c,m,y;const{ctx:r,unmarshal:i,isMarshalable:n,find:s,pre:o}=e;{const _=x(r,t);if(_)return _}{const _=s(t);if(_)return _}const u=n==null?void 0:n(t);if(u===!1)return r.undefined;const a=(_,b)=>o(_,b,u);if(u==="json")return Z(r,t,a);const p=_=>O(_,e);return(y=(m=(c=(f=G(r,t,a,[...V,...(l=e.custom)!=null?l:[]]))!=null?f:ee(r,t,p,a))!=null?c:Y(r,t,p,i,a,e.preApply))!=null?m:K(r,t,p,a))!=null?y:r.undefined}function te(t,e,r,i){var s;let n;for(const o of i)if(n=o(e,t),n)break;return n?(s=r(n,e))!=null?s:n:void 0}function re(t,e){if(e.typeof(t)!=="symbol")return;const r=e.getString(e.getProp(t,"description"));return Symbol(r)}function ne(t,e){if(!e.dump(d(e,"a => a instanceof Date",void 0,t)))return;const r=e.getNumber(d(e,"a => a.getTime()",void 0,t));return new Date(r)}const se=[re,ne];function F(t,e,r,i){t.newFunction("",(n,s)=>{const[o]=i(n);if(typeof o!="string"&&typeof o!="number"&&typeof o!="symbol")return;const u=[["value",!0],["get",!0],["set",!0],["configurable",!1],["enumerable",!1],["writable",!1]].reduce((a,[p,l])=>{const f=t.getProp(s,p),c=t.typeof(f);if(c==="undefined")return a;if(!l&&c==="boolean")return a[p]=t.dump(t.getProp(s,p)),a;const[m,y]=i(f);return y&&f.dispose(),a[p]=m,a},{});Object.defineProperty(r,o,u)}).consume(n=>{d(t,`(o, fn) => {
|
|
7
|
+
const descs = Object.getOwnPropertyDescriptors(o);
|
|
8
|
+
Object.entries(descs).forEach(([k, v]) => fn(k, v));
|
|
9
|
+
Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));
|
|
10
|
+
}`,void 0,e,n).dispose()})}function ie(t,e,r,i,n){var u;if(t.typeof(e)!=="function")return;const s=function(...a){return j([r(this),...a.map(p=>r(p))],(p,...l)=>{if(new.target){const[y]=i(d(t,"(Cls, ...args) => new Cls(...args)",p,e,...l));return Object.defineProperties(this,Object.getOwnPropertyDescriptors(y)),this}const f=t.unwrapResult(t.callFunction(e,p,...l)),[c,m]=i(f);return m&&f.dispose(),c})},o=(u=n(s,e))!=null?u:s;return F(t,e,s,i),o}function oe(t,e,r,i){var u;if(t.typeof(e)!=="object"||t.unwrapResult(t.evalCode("o => o === null")).consume(a=>t.dump(t.unwrapResult(t.callFunction(a,t.undefined,e)))))return;const n=d(t,"Array.isArray",void 0,e).consume(a=>t.dump(a))?[]:{},s=(u=i(n,e))!=null?u:n,o=d(t,`o => {
|
|
11
|
+
const p = Object.getPrototypeOf(o);
|
|
12
|
+
return !p || p === Object.prototype || p === Array.prototype ? undefined : p;
|
|
13
|
+
}`,void 0,e).consume(a=>{if(t.typeof(a)==="undefined")return;const[p]=r(a);return p});return typeof o=="object"&&Object.setPrototypeOf(s,o),F(t,e,n,r),s}function ue(t,e){const r=t.typeof(e);return r==="undefined"||r==="number"||r==="string"||r==="boolean"?[t.dump(e),!0]:r==="object"&&t.unwrapResult(t.evalCode("a => a === null")).consume(n=>t.dump(t.unwrapResult(t.callFunction(n,t.undefined,e))))?[null,!0]:[void 0,!1]}function ae(t,e,r,i){var p;if(!pe(t,e))return;const n=X(),[s,o]=r(n.resolve),[u,a]=r(n.reject);return d(t,"(p, res, rej) => { p.then(res, rej); }",void 0,e,s,u),o&&s.dispose(),a&&u.dispose(),(p=i(n.promise,e))!=null?p:n.promise}function pe(t,e){return e.owner?t.unwrapResult(t.evalCode("Promise")).consume(r=>e.owner?U(t,e,r):!1):!1}function A(t,e){const[r]=N(t,e);return r}function N(t,e){var a,p,l,f;const{ctx:r,marshal:i,find:n,pre:s}=e;{const[c,m]=ue(r,t);if(m)return[c,!1]}{const c=n(t);if(c)return[c,!0]}const o=c=>N(c,e);return[(f=(l=(p=te(r,t,s,[...se,...(a=e.custom)!=null?a:[]]))!=null?p:ae(r,t,i,s))!=null?l:ie(r,t,i,o,s))!=null?f:oe(r,t,o,s),!1]}class S{constructor(e){this._map1=new Map,this._map2=new Map,this._map3=new Map,this._map4=new Map,this._counterMap=new Map,this._disposables=new Set,this._counter=0,this.ctx=e;const r=e.unwrapResult(e.evalCode(`() => {
|
|
14
|
+
const mapSym = new Map();
|
|
15
|
+
let map = new WeakMap();
|
|
16
|
+
let map2 = new WeakMap();
|
|
17
|
+
const isObj = o => typeof o === "object" && o !== null || typeof o === "function";
|
|
18
|
+
return {
|
|
19
|
+
get: key => mapSym.get(key) ?? map.get(key) ?? map2.get(key) ?? -1,
|
|
20
|
+
set: (key, value, key2) => {
|
|
21
|
+
if (typeof key === "symbol") mapSym.set(key, value);
|
|
22
|
+
if (isObj(key)) map.set(key, value);
|
|
23
|
+
if (isObj(key2)) map2.set(key2, value);
|
|
24
|
+
},
|
|
25
|
+
delete: (key, key2) => {
|
|
26
|
+
mapSym.delete(key);
|
|
27
|
+
map.delete(key);
|
|
28
|
+
map2.delete(key2);
|
|
29
|
+
},
|
|
30
|
+
clear: () => {
|
|
31
|
+
mapSym.clear();
|
|
32
|
+
map = new WeakMap();
|
|
33
|
+
map2 = new WeakMap();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}`)).consume(i=>this._call(i,void 0));this._mapGet=e.getProp(r,"get"),this._mapSet=e.getProp(r,"set"),this._mapDelete=e.getProp(r,"delete"),this._mapClear=e.getProp(r,"clear"),r.dispose(),this._disposables.add(this._mapGet),this._disposables.add(this._mapSet),this._disposables.add(this._mapDelete),this._disposables.add(this._mapClear)}set(e,r,i,n){var u;if(!r.alive||n&&!n.alive)return!1;const s=(u=this.get(e))!=null?u:this.get(i);if(s)return s===r||s===n;const o=this._counter++;return this._map1.set(e,o),this._map3.set(o,r),this._counterMap.set(o,e),i&&(this._map2.set(i,o),n&&this._map4.set(o,n)),this.ctx.newNumber(o).consume(a=>{this._call(this._mapSet,void 0,r,a,n!=null?n:this.ctx.undefined)}),!0}merge(e){if(!!e)for(const r of e)!r||r[1]&&this.set(r[0],r[1],r[2],r[3])}get(e){var n;const r=(n=this._map1.get(e))!=null?n:this._map2.get(e),i=typeof r=="number"?this._map3.get(r):void 0;if(!!i){if(!i.alive){this.delete(e);return}return i}}getByHandle(e){if(!!e.alive)return this._counterMap.get(this.ctx.getNumber(this._call(this._mapGet,void 0,e)))}has(e){return!!this.get(e)}hasHandle(e){return typeof this.getByHandle(e)!="undefined"}keys(){return this._map1.keys()}delete(e,r){var o;const i=(o=this._map1.get(e))!=null?o:this._map2.get(e);if(typeof i=="undefined")return;const n=this._map3.get(i),s=this._map4.get(i);this._call(this._mapDelete,void 0,...[n,s].filter(u=>!!(u!=null&&u.alive))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(i),this._map4.delete(i);for(const[u,a]of this._map1)if(a===i){this._map1.delete(u);break}for(const[u,a]of this._map2)if(a===i){this._map2.delete(u);break}for(const[u,a]of this._counterMap)if(a===e){this._counterMap.delete(u);break}r&&(n!=null&&n.alive&&n.dispose(),s!=null&&s.alive&&s.dispose())}deleteByHandle(e,r){const i=this.getByHandle(e);typeof i!="undefined"&&this.delete(i,r)}clear(){this._counter=0,this._map1.clear(),this._map2.clear(),this._map3.clear(),this._map4.clear(),this._counterMap.clear(),this._mapClear.alive&&this._call(this._mapClear,void 0)}dispose(){for(const e of this._disposables.values())e.alive&&e.dispose();for(const e of this._map3.values())e.alive&&e.dispose();for(const e of this._map4.values())e.alive&&e.dispose();this._disposables.clear(),this.clear()}get size(){return this._map1.size}[Symbol.iterator](){const e=this._map1.keys();return{next:()=>{for(;;){const r=e.next();if(r.done)return{value:void 0,done:!0};const i=this._map1.get(r.value);if(typeof i=="undefined")continue;const n=this._map3.get(i),s=this._map4.get(i);if(!n)continue;const o=this._get2(i);return{value:[r.value,n,o,s],done:!1}}}}}_get2(e){for(const[r,i]of this._map2)if(i===e)return r}_call(e,r,...i){return this.ctx.unwrapResult(this.ctx.callFunction(e,typeof r=="undefined"?this.ctx.undefined:r,...i))}}function fe(t,e,r,i,n,s,o){if(!v(e)||e instanceof Promise||e instanceof Date||o&&!o(e))return;if(ce(e,r))return e;const u=new Proxy(e,{get(a,p){return p===r?a:Reflect.get(a,p)},set(a,p,l,f){var y;const c=g(l,r),m=(y=s==null?void 0:s(f))!=null?y:"host";return m!=="vm"&&!Reflect.set(a,p,c,f)||m==="host"||!t.alive||j([n(f),n(p),n(c)],(_,b,T)=>{const[J,he]=E(t,_,i);he?J.consume(me=>t.setProp(me,b,T)):t.setProp(J,b,T)}),!0},deleteProperty(a,p){var f;const l=(f=s==null?void 0:s(u))!=null?f:"host";return j([n(u),n(p)],(c,m)=>{const[y,_]=E(t,c,i);if(l==="vm"||Reflect.deleteProperty(a,p)){if(l==="host"||!t.alive)return!0;_?y.consume(b=>d(t,"(a, b) => delete a[b]",void 0,b,m)):d(t,"(a, b) => delete a[b]",void 0,y,m)}return!0})}});return u}function le(t,e,r,i,n,s,o){return!R(t,e)||o&&!o(e,t)?[void 0,!1]:B(t,e,i)?[e,!1]:H([t.newFunction("getSyncMode",u=>{const a=s==null?void 0:s(n(u));return typeof a=="string"?t.newString(a):t.undefined}),t.newFunction("setter",(u,a,p)=>{const l=n(u);if(!l)return;const f=n(a);if(f==="__proto__")return;const c=n(p);g(l,r)[f]=c}),t.newFunction("deleter",(u,a)=>{const p=n(u);if(!p)return;const l=n(a);delete g(p,r)[l]})],u=>[d(t,`(target, sym, getSyncMode, setter, deleter) => {
|
|
37
|
+
const rec = new Proxy(target, {
|
|
38
|
+
get(obj, key, receiver) {
|
|
39
|
+
return key === sym ? obj : Reflect.get(obj, key, receiver)
|
|
40
|
+
},
|
|
41
|
+
set(obj, key, value, receiver) {
|
|
42
|
+
const v = typeof value === "object" && value !== null || typeof value === "function"
|
|
43
|
+
? value[sym] ?? value
|
|
44
|
+
: value;
|
|
45
|
+
const sync = getSyncMode(receiver) ?? "vm";
|
|
46
|
+
if (sync === "host" || Reflect.set(obj, key, v, receiver)) {
|
|
47
|
+
if (sync !== "vm") {
|
|
48
|
+
setter(receiver, key, v);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
deleteProperty(obj, key) {
|
|
54
|
+
const sync = getSyncMode(rec) ?? "vm";
|
|
55
|
+
if (sync === "host" || Reflect.deleteProperty(obj, key)) {
|
|
56
|
+
if (sync !== "vm") {
|
|
57
|
+
deleter(rec, key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return rec;
|
|
64
|
+
}`,void 0,e,i,...u),!0])}function g(t,e){var r;return v(t)&&(r=t[e])!=null?r:t}function E(t,e,r){return B(t,e,r)?[t.getProp(e,r),!0]:[e,!1]}function ce(t,e){return v(t)&&!!t[e]}function B(t,e,r){return!!t.dump(d(t,'(a, s) => (a instanceof Promise) || (a instanceof Date) || (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',void 0,e,r))}class de{constructor(e,r){var i;this._registeredMapDispose=new Set,this._sync=new Set,this._temporalSync=new Set,this._symbol=Symbol(),this._isMarshalable=n=>{var o,u;const s=(o=this._options)==null?void 0:o.isMarshalable;return(u=typeof s=="function"?s(this._unwrap(n)):s)!=null?u:"json"},this._marshalFind=n=>{var u,a,p;const s=this._unwrap(n);return(p=(a=(u=this._registeredMap.get(n))!=null?u:s!==n?this._registeredMap.get(s):void 0)!=null?a:this._map.get(n))!=null?p:s!==n?this._map.get(s):void 0},this._marshalPre=(n,s,o)=>{var u;if(o!=="json")return(u=this._register(n,$(s),this._map))==null?void 0:u[1]},this._marshalPreApply=(n,s,o)=>{const u=v(s)?this._unwrap(s):void 0;u&&this._temporalSync.add(u);try{return n.apply(s,o)}finally{u&&this._temporalSync.delete(u)}},this._marshal=n=>{var u,a;const s=this._registeredMap.get(n);if(s)return[s,!1];const o=O((u=this._wrap(n))!=null?u:n,{ctx:this.context,unmarshal:this._unmarshal,isMarshalable:this._isMarshalable,find:this._marshalFind,pre:this._marshalPre,preApply:this._marshalPreApply,custom:(a=this._options)==null?void 0:a.customMarshaller});return[o,!this._map.hasHandle(o)]},this._preUnmarshal=(n,s)=>{var o;return(o=this._register(n,s,void 0,!0))==null?void 0:o[0]},this._unmarshalFind=n=>{var s;return(s=this._registeredMap.getByHandle(n))!=null?s:this._map.getByHandle(n)},this._unmarshal=n=>{var u;const s=this._registeredMap.getByHandle(n);if(typeof s!="undefined")return s;const[o]=this._wrapHandle(n);return A(o!=null?o:n,{ctx:this.context,marshal:this._marshal,find:this._unmarshalFind,pre:this._preUnmarshal,custom:(u=this._options)==null?void 0:u.customUnmarshaller})},this._syncMode=n=>{const s=this._unwrap(n);return this._sync.has(s)||this._temporalSync.has(s)?"both":void 0},this._unwrapIfNotSynced=n=>{const s=this._unwrap(n);return s instanceof Promise||!this._sync.has(s)?s:n},(r==null?void 0:r.compat)&&!("runtime"in e)&&(e.runtime={hasPendingJob:()=>e.hasPendingJob(),executePendingJobs:n=>e.executePendingJobs(n)}),this.context=e,this._options=r,this._symbolHandle=e.unwrapResult(e.evalCode("Symbol()")),this._map=new S(e),this._registeredMap=new S(e),this.registerAll((i=r==null?void 0:r.registeredObjects)!=null?i:w)}dispose(){this._map.dispose(),this._registeredMap.dispose(),this._symbolHandle.dispose()}evalCode(e){const r=this.context.evalCode(e);return this._unwrapResultAndUnmarshal(r)}executePendingJobs(e){const r=this.context.runtime.executePendingJobs(e);if("value"in r)return r.value;throw this._unwrapIfNotSynced(r.error.consume(this._unmarshal))}expose(e){for(const[r,i]of Object.entries(e))W(this._marshal(i),n=>{this.context.setProp(this.context.global,r,n)})}sync(e){const r=this._wrap(e);return typeof r=="undefined"?e:(P(r,i=>{const n=this._unwrap(i);this._sync.add(n)}),r)}register(e,r){if(this._registeredMap.has(e))return;const i=typeof r=="string"?this._unwrapResult(this.context.evalCode(r)):r;M(this.context,i,this.context.undefined)||(typeof r=="string"&&this._registeredMapDispose.add(e),this._registeredMap.set(e,i))}registerAll(e){for(const[r,i]of e)this.register(r,i)}unregister(e,r){this._registeredMap.delete(e,this._registeredMapDispose.has(e)||r),this._registeredMapDispose.delete(e)}unregisterAll(e,r){for(const i of e)this.unregister(i,r)}startSync(e){if(!v(e))return;const r=this._unwrap(e);this._sync.add(r)}endSync(e){this._sync.delete(this._unwrap(e))}_unwrapResult(e){if("value"in e)return e.value;throw this._unwrapIfNotSynced(e.error.consume(this._unmarshal))}_unwrapResultAndUnmarshal(e){if(!!e)return this._unwrapIfNotSynced(this._unwrapResult(e).consume(this._unmarshal))}_register(e,r,i=this._map,n){if(this._registeredMap.has(e)||this._registeredMap.hasHandle(r))return;let s=this._wrap(e);const[o]=this._wrapHandle(r),u=e instanceof Promise;if(!o||!s&&!u)return;u&&(s=e);const a=this._unwrap(e),[p,l]=this._unwrapHandle(r);if(i.set(s,o,a,p))n&&this._sync.add(a);else throw l&&p.dispose(),new Error("already registered");return[s,o]}_wrap(e){var r;return fe(this.context,e,this._symbol,this._symbolHandle,this._marshal,this._syncMode,(r=this._options)==null?void 0:r.isWrappable)}_unwrap(e){return g(e,this._symbol)}_wrapHandle(e){var r;return le(this.context,e,this._symbol,this._symbolHandle,this._unmarshal,this._syncMode,(r=this._options)==null?void 0:r.isHandleWrappable)}_unwrapHandle(e){return E(this.context,e,this._symbolHandle)}}h.Arena=de,h.VMMap=S,h.call=d,h.complexity=L,h.consumeAll=H,h.defaultRegisteredObjects=w,h.eq=M,h.isES2015Class=C,h.isHandleObject=R,h.isObject=v,h.json=k,h.marshal=O,h.unmarshal=A,h.walkObject=P,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,75 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickjs-emscripten-sync",
|
|
3
3
|
"author": "rot1024",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"source": "./src/index.ts",
|
|
8
|
-
"main": "./dist/quickjs-emscripten-sync.
|
|
9
|
-
"module": "./dist/quickjs-emscripten-sync.
|
|
10
|
-
"exports": "./dist/quickjs-emscripten-sync.modern.js",
|
|
7
|
+
"main": "./dist/quickjs-emscripten-sync.umd.js",
|
|
8
|
+
"module": "./dist/quickjs-emscripten-sync.es.js",
|
|
11
9
|
"unpkg": "./dist/quickjs-emscripten-sync.umd.js",
|
|
12
10
|
"types": "./dist/index.d.ts",
|
|
13
11
|
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/quickjs-emscripten-sync.es.js",
|
|
15
|
+
"require": "./dist/quickjs-emscripten-sync.umd.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
14
18
|
"files": [
|
|
15
19
|
"dist",
|
|
16
20
|
"src"
|
|
17
21
|
],
|
|
18
22
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
23
|
+
"node": ">=12"
|
|
20
24
|
},
|
|
21
25
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"lint": "tsc && eslint --ext '.ts,.tsx,.js' .",
|
|
26
|
-
"size": "size-limit",
|
|
27
|
-
"analyze": "size-limit --why"
|
|
26
|
+
"build": "tsc && vite build",
|
|
27
|
+
"test": "vitest",
|
|
28
|
+
"lint": "eslint ."
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"quickjs-emscripten": "*"
|
|
31
32
|
},
|
|
32
|
-
"jest": {
|
|
33
|
-
"preset": "ts-jest"
|
|
34
|
-
},
|
|
35
|
-
"prettier": {
|
|
36
|
-
"printWidth": 80,
|
|
37
|
-
"semi": true,
|
|
38
|
-
"singleQuote": false,
|
|
39
|
-
"trailingComma": "es5"
|
|
40
|
-
},
|
|
41
|
-
"size-limit": [
|
|
42
|
-
{
|
|
43
|
-
"path": "dist/quickjs-emscripten-sync.cjs",
|
|
44
|
-
"limit": "10 KB"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"path": "dist/quickjs-emscripten-sync.umd.js",
|
|
48
|
-
"limit": "10 KB"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"path": "dist/quickjs-emscripten-sync.module.js",
|
|
52
|
-
"limit": "10 KB"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"path": "dist/quickjs-emscripten-sync.modern.js",
|
|
56
|
-
"limit": "10 KB"
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
33
|
"devDependencies": {
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"prettier": "^2.4.0",
|
|
70
|
-
"quickjs-emscripten": "^0.13.0",
|
|
71
|
-
"size-limit": "^5.0.3",
|
|
72
|
-
"ts-jest": "^27.0.5",
|
|
73
|
-
"typescript": "^4.4.3"
|
|
34
|
+
"c8": "^7.12.0",
|
|
35
|
+
"eslint": "^8.22.0",
|
|
36
|
+
"eslint-config-reearth": "^0.1.0",
|
|
37
|
+
"prettier": "^2.7.1",
|
|
38
|
+
"quickjs-emscripten": "^0.21.0",
|
|
39
|
+
"typescript": "^4.8.2",
|
|
40
|
+
"vite": "^3.0.9",
|
|
41
|
+
"vite-plugin-dts": "^1.4.1",
|
|
42
|
+
"vitest": "^0.22.1"
|
|
74
43
|
}
|
|
75
44
|
}
|
package/src/default.ts
CHANGED
|
@@ -32,6 +32,6 @@ export const defaultRegisteredObjects: [any, string][] = [
|
|
|
32
32
|
[URIError.prototype, "URIError.prototype"],
|
|
33
33
|
// built-in symbols
|
|
34
34
|
...Object.getOwnPropertyNames(Symbol)
|
|
35
|
-
.filter(
|
|
36
|
-
.map<[any, string]>(
|
|
35
|
+
.filter(k => typeof (Symbol as any)[k] === "symbol")
|
|
36
|
+
.map<[any, string]>(k => [(Symbol as any)[k], `Symbol.${k}`]),
|
|
37
37
|
];
|