UNPKG

@mcesystems/nbind

Version:

Magical headers that make your C++ library accessible from JavaScript

946 lines (945 loc) 118 kB
!function(e){function t(e){Object.defineProperty(this,e,{enumerable:!0,get:function(){return this[v][e]}})}function r(e){if("undefined"!=typeof System&&System.isModule?System.isModule(e):"[object Module]"===Object.prototype.toString.call(e))return e;var t={default:e,__useDefault:e};if(e&&e.__esModule)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return new o(t)}function o(e){Object.defineProperty(this,v,{value:e}),Object.keys(e).forEach(t,this)}function n(e){return"@node/"===e.substr(0,6)?c(e,r(m(e.substr(6))),{}):p[e]}function u(e){var t=n(e);if(!t)throw new Error('Module "'+e+'" expected, but not contained in build.');if(t.module)return t.module;var r=t.linkRecord;return i(t,r),a(t,r,[]),t.module}function i(e,t){if(!t.depLoads){t.declare&&d(e,t),t.depLoads=[];for(var r=0;r<t.deps.length;r++){var o=n(t.deps[r]);t.depLoads.push(o),o.linkRecord&&i(o,o.linkRecord);var u=t.setters&&t.setters[r];u&&(u(o.module||o.linkRecord.moduleObj),o.importerSetters.push(u))}return e}}function d(t,r){var o=r.moduleObj,n=t.importerSetters,u=!1,i=r.declare.call(e,function(e,t){if(!u){if("object"==typeof e)for(var r in e)"__useDefault"!==r&&(o[r]=e[r]);else o[e]=t;u=!0;for(var i=0;i<n.length;i++)n[i](o);return u=!1,t}},{id:t.key});"function"!=typeof i?(r.setters=i.setters,r.execute=i.execute):(r.setters=[],r.execute=i)}function l(e,t,r){return p[e]={key:e,module:void 0,importerSetters:[],linkRecord:{deps:t,depLoads:void 0,declare:r,setters:void 0,execute:void 0,moduleObj:{}}}}function f(e,t,r,o){var n={};return p[e]={key:e,module:void 0,importerSetters:[],linkRecord:{deps:t,depLoads:void 0,declare:void 0,execute:o,executingRequire:r,moduleObj:{default:n,__useDefault:n},setters:void 0}}}function s(e,t,r){return function(o){for(var n=0;n<e.length;n++)if(e[n]===o){var u,i=t[n],d=i.linkRecord;return u=d?-1===r.indexOf(i)?a(i,d,r):d.moduleObj:i.module,"__useDefault"in u?u.__useDefault:u}}}function a(t,r,n){if(n.push(t),t.module)return t.module;var u;if(r.setters){for(var i=0;i<r.deps.length;i++){var d=r.depLoads[i],l=d.linkRecord;l&&-1===n.indexOf(d)&&(u=a(d,l,l.setters?n:[]))}r.execute.call(y)}else{var f={id:t.key},c=r.moduleObj;Object.defineProperty(f,"exports",{configurable:!0,set:function(e){c.default=c.__useDefault=e},get:function(){return c.__useDefault}});var p=s(r.deps,r.depLoads,n);if(!r.executingRequire)for(var i=0;i<r.deps.length;i++)p(r.deps[i]);var v=r.execute.call(e,p,c.__useDefault,f);void 0!==v?c.default=c.__useDefault=v:f.exports!==c.__useDefault&&(c.default=c.__useDefault=f.exports);var m=c.__useDefault;if(m&&m.__esModule)for(var b in m)Object.hasOwnProperty.call(m,b)&&(c[b]=m[b])}var f=t.module=new o(r.moduleObj);if(!r.setters)for(var i=0;i<t.importerSetters.length;i++)t.importerSetters[i](f);return f}function c(e,t){return p[e]={key:e,module:t,importerSetters:[],linkRecord:void 0}}var p={},v="undefined"!=typeof Symbol?Symbol():"@@baseObject";o.prototype=Object.create(null),"undefined"!=typeof Symbol&&Symbol.toStringTag&&(o.prototype[Symbol.toStringTag]="Module");var m="undefined"!=typeof System&&System._nodeRequire||"undefined"!=typeof require&&"undefined"!=typeof require.resolve&&"undefined"!=typeof process&&process.platform&&require,y={};return Object.freeze&&Object.freeze(y),function(e,t,n,i){return function(d){d(function(d){var s={_nodeRequire:m,register:l,registerDynamic:f,registry:{get:function(e){return p[e].module},set:c},newModule:function(e){return new o(e)}};c("@empty",new o({}));for(var a=0;a<t.length;a++)c(t[a],r(arguments[a],{}));i(s);var v=u(e[0]);if(e.length>1)for(var a=1;a<e.length;a++)u(e[a]);return n?v.__useDefault:(v instanceof o&&Object.defineProperty(v,"__esModule",{value:!0}),v)})}}}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this) (["a"], [], true, function($__System) { var require = this.require, exports = this.exports, module = this.module; $__System.registerDynamic("b", ["e", "c", "d"], true, function ($__require, exports, module) { var global = this || self, GLOBAL = global; // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd. // Released under the MIT license, see LICENSE. var __extends = exports && exports.__extends || function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __decorate = exports && exports.__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var emscripten_library_decorator_1 = $__require("e"); var BindingType_1 = $__require("c"); var Wrapper_1 = $__require("d"); // Let decorators run eval in current scope to read function source code. emscripten_library_decorator_1.setEvil(function (code) { return eval(code); }); var _nbind; (function (_nbind) { _nbind.BindType = BindingType_1._nbind.BindType; _nbind.Wrapper = Wrapper_1._nbind.Wrapper; })(_nbind = exports._nbind || (exports._nbind = {})); (function (_nbind) { _nbind.ptrMarker = {}; // Base class for all bound C++ classes (not their instances), // also inheriting from a generic type definition. var BindClass = /** @class */function (_super) { __extends(BindClass, _super); function BindClass(spec) { var _this = _super.call(this, spec) || this; _this.wireRead = function (arg) { return _nbind.popValue(arg, _this.ptrType); }; _this.wireWrite = function (arg) { return pushPointer(arg, _this.ptrType, true); }; /** Number of super classes left to initialize. */ _this.pendingSuperCount = 0; _this.ready = false; _this.methodTbl = {}; if (spec.paramList) { _this.classType = spec.paramList[0].classType; _this.proto = _this.classType.proto; } else _this.classType = _this; return _this; } BindClass.prototype.makeBound = function (policyTbl) { var Bound = _nbind.makeBound(policyTbl, this); this.proto = Bound; this.ptrType.proto = Bound; return Bound; }; BindClass.prototype.addMethod = function (spec) { var overloadList = this.methodTbl[spec.name] || []; overloadList.push(spec); this.methodTbl[spec.name] = overloadList; }; BindClass.prototype.registerMethods = function (src, staticOnly) { var setter; for (var _i = 0, _a = Object.keys(src.methodTbl); _i < _a.length; _i++) { var name = _a[_i]; var overloadList = src.methodTbl[name]; for (var _b = 0, overloadList_1 = overloadList; _b < overloadList_1.length; _b++) { var spec = overloadList_1[_b]; var target = void 0; var caller = void 0; target = this.proto.prototype; if (staticOnly && spec.signatureType != 1 /* func */) continue; switch (spec.signatureType) { case 1 /* func */: target = this.proto; // tslint:disable-next-line:no-switch-case-fall-through case 5 /* construct */: caller = _nbind.makeCaller(spec); _nbind.addMethod(target, spec.name, caller, spec.typeList.length - 1); break; case 4 /* setter */: setter = _nbind.makeMethodCaller(src.ptrType, spec); break; case 3 /* getter */: Object.defineProperty(target, spec.name, { configurable: true, enumerable: false, get: _nbind.makeMethodCaller(src.ptrType, spec), set: setter }); break; case 2 /* method */: caller = _nbind.makeMethodCaller(src.ptrType, spec); _nbind.addMethod(target, spec.name, caller, spec.typeList.length - 1); break; default: break; } } } }; BindClass.prototype.registerSuperMethods = function (src, firstSuper, visitTbl) { if (visitTbl[src.name]) return; visitTbl[src.name] = true; var superNum = 0; var nextFirst; for (var _i = 0, _a = src.superIdList || []; _i < _a.length; _i++) { var superId = _a[_i]; var superClass = _nbind.getType(superId); if (superNum++ < firstSuper || firstSuper < 0) { nextFirst = -1; } else { nextFirst = 0; } this.registerSuperMethods(superClass, nextFirst, visitTbl); } this.registerMethods(src, firstSuper < 0); }; BindClass.prototype.finish = function () { if (this.ready) return this; this.ready = true; this.superList = (this.superIdList || []).map(function (superId) { return _nbind.getType(superId).finish(); }); var Bound = this.proto; if (this.superList.length) { var Proto = function () { this.constructor = Bound; }; Proto.prototype = this.superList[0].proto.prototype; Bound.prototype = new Proto(); } if (Bound != Module) Bound.prototype.__nbindType = this; this.registerSuperMethods(this, 1, {}); return this; }; BindClass.prototype.upcastStep = function (dst, ptr) { if (dst == this) return ptr; for (var i = 0; i < this.superList.length; ++i) { var superPtr = this.superList[i].upcastStep(dst, _nbind.callUpcast(this.upcastList[i], ptr)); if (superPtr) return superPtr; } return 0; }; BindClass.list = []; return BindClass; }(_nbind.BindType); _nbind.BindClass = BindClass; function popPointer(ptr, type) { return ptr ? new type.proto(_nbind.ptrMarker, type.flags, ptr) : null; } _nbind.popPointer = popPointer; function pushPointer(obj, type, tryValue) { if (!(obj instanceof _nbind.Wrapper)) { if (tryValue) { return _nbind.pushValue(obj); } else throw new Error('Type mismatch'); } var ptr = obj.__nbindPtr; var objType = obj.__nbindType.classType; var classType = type.classType; if (obj instanceof type.proto) { // Fast path, requested type is in object's prototype chain. while (objType != classType) { ptr = _nbind.callUpcast(objType.upcastList[0], ptr); objType = objType.superList[0]; } } else { ptr = objType.upcastStep(classType, ptr); if (!ptr) throw new Error('Type mismatch'); } return ptr; } _nbind.pushPointer = pushPointer; function pushMutablePointer(obj, type) { var ptr = pushPointer(obj, type); if (obj.__nbindFlags & 1 /* isConst */) { throw new Error('Passing a const value as a non-const argument'); } return ptr; } var BindClassPtr = /** @class */function (_super) { __extends(BindClassPtr, _super); function BindClassPtr(spec) { var _this = _super.call(this, spec) || this; _this.classType = spec.paramList[0].classType; _this.proto = _this.classType.proto; var isConst = spec.flags & 1 /* isConst */; var isValue = (_this.flags & 896 /* refMask */) == 256 /* isReference */ && spec.flags & 2 /* isValueObject */; var push = isConst ? pushPointer : pushMutablePointer; var pop = isValue ? _nbind.popValue : popPointer; _this.makeWireWrite = function (expr, policyTbl) { return policyTbl['Nullable'] ? // Handle null pointers. function (arg) { return arg ? push(arg, _this) : 0; } : function (arg) { return push(arg, _this); }; }; _this.wireRead = function (arg) { return pop(arg, _this); }; _this.wireWrite = function (arg) { return push(arg, _this); }; return _this; } return BindClassPtr; }(_nbind.BindType); _nbind.BindClassPtr = BindClassPtr; function popShared(ptr, type) { var shared = HEAPU32[ptr / 4]; var unsafe = HEAPU32[ptr / 4 + 1]; return unsafe ? new type.proto(_nbind.ptrMarker, type.flags, unsafe, shared) : null; } _nbind.popShared = popShared; function pushShared(obj, type) { if (!(obj instanceof type.proto)) throw new Error('Type mismatch'); return obj.__nbindShared; } function pushMutableShared(obj, type) { if (!(obj instanceof type.proto)) throw new Error('Type mismatch'); if (obj.__nbindFlags & 1 /* isConst */) { throw new Error('Passing a const value as a non-const argument'); } return obj.__nbindShared; } var SharedClassPtr = /** @class */function (_super) { __extends(SharedClassPtr, _super); function SharedClassPtr(spec) { var _this = _super.call(this, spec) || this; _this.readResources = [_nbind.resources.pool]; _this.classType = spec.paramList[0].classType; _this.proto = _this.classType.proto; var isConst = spec.flags & 1 /* isConst */; var push = isConst ? pushShared : pushMutableShared; _this.wireRead = function (arg) { return popShared(arg, _this); }; _this.wireWrite = function (arg) { return push(arg, _this); }; return _this; } return SharedClassPtr; }(_nbind.BindType); _nbind.SharedClassPtr = SharedClassPtr; var _ = /** @class */function () { function _() {} _ = __decorate([emscripten_library_decorator_1.prepareNamespace('_nbind')], _); return _; }(); // tslint:disable-line:class-name _nbind._ = _; })(_nbind = exports._nbind || (exports._nbind = {})); }); $__System.registerDynamic("f", ["e", "c", "10"], true, function ($__require, exports, module) { var global = this || self, GLOBAL = global; // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd. // Released under the MIT license, see LICENSE. var __extends = exports && exports.__extends || function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __decorate = exports && exports.__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); // This file handles type conversion of JavaScript callback functions // accessible from C++. See also Caller.ts var emscripten_library_decorator_1 = $__require("e"); var BindingType_1 = $__require("c"); var External_1 = $__require("10"); // Let decorators run eval in current scope to read function source code. emscripten_library_decorator_1.setEvil(function (code) { return eval(code); }); var _nbind; (function (_nbind) { _nbind.BindType = BindingType_1._nbind.BindType; _nbind.External = External_1._nbind.External; })(_nbind = exports._nbind || (exports._nbind = {})); (function (_nbind) { // List of invoker functions for all argument and return value combinations // seen so far. _nbind.callbackSignatureList = []; var CallbackType = /** @class */function (_super) { __extends(CallbackType, _super); function CallbackType() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.wireWrite = function (func) { if (typeof func != 'function') _nbind.throwError('Type mismatch'); return new _nbind.External(func).register(); }; return _this; // Optional type conversion code // makeWireWrite = (expr: string) => '_nbind.registerCallback(' + expr + ')'; } return CallbackType; }(_nbind.BindType); _nbind.CallbackType = CallbackType; var _ = /** @class */function () { function _() {} _ = __decorate([emscripten_library_decorator_1.prepareNamespace('_nbind')], _); return _; }(); // tslint:disable-line:class-name _nbind._ = _; })(_nbind = exports._nbind || (exports._nbind = {})); var nbind = /** @class */function () { function nbind() {} nbind._nbind_register_callback_signature = function (typeListPtr, typeCount) { var typeList = _nbind.readTypeIdList(typeListPtr, typeCount); var num = _nbind.callbackSignatureList.length; _nbind.callbackSignatureList[num] = _nbind.makeJSCaller(typeList); return num; }; __decorate([emscripten_library_decorator_1.dep('_nbind')], nbind, "_nbind_register_callback_signature", null); nbind = __decorate([emscripten_library_decorator_1.exportLibrary], nbind); return nbind; }(); }); $__System.registerDynamic("11", ["e", "c"], true, function ($__require, exports, module) { var global = this || self, GLOBAL = global; // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd. // Released under the MIT license, see LICENSE. var __extends = exports && exports.__extends || function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __decorate = exports && exports.__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); // This file handles value objects, which are represented by equivalent C++ and // JavaScript classes, with toJS and fromJS methods calling each others' // constructors to marshal the class between languages and providing a similar // API in both. var emscripten_library_decorator_1 = $__require("e"); var BindingType_1 = $__require("c"); // Let decorators run eval in current scope to read function source code. emscripten_library_decorator_1.setEvil(function (code) { return eval(code); }); var _defineHidden = emscripten_library_decorator_1.defineHidden; var _nbind; (function (_nbind) { _nbind.BindType = BindingType_1._nbind.BindType; })(_nbind = exports._nbind || (exports._nbind = {})); (function (_nbind) { /** Storage for value objects. Slot 0 is reserved to represent errors. */ _nbind.valueList = [0]; /** Value object storage slot free list head. */ var firstFreeValue = 0; function pushValue(value) { var num = firstFreeValue; if (num) { firstFreeValue = _nbind.valueList[num]; } else num = _nbind.valueList.length; _nbind.valueList[num] = value; return num * 2 + 1; } _nbind.pushValue = pushValue; function popValue(num, type) { if (!num) _nbind.throwError('Value type JavaScript class is missing or not registered'); if (num & 1) { num >>= 1; var obj = _nbind.valueList[num]; _nbind.valueList[num] = firstFreeValue; firstFreeValue = num; return obj; } else if (type) { return _nbind.popShared(num, type); } else throw new Error('Invalid value slot ' + num); } _nbind.popValue = popValue; // 2^64, first integer not representable with uint64_t. // Start of range used for other flags. var valueBase = 18446744073709551616.0; function push64(num) { if (typeof num == 'number') return num; return pushValue(num) * 4096 + valueBase; } function pop64(num) { if (num < valueBase) return num; return popValue((num - valueBase) / 4096); } // Special type that constructs a new object. var CreateValueType = /** @class */function (_super) { __extends(CreateValueType, _super); function CreateValueType() { return _super !== null && _super.apply(this, arguments) || this; } CreateValueType.prototype.makeWireWrite = function (expr) { return '(_nbind.pushValue(new ' + expr + '))'; }; return CreateValueType; }(_nbind.BindType); _nbind.CreateValueType = CreateValueType; var Int64Type = /** @class */function (_super) { __extends(Int64Type, _super); function Int64Type() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.wireWrite = push64; _this.wireRead = pop64; return _this; } return Int64Type; }(_nbind.BindType); _nbind.Int64Type = Int64Type; var _ = /** @class */function () { function _() {} _ = __decorate([emscripten_library_decorator_1.prepareNamespace('_nbind')], _); return _; }(); // tslint:disable-line:class-name _nbind._ = _; })(_nbind = exports._nbind || (exports._nbind = {})); var nbind = /** @class */function () { function nbind() {} // Initialize a C++ object based on a JavaScript object's contents. nbind._nbind_get_value_object = function (num, ptr) { var obj = _nbind.popValue(num); if (!obj.fromJS) { throw new Error('Object ' + obj + ' has no fromJS function'); } obj.fromJS(function () { obj.__nbindValueConstructor.apply(this, Array.prototype.concat.apply([ptr], arguments)); }); }; nbind._nbind_get_int_64 = function (num, ptr) { var obj = _nbind.popValue(num); obj.fromJS(function (lo, hi, sign) { if (sign) { lo = ~lo; hi = ~hi; if (!++lo) ++hi; } ptr >>= 2; if (_nbind.bigEndian) { // Emscripten itself might not work on big endian, // but we support it here anyway. HEAP32[ptr] = hi; HEAP32[ptr + 1] = lo; } else { HEAP32[ptr] = lo; HEAP32[ptr + 1] = hi; } }); }; nbind.nbind_value = function (name, proto) { if (!_nbind.typeNameTbl[name]) _nbind.throwError('Unknown value type ' + name); Module['NBind'].bind_value(name, proto); // Copy value constructor reference from C++ wrapper prototype // to equivalent JS prototype. _defineHidden(_nbind.typeNameTbl[name].proto.prototype.__nbindValueConstructor)(proto.prototype, '__nbindValueConstructor'); }; __decorate([emscripten_library_decorator_1.dep('_nbind')], nbind, "_nbind_get_value_object", null); __decorate([emscripten_library_decorator_1.dep('_nbind')], nbind, "_nbind_get_int_64", null); __decorate([emscripten_library_decorator_1.dep('_nbind')], nbind, "nbind_value", null); nbind = __decorate([emscripten_library_decorator_1.exportLibrary], nbind); return nbind; }(); }); $__System.registerDynamic("12", ["e", "13", "c"], true, function ($__require, exports, module) { var global = this || self, GLOBAL = global; // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd. // Released under the MIT license, see LICENSE. var __extends = exports && exports.__extends || function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __decorate = exports && exports.__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); // This file handles type conversion of C++ standard library types // to / from JavaScript. var emscripten_library_decorator_1 = $__require("e"); var Globals_1 = $__require("13"); var BindingType_1 = $__require("c"); // Let decorators run eval in current scope to read function source code. emscripten_library_decorator_1.setEvil(function (code) { return eval(code); }); var _nbind; (function (_nbind) { _nbind.Pool = Globals_1._nbind.Pool; _nbind.BindType = BindingType_1._nbind.BindType; })(_nbind = exports._nbind || (exports._nbind = {})); (function (_nbind) { function pushArray(arr, type) { if (!arr) return 0; var length = arr.length; if ((type.size || type.size === 0) && length < type.size) { throw new Error('Type mismatch'); } var ptrSize = type.memberType.ptrSize; var result = _nbind.Pool.lalloc(4 + length * ptrSize); HEAPU32[result / 4] = length; var heap = type.memberType.heap; var ptr = (result + 4) / ptrSize; var wireWrite = type.memberType.wireWrite; var num = 0; if (wireWrite) { while (num < length) { heap[ptr++] = wireWrite(arr[num++]); } } else { while (num < length) { heap[ptr++] = arr[num++]; } } return result; } _nbind.pushArray = pushArray; function popArray(ptr, type) { if (ptr === 0) return null; var length = HEAPU32[ptr / 4]; var arr = new Array(length); var heap = type.memberType.heap; ptr = (ptr + 4) / type.memberType.ptrSize; var wireRead = type.memberType.wireRead; var num = 0; if (wireRead) { while (num < length) { arr[num++] = wireRead(heap[ptr++]); } } else { while (num < length) { arr[num++] = heap[ptr++]; } } return arr; } _nbind.popArray = popArray; var ArrayType = /** @class */function (_super) { __extends(ArrayType, _super); function ArrayType(spec) { var _this = _super.call(this, spec) || this; _this.wireRead = function (arg) { return popArray(arg, _this); }; _this.wireWrite = function (arg) { return pushArray(arg, _this); }; // Optional type conversion code /* makeWireRead = (expr: string, convertParamList: any[], num: number) => { convertParamList[num] = this; return('_nbind.popArray(' + expr + ',convertParamList[' + num + '])'); }; makeWireWrite = (expr: string, convertParamList: any[], num: number) => { convertParamList[num] = this; return('_nbind.pushArray(' + expr + ',convertParamList[' + num + '])'); }; */ _this.readResources = [_nbind.resources.pool]; _this.writeResources = [_nbind.resources.pool]; _this.memberType = spec.paramList[0]; if (spec.paramList[1]) _this.size = spec.paramList[1]; return _this; } return ArrayType; }(_nbind.BindType); _nbind.ArrayType = ArrayType; function pushString(str, policyTbl) { if (str === null || str === undefined) { if (policyTbl && policyTbl['Nullable']) { str = ''; } else throw new Error('Type mismatch'); } if (policyTbl && policyTbl['Strict']) { if (typeof str != 'string') throw new Error('Type mismatch'); } else str = str.toString(); var length = Module.lengthBytesUTF8(str); // 32-bit length, string and a zero terminator // (stringToUTF8Array insists on adding it) var result = _nbind.Pool.lalloc(4 + length + 1); HEAPU32[result / 4] = length; Module.stringToUTF8Array(str, HEAPU8, result + 4, length + 1); return result; } _nbind.pushString = pushString; function popString(ptr) { if (ptr === 0) return null; var length = HEAPU32[ptr / 4]; return Module.Pointer_stringify(ptr + 4, length); } _nbind.popString = popString; var StringType = /** @class */function (_super) { __extends(StringType, _super); function StringType() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.wireRead = popString; _this.wireWrite = pushString; _this.readResources = [_nbind.resources.pool]; _this.writeResources = [_nbind.resources.pool]; return _this; } StringType.prototype.makeWireWrite = function (expr, policyTbl) { return function (arg) { return pushString(arg, policyTbl); }; }; return StringType; }(_nbind.BindType); _nbind.StringType = StringType; var _ = /** @class */function () { function _() {} _ = __decorate([emscripten_library_decorator_1.prepareNamespace('_nbind')], _); return _; }(); // tslint:disable-line:class-name _nbind._ = _; })(_nbind = exports._nbind || (exports._nbind = {})); }); $__System.registerDynamic("14", ["e"], true, function ($__require, exports, module) { var global = this || self, GLOBAL = global; // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd. // Released under the MIT license, see LICENSE. var __decorate = exports && exports.__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); // This file handles creating invoker functions for Emscripten dyncalls // wrapped in type conversions for arguments and return values. var emscripten_library_decorator_1 = $__require("e"); // Let decorators run eval in current scope to read function source code. emscripten_library_decorator_1.setEvil(function (code) { return eval(code); }); var _nbind; (function (_nbind) { /** Make a list of argument names a1, a2, a3... * for dynamically generating function source code. */ function makeArgList(argCount) { return Array.apply(null, Array(argCount)).map(function (dummy, num) { return 'a' + (num + 1); }); } /** Check if any type on the list requires conversion writing to C++. * Mainly numbers can be passed as-is between Asm.js and JavaScript. */ function anyNeedsWireWrite(typeList, policyTbl) { return typeList.reduce(function (result, type) { return result || type.needsWireWrite(policyTbl); }, false); } /** Check if any type on the list requires conversion reading from C++. * Mainly numbers can be passed as-is between Asm.js and JavaScript. */ function anyNeedsWireRead(typeList, policyTbl) { return typeList.reduce(function (result, type) { return result || !!type.needsWireRead(policyTbl); }, false); } function makeWireRead(convertParamList, policyTbl, type, expr) { /** Next free slot number in type converter data list. */ var paramNum = convertParamList.length; if (type.makeWireRead) { return type.makeWireRead(expr, convertParamList, paramNum); } else if (type.wireRead) { convertParamList[paramNum] = type.wireRead; return '(convertParamList[' + paramNum + '](' + expr + '))'; } else return expr; } function makeWireWrite(convertParamList, policyTbl, type, expr) { var wireWrite; /** Next free slot number in type converter data list. */ var paramNum = convertParamList.length; if (type.makeWireWrite) { wireWrite = type.makeWireWrite(expr, policyTbl, convertParamList, paramNum); } else wireWrite = type.wireWrite; if (wireWrite) { if (typeof wireWrite == 'string') { return wireWrite; } else { convertParamList[paramNum] = wireWrite; return '(convertParamList[' + paramNum + '](' + expr + '))'; } } else return expr; } /** Dynamically build a function that calls an Asm.js invoker * with appropriate type conversion for complicated types: * - Push arguments to stack. * - Read return value. * - Restore stack pointer if necessary. */ function buildCallerFunction(dynCall, ptrType, ptr, num, policyTbl, needsWireWrite, prefix, returnType, argTypeList, mask, err) { var argList = makeArgList(argTypeList.length); /** List of arbitrary data for type converters. * Each one may read and write its own slot. */ var convertParamList = []; // Build code for function call and type conversion. var callExpression = makeWireRead(convertParamList, policyTbl, returnType, 'dynCall(' + [prefix].concat(argList.map( // TODO: if one wireWrite throws, // resources allocated by others may leak! function (name, index) { return makeWireWrite(convertParamList, policyTbl, argTypeList[index], name); })).join(',') + ')'); // Build code to allocate and free the stack etc. if necessary. var resourceSet = _nbind.listResources([returnType], argTypeList); var sourceCode = 'function(' + argList.join(',') + '){' + (mask ? 'this.__nbindFlags&mask&&err();' : '') + resourceSet.makeOpen() + 'var r=' + callExpression + ';' + resourceSet.makeClose() + 'return r;' + '}'; // Use eval to allow JIT compiling the function. return eval('(' + sourceCode + ')'); } /** Dynamically build a function that calls a JavaScript callback invoker * with appropriate type conversion for complicated types: * - Read arguments from stack. * - Push return value. * - Restore stack pointer if necessary. */ function buildJSCallerFunction(returnType, argTypeList) { var argList = makeArgList(argTypeList.length); /** List of arbitrary data for type converters. * Each one may read and write its own slot. */ var convertParamList = []; var callExpression = makeWireWrite(convertParamList, null, returnType, '_nbind.externalList[num].data(' + argList.map( // TODO: if one wireRead throws, // resources held by others may leak! function (name, index) { return makeWireRead(convertParamList, null, argTypeList[index], name); }).join(',') + ')'); var resourceSet = _nbind.listResources(argTypeList, [returnType]); // Let the calling C++ side handle resetting the pool (using the // PoolRestore class) after parsing the callback return value passed // through the pool. resourceSet.remove(_nbind.resources.pool); var sourceCode = 'function(' + ['dummy', 'num'].concat(argList).join(',') + '){' + resourceSet.makeOpen() + 'var r=' + callExpression + ';' + resourceSet.makeClose() + 'return r;' + '}'; // Use eval to allow JIT compiling the function. return eval('(' + sourceCode + ')'); } _nbind.buildJSCallerFunction = buildJSCallerFunction; /* tslint:disable:indent */ /** Dynamically create an invoker for a JavaScript callback. */ function makeJSCaller(idList) { var argCount = idList.length - 1; var typeList = _nbind.getTypes(idList, 'callback'); var returnType = typeList[0]; var argTypeList = typeList.slice(1); var needsWireRead = anyNeedsWireRead(argTypeList, null); var needsWireWrite = returnType.needsWireWrite(null); if (!needsWireWrite && !needsWireRead) { switch (argCount) { case 0: return function (dummy, num) { return _nbind.externalList[num].data(); }; case 1: return function (dummy, num, a1) { return _nbind.externalList[num].data(a1); }; case 2: return function (dummy, num, a1, a2) { return _nbind.externalList[num].data(a1, a2); }; case 3: return function (dummy, num, a1, a2, a3) { return _nbind.externalList[num].data(a1, a2, a3); }; default: // Function takes over 3 arguments. // Let's create the invoker dynamically then. break; } } return buildJSCallerFunction(returnType, argTypeList); } _nbind.makeJSCaller = makeJSCaller; /** Dynamically create an invoker function for calling a C++ class method. */ function makeMethodCaller(ptrType, spec) { var argCount = spec.typeList.length - 1; // The method invoker function adds two arguments to those of the method: // - Number of the method in a list of methods with identical signatures. // - Target object var typeIdList = spec.typeList.slice(0); typeIdList.splice(1, 0, 'uint32_t', spec.boundID); var typeList = _nbind.getTypes(typeIdList, spec.title); var returnType = typeList[0]; var argTypeList = typeList.slice(3); var needsWireRead = returnType.needsWireRead(spec.policyTbl); var needsWireWrite = anyNeedsWireWrite(argTypeList, spec.policyTbl); var ptr = spec.ptr; var num = spec.num; var dynCall = _nbind.getDynCall(typeList, spec.title); var mask = ~spec.flags & 1 /* isConst */; function err() { throw new Error('Calling a non-const method on a const object'); } if (!needsWireRead && !needsWireWrite) { // If there are only a few arguments not requiring type conversion, // build a simple invoker function without using eval. switch (argCount) { case 0: return function () { return this.__nbindFlags & mask ? err() : dynCall(ptr, num, _nbind.pushPointer(this, ptrType)); }; case 1: return function (a1) { return this.__nbindFlags & mask ? err() : dynCall(ptr, num, _nbind.pushPointer(this, ptrType), a1); }; case 2: return function (a1, a2) { return this.__nbindFlags & mask ? err() : dynCall(ptr, num, _nbind.pushPointer(this, ptrType), a1, a2); }; case 3: return function (a1, a2, a3) { return this.__nbindFlags & mask ? err() : dynCall(ptr, num, _nbind.pushPointer(this, ptrType), a1, a2, a3); }; default: // Function takes over 3 arguments or needs type conversion. // Let's create the invoker dynamically then. break; } } return buildCallerFunction(dynCall, ptrType, ptr, num, spec.policyTbl, needsWireWrite, 'ptr,num,pushPointer(this,ptrType)', returnType, argTypeList, mask, err); } _nbind.makeMethodCaller = makeMethodCaller; /** Dynamically create an invoker function for calling a C++ function. */ function makeCaller(spec) { var argCount = spec.typeList.length - 1; var typeList = _nbind.getTypes(spec.typeList, spec.title); var returnType = typeList[0]; var argTypeList = typeList.slice(1); var needsWireRead = returnType.needsWireRead(spec.policyTbl); var needsWireWrite = anyNeedsWireWrite(argTypeList, spec.policyTbl); var direct = spec.direct; var dynCall; var ptr = spec.ptr; if (spec.direct && !needsWireRead && !needsWireWrite) { // If there are only a few arguments not requiring type conversion, // build a simple invoker function without using eval. dynCall = _nbind.getDynCall(typeList, spec.title); switch (argCount) { case 0: return function () { return dynCall(direct); }; case 1: return function (a1) { return dynCall(direct, a1); }; case 2: return function (a1, a2) { return dynCall(direct, a1, a2); }; case 3: return function (a1, a2, a3) { return dynCall(direct, a1, a2, a3); }; default: // Function takes over 3 arguments. // Let's create the invoker dynamically then. break; } // Input and output types don't need conversion so omit dispatcher. ptr = 0; } var prefix; if (ptr) { // The function invoker adds an argument to those of the function: // - Number of the function in a list of functions with identical signatures. var typeIdList = spec.typeList.slice(0); typeIdList.splice(1, 0, 'uint32_t'); typeList = _nbind.getTypes(typeIdList, spec.title); prefix = 'ptr,num'; } else { ptr = direct; prefix = 'ptr'; } // Type ID list was changed. dynCall = _nbind.getDynCall(typeList, spec.title); return buildCallerFunction(dynCall, null, ptr, spec.num, spec.policyTbl, needs