@ohos-ports/nbind 0.0.0-stage → 0.3.15-beta.1

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.
Files changed (92) hide show
  1. package/.editorconfig +7 -0
  2. package/LICENSE +22 -0
  3. package/README.md +1393 -2
  4. package/autogypi.json +11 -0
  5. package/bin/ci-trigger +40 -0
  6. package/bin/copyasm.js +77 -0
  7. package/bin/emcc +21 -0
  8. package/bin/emcc-path.js +7 -0
  9. package/bin/ndts.js +22 -0
  10. package/config.js +7 -0
  11. package/dist/Type.d.ts +92 -0
  12. package/dist/Type.js +180 -0
  13. package/dist/common.d.ts +9 -0
  14. package/dist/common.js +10 -0
  15. package/dist/em-api.js +2353 -0
  16. package/dist/int64.d.ts +9 -0
  17. package/dist/int64.js +64 -0
  18. package/dist/nbind.d.ts +49 -0
  19. package/dist/nbind.js +154 -0
  20. package/dist/reflect.d.ts +69 -0
  21. package/dist/reflect.js +261 -0
  22. package/dist/shim.d.ts +1 -0
  23. package/dist/shim.js +2 -0
  24. package/dist/todts.d.ts +5 -0
  25. package/dist/todts.js +146 -0
  26. package/include/nbind/ArgStorage.h +67 -0
  27. package/include/nbind/BindClass.h +290 -0
  28. package/include/nbind/BindDefiner.h +295 -0
  29. package/include/nbind/Buffer.h +50 -0
  30. package/include/nbind/FunctionDefiner.h +51 -0
  31. package/include/nbind/MethodDef.h +50 -0
  32. package/include/nbind/Policy.h +255 -0
  33. package/include/nbind/TypeID.h +84 -0
  34. package/include/nbind/TypeStd.h +66 -0
  35. package/include/nbind/TypeTransformer.h +38 -0
  36. package/include/nbind/api.h +100 -0
  37. package/include/nbind/common.h +22 -0
  38. package/include/nbind/em/ArgFromWire.h +31 -0
  39. package/include/nbind/em/BindingStd.h +221 -0
  40. package/include/nbind/em/BindingType.h +204 -0
  41. package/include/nbind/em/Buffer.h +37 -0
  42. package/include/nbind/em/Callback.h +186 -0
  43. package/include/nbind/em/Caller.h +61 -0
  44. package/include/nbind/em/Creator.h +30 -0
  45. package/include/nbind/em/External.h +63 -0
  46. package/include/nbind/em/Int64.h +131 -0
  47. package/include/nbind/em/NBind.h +63 -0
  48. package/include/nbind/em/Pool.h +34 -0
  49. package/include/nbind/em/StdFunction.h +40 -0
  50. package/include/nbind/em/ValueObj.h +54 -0
  51. package/include/nbind/nbind.h +19 -0
  52. package/include/nbind/noconflict.h +91 -0
  53. package/include/nbind/signature/BaseSignature.h +238 -0
  54. package/include/nbind/signature/CallbackSignature.h +59 -0
  55. package/include/nbind/signature/ConstructorSignature.h +76 -0
  56. package/include/nbind/signature/FunctionSignature.h +63 -0
  57. package/include/nbind/signature/GetterSignature.h +62 -0
  58. package/include/nbind/signature/MethodSignature.h +61 -0
  59. package/include/nbind/signature/SetterSignature.h +63 -0
  60. package/include/nbind/signature/SignatureParam.h +39 -0
  61. package/include/nbind/v8/ArgFromWire.h +69 -0
  62. package/include/nbind/v8/BindWrapper.h +295 -0
  63. package/include/nbind/v8/BindingStd.h +180 -0
  64. package/include/nbind/v8/BindingType.h +241 -0
  65. package/include/nbind/v8/Buffer.h +59 -0
  66. package/include/nbind/v8/Callback.h +165 -0
  67. package/include/nbind/v8/Caller.h +140 -0
  68. package/include/nbind/v8/Convert.h +80 -0
  69. package/include/nbind/v8/Creator.h +26 -0
  70. package/include/nbind/v8/External.h +119 -0
  71. package/include/nbind/v8/Int64.h +195 -0
  72. package/include/nbind/v8/NBind.h +63 -0
  73. package/include/nbind/v8/Output.h +36 -0
  74. package/include/nbind/v8/Overloader.h +215 -0
  75. package/include/nbind/v8/StdFunction.h +44 -0
  76. package/include/nbind/v8/ValueObj.h +137 -0
  77. package/include/nbind/wire.h +79 -0
  78. package/package.json +69 -4
  79. package/src/checkver.js +31 -0
  80. package/src/common.cc +129 -0
  81. package/src/em/Binding.cc +313 -0
  82. package/src/em/tsconfig.json +22 -0
  83. package/src/nbind-common.gypi +14 -0
  84. package/src/nbind.gypi +98 -0
  85. package/src/post.js +2 -0
  86. package/src/pre.js +48 -0
  87. package/src/reflect.cc +170 -0
  88. package/src/symbols.txt +1 -0
  89. package/src/tsconfig.json +23 -0
  90. package/src/tslint.json +86 -0
  91. package/src/v8/Binding.cc +391 -0
  92. package/src/v8/Buffer.cc +73 -0
@@ -0,0 +1,9 @@
1
+ /** Simple bignum style class for formatting 64-bit integers. */
2
+ export declare class Int64 {
3
+ constructor(lo: number, hi: number, sign: boolean);
4
+ fromJS(output: (lo: number, hi: number, sign: boolean) => void): void;
5
+ toString(base: number): string;
6
+ lo: number;
7
+ hi: number;
8
+ sign: boolean;
9
+ }
package/dist/int64.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
3
+ // Released under the MIT license, see LICENSE.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ function zeroes(count) {
6
+ return (new Array(count + 1).join('0'));
7
+ }
8
+ var padTbl = {
9
+ 2: zeroes(32),
10
+ 4: zeroes(16),
11
+ 10: zeroes(9),
12
+ 16: zeroes(8)
13
+ };
14
+ /** Simple bignum style class for formatting 64-bit integers. */
15
+ var Int64 = (function () {
16
+ function Int64(lo, hi, sign) {
17
+ this.lo = lo >>> 0;
18
+ this.hi = hi >>> 0;
19
+ this.sign = sign;
20
+ }
21
+ Int64.prototype.fromJS = function (output) {
22
+ output(this.lo, this.hi, this.sign);
23
+ };
24
+ Int64.prototype.toString = function (base) {
25
+ var prefix = this.sign ? '-' : '';
26
+ var hi = this.hi;
27
+ var lo = this.lo;
28
+ if (!base)
29
+ base = 10;
30
+ if (!hi)
31
+ return (prefix + lo.toString(base));
32
+ var pad = padTbl[base];
33
+ var part;
34
+ if (base != 10) {
35
+ if (!pad)
36
+ throw (new Error('Unsupported base ' + base));
37
+ part = lo.toString(base);
38
+ return (prefix + hi.toString(base) + pad.substr(part.length) + part);
39
+ }
40
+ var groupSize = 1000000000;
41
+ var result = '';
42
+ var carry;
43
+ function step(limb) {
44
+ carry = carry * 0x10000 + (limb >>> 16);
45
+ var hi16 = (carry / groupSize) >>> 0;
46
+ carry = carry - hi16 * groupSize;
47
+ carry = carry * 0x10000 + (limb & 0xffff);
48
+ var lo16 = (carry / groupSize) >>> 0;
49
+ carry = carry - lo16 * groupSize;
50
+ return (((hi16 << 16) | lo16) >>> 0);
51
+ }
52
+ while (hi || lo >= groupSize) {
53
+ carry = 0;
54
+ hi = step(hi);
55
+ lo = step(lo);
56
+ part = '' + carry;
57
+ result = pad.substr(part.length) + part + result;
58
+ }
59
+ result = prefix + lo + result;
60
+ return (result);
61
+ };
62
+ return Int64;
63
+ }());
64
+ exports.Int64 = Int64;
@@ -0,0 +1,49 @@
1
+ import { SignatureType } from './common';
2
+ /** Compiled C++ binary type and path. */
3
+ export interface FindModuleSpec {
4
+ type: 'node' | 'emcc';
5
+ ext: string;
6
+ name: string;
7
+ path?: string;
8
+ }
9
+ export interface ModuleSpec extends FindModuleSpec {
10
+ path: string;
11
+ }
12
+ /** Any class constructor. */
13
+ export declare type ClassType = {
14
+ new (...args: any[]): any;
15
+ };
16
+ export interface DefaultExportType {
17
+ [key: string]: any;
18
+ locateFile?(name: string): string;
19
+ onRuntimeInitialized?(): void;
20
+ ccall?(name: string, returnType?: string, argTypes?: string[], args?: any[]): any;
21
+ _nbind_value?(name: string, proto: ClassType): void;
22
+ NBind?: {
23
+ bind_value(name: string, proto: ClassType): void;
24
+ };
25
+ }
26
+ export declare class Binding<ExportType extends DefaultExportType> {
27
+ [key: string]: any;
28
+ queryType?<Result>(id: number, outTypeDetail: (kind: number, ...args: any[]) => Result): Result;
29
+ /** Bind a value type (class with a fromJS method) to an equivalent C++ type. */
30
+ bind: (name: string, proto: ClassType) => void;
31
+ reflect: (outPrimitive: (id: number, size: number, flag: number) => void, outType: (id: number, name: string) => void, outClass: (id: number, name: string) => void, outSuper: (classId: number, superIdList: number[]) => void, outMethod: (classId: number, name: string, kind: SignatureType, argTypeList: number[], policyList: string[]) => void) => void;
32
+ toggleLightGC: (enable: boolean) => void;
33
+ binary: ModuleSpec;
34
+ /** Exported API of a C++ library compiled for nbind. */
35
+ lib: ExportType;
36
+ }
37
+ export declare type FindCallback = (err: any, result?: ModuleSpec) => any;
38
+ /** Find compiled C++ binary under current working directory. */
39
+ export declare function find(cb?: FindCallback): ModuleSpec;
40
+ /** Find compiled C++ binary under given path. */
41
+ export declare function find(basePath: string, cb?: FindCallback): ModuleSpec;
42
+ export declare type InitCallback<ExportType extends DefaultExportType> = (err: any, result?: Binding<ExportType>) => any;
43
+ /** Initialize compiled C++ binary under current working directory. */
44
+ export declare function init<ExportType extends DefaultExportType>(cb?: InitCallback<ExportType>): Binding<ExportType>;
45
+ /** Initialize compiled C++ binary under given path. */
46
+ export declare function init<ExportType extends DefaultExportType>(basePath: string, cb?: InitCallback<ExportType>): Binding<ExportType>;
47
+ /** Initialize compiled C++ binary under given path and merge its API to given
48
+ * object, which may contain options for Emscripten modules. */
49
+ export declare function init<ExportType extends DefaultExportType>(basePath: string, lib: ExportType, cb?: InitCallback<ExportType>): Binding<ExportType>;
package/dist/nbind.js ADDED
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
3
+ // Released under the MIT license, see LICENSE.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ var path = require('path'); // tslint:disable-line:no-var-requires
6
+ var Binding = (function () {
7
+ function Binding() {
8
+ }
9
+ return Binding;
10
+ }());
11
+ exports.Binding = Binding;
12
+ /** Default callback that throws any error given to it. */
13
+ function rethrow(err, result) {
14
+ if (err)
15
+ throw (err);
16
+ }
17
+ /** Make list of possible paths for a single compiled output file name. */
18
+ function makeModulePathList(root, name) {
19
+ return ([
20
+ // Binary copied using copyasm
21
+ [root, name],
22
+ // node-gyp's linked version in the "build" dir
23
+ [root, 'build', name],
24
+ // node-waf and gyp_addon (a.k.a node-gyp)
25
+ [root, 'build', 'Debug', name],
26
+ [root, 'build', 'Release', name],
27
+ // Debug files, for development (legacy behavior, remove for node v0.9)
28
+ [root, 'out', 'Debug', name],
29
+ [root, 'Debug', name],
30
+ // Release files, but manually compiled (legacy behavior, remove for node v0.9)
31
+ [root, 'out', 'Release', name],
32
+ [root, 'Release', name],
33
+ // Legacy from node-waf, node <= 0.4.x
34
+ [root, 'build', 'default', name],
35
+ [
36
+ root,
37
+ process.env['NODE_BINDINGS_COMPILED_DIR'] || 'compiled',
38
+ process.versions.node,
39
+ process.platform,
40
+ process.arch,
41
+ name
42
+ ]
43
+ ]);
44
+ }
45
+ function findCompiledModule(basePath, specList, callback) {
46
+ var resolvedList = [];
47
+ var ext = path.extname(basePath);
48
+ /** If basePath has a known extension, check if it's a loadable module. */
49
+ for (var _i = 0, specList_1 = specList; _i < specList_1.length; _i++) {
50
+ var spec = specList_1[_i];
51
+ if (ext == spec.ext) {
52
+ try {
53
+ spec.path = require.resolve(basePath);
54
+ // Stop if a module was found.
55
+ callback(null, spec);
56
+ return (spec);
57
+ }
58
+ catch (err) {
59
+ resolvedList.push(basePath);
60
+ }
61
+ }
62
+ }
63
+ /** Try all possible subdirectories of basePath. */
64
+ for (var _a = 0, specList_2 = specList; _a < specList_2.length; _a++) {
65
+ var spec = specList_2[_a];
66
+ // Check if any possible path contains a loadable module,
67
+ // and store unsuccessful attempts.
68
+ for (var _b = 0, _c = makeModulePathList(basePath, spec.name); _b < _c.length; _b++) {
69
+ var pathParts = _c[_b];
70
+ var resolvedPath = path.resolve.apply(path, pathParts);
71
+ try {
72
+ spec.path = require.resolve(resolvedPath);
73
+ }
74
+ catch (err) {
75
+ resolvedList.push(resolvedPath);
76
+ continue;
77
+ }
78
+ // Stop if a module was found.
79
+ callback(null, spec);
80
+ return (spec);
81
+ }
82
+ }
83
+ var err = new Error('Could not locate the bindings file. Tried:\n' +
84
+ resolvedList.join('\n'));
85
+ err.tries = resolvedList;
86
+ callback(err);
87
+ return (null);
88
+ }
89
+ function find(basePath, cb) {
90
+ var callback = arguments[arguments.length - 1];
91
+ if (typeof (callback) != 'function')
92
+ callback = rethrow;
93
+ return (findCompiledModule((basePath != callback && basePath) || process.cwd(), [
94
+ { ext: '.node', name: 'nbind.node', type: 'node' },
95
+ { ext: '.js', name: 'nbind.js', type: 'emcc' }
96
+ ], callback));
97
+ }
98
+ exports.find = find;
99
+ function init(basePath, lib, cb) {
100
+ var callback = arguments[arguments.length - 1];
101
+ if (typeof (callback) != 'function')
102
+ callback = rethrow;
103
+ var binding = new Binding();
104
+ find(basePath != callback && basePath, function (err, binary) {
105
+ if (err) {
106
+ callback(err);
107
+ return;
108
+ }
109
+ binding.binary = binary;
110
+ binding.lib = (lib != callback && lib) || {};
111
+ if (binary.type == 'emcc') {
112
+ initAsm(binding, callback);
113
+ }
114
+ else {
115
+ initNode(binding, callback);
116
+ }
117
+ });
118
+ return (binding);
119
+ }
120
+ exports.init = init;
121
+ /** Initialize asm.js module. */
122
+ function initAsm(binding, callback) {
123
+ var lib = binding.lib;
124
+ lib.locateFile = lib.locateFile || function (name) {
125
+ return (path.resolve(path.dirname(binding.binary.path), name));
126
+ };
127
+ // Load the Asm.js module.
128
+ require(binding.binary.path)(lib, function (err, parts) {
129
+ if (!err) {
130
+ for (var _i = 0, _a = Object.keys(parts); _i < _a.length; _i++) {
131
+ var key = _a[_i];
132
+ binding[key] = parts[key];
133
+ }
134
+ }
135
+ callback(err, binding);
136
+ });
137
+ }
138
+ /** Initialize native Node.js addon. */
139
+ function initNode(binding, callback) {
140
+ // Load the compiled addon.
141
+ var lib = require(binding.binary.path);
142
+ if (!lib || typeof (lib) != 'object') {
143
+ callback(new Error('Error loading addon'));
144
+ return;
145
+ }
146
+ binding.bind = lib.NBind.bind_value;
147
+ binding.reflect = lib.NBind.reflect;
148
+ binding.queryType = lib.NBind.queryType;
149
+ binding.toggleLightGC = function (enable) { }; // tslint:disable-line:no-empty
150
+ Object.keys(lib).forEach(function (key) {
151
+ binding.lib[key] = lib[key];
152
+ });
153
+ callback(null, binding);
154
+ }
@@ -0,0 +1,69 @@
1
+ import { Binding } from './nbind';
2
+ import { SignatureType } from './common';
3
+ import { TypeSpec, TypeClass } from './Type';
4
+ export declare type TypeBase = TypeClass;
5
+ export declare const TypeBase: new (spec: TypeSpec) => TypeClass;
6
+ export declare class BindType extends TypeBase {
7
+ constructor(spec: TypeSpec);
8
+ isClass: boolean;
9
+ }
10
+ export declare class BindClass extends BindType {
11
+ addSuper(superClass: BindClass): void;
12
+ addMethod(name: string, kind: SignatureType, typeList: BindType[], policyList: string[]): void;
13
+ addProperty(name: string, kind: SignatureType, typeList: BindType[], policyList: string[]): void;
14
+ name: string;
15
+ superList: BindClass[];
16
+ methodTbl: {
17
+ [name: string]: BindMethod;
18
+ };
19
+ methodList: BindMethod[];
20
+ propertyTbl: {
21
+ [name: string]: BindProperty;
22
+ };
23
+ propertyList: BindProperty[];
24
+ }
25
+ export declare class BindMethod {
26
+ constructor(bindClass: BindClass, name: string, returnType: BindType, argTypeList: BindType[], policyList: string[], isStatic: boolean);
27
+ toString(): string;
28
+ bindClass: BindClass;
29
+ name: string;
30
+ returnType: BindType;
31
+ argTypeList: BindType[];
32
+ policyList: string[];
33
+ isStatic: boolean;
34
+ }
35
+ export declare class BindProperty {
36
+ constructor(bindClass: BindClass, name: string);
37
+ makeReadable(bindType: BindType): void;
38
+ makeWritable(bindType: BindType): void;
39
+ toString(): string;
40
+ bindClass: BindClass;
41
+ name: string;
42
+ bindType: BindType;
43
+ isReadable: boolean;
44
+ isWritable: boolean;
45
+ }
46
+ export declare class Reflect {
47
+ constructor(binding: Binding<any>);
48
+ private readPrimitive(id, size, flags);
49
+ private readType(id, name);
50
+ private readClass(id, name);
51
+ private readSuper(classId, superIdList);
52
+ private readMethod(classId, name, kind, typeIdList, policyList);
53
+ private getType(id);
54
+ private queryType(id);
55
+ dumpPseudo(): string;
56
+ private constructType;
57
+ skipNameTbl: {
58
+ [key: string]: boolean;
59
+ };
60
+ binding: Binding<any>;
61
+ typeIdTbl: {
62
+ [id: number]: BindType;
63
+ };
64
+ typeNameTbl: {
65
+ [name: string]: BindType;
66
+ };
67
+ globalScope: BindClass;
68
+ classList: BindClass[];
69
+ }
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
3
+ // Released under the MIT license, see LICENSE.
4
+ var __extends = (this && this.__extends) || (function () {
5
+ var extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ var common_1 = require("./common");
16
+ var Type_1 = require("./Type");
17
+ var _a = Type_1.typeModule(Type_1.typeModule), Type = _a.Type, makeType = _a.makeType, getComplexType = _a.getComplexType;
18
+ exports.TypeBase = Type;
19
+ var NBindID = (function () {
20
+ function NBindID(id) {
21
+ this.id = id;
22
+ }
23
+ NBindID.prototype.fromJS = function (output) {
24
+ output(this.id);
25
+ };
26
+ NBindID.prototype.toString = function () {
27
+ return ('' + this.id);
28
+ };
29
+ return NBindID;
30
+ }());
31
+ var BindType = (function (_super) {
32
+ __extends(BindType, _super);
33
+ function BindType(spec) {
34
+ var _this = _super.call(this, spec) || this;
35
+ _this.isClass = (spec.flags & 15360 /* kindMask */) == 2048 /* isClass */;
36
+ return _this;
37
+ }
38
+ return BindType;
39
+ }(exports.TypeBase));
40
+ exports.BindType = BindType;
41
+ var BindClass = (function (_super) {
42
+ __extends(BindClass, _super);
43
+ function BindClass() {
44
+ var _this = _super !== null && _super.apply(this, arguments) || this;
45
+ _this.superList = [];
46
+ _this.methodTbl = {};
47
+ _this.methodList = [];
48
+ _this.propertyTbl = {};
49
+ _this.propertyList = [];
50
+ return _this;
51
+ }
52
+ BindClass.prototype.addSuper = function (superClass) {
53
+ this.superList.push(superClass);
54
+ };
55
+ BindClass.prototype.addMethod = function (name, kind, typeList, policyList) {
56
+ var bindMethod = new BindMethod(this, name, typeList[0], typeList.slice(1), policyList, kind == 1 /* func */);
57
+ this.methodTbl[name] = bindMethod;
58
+ this.methodList.push(bindMethod);
59
+ };
60
+ BindClass.prototype.addProperty = function (name, kind, typeList, policyList) {
61
+ name = common_1.removeAccessorPrefix(name);
62
+ var bindProperty = this.propertyTbl[name];
63
+ if (!bindProperty) {
64
+ bindProperty = new BindProperty(this, name);
65
+ this.propertyTbl[name] = bindProperty;
66
+ this.propertyList.push(bindProperty);
67
+ }
68
+ if (kind == 3 /* getter */) {
69
+ // Property type is getter's return type.
70
+ bindProperty.makeReadable(typeList[0]);
71
+ }
72
+ else {
73
+ // Property type is type of setter's first argument.
74
+ bindProperty.makeWritable(typeList[1]);
75
+ }
76
+ };
77
+ return BindClass;
78
+ }(BindType));
79
+ exports.BindClass = BindClass;
80
+ var BindMethod = (function () {
81
+ function BindMethod(bindClass, name, returnType, argTypeList, policyList, isStatic) {
82
+ this.bindClass = bindClass;
83
+ this.name = name;
84
+ this.returnType = returnType;
85
+ this.argTypeList = argTypeList;
86
+ this.policyList = policyList;
87
+ this.isStatic = isStatic;
88
+ }
89
+ BindMethod.prototype.toString = function () {
90
+ return ((this.name ?
91
+ this.returnType + ' ' + this.name :
92
+ this.bindClass.name) +
93
+ '(' + this.argTypeList.join(', ') + ')');
94
+ };
95
+ return BindMethod;
96
+ }());
97
+ exports.BindMethod = BindMethod;
98
+ var BindProperty = (function () {
99
+ function BindProperty(bindClass, name) {
100
+ this.isReadable = false;
101
+ this.isWritable = false;
102
+ this.bindClass = bindClass;
103
+ this.name = name;
104
+ }
105
+ BindProperty.prototype.makeReadable = function (bindType) {
106
+ this.bindType = bindType;
107
+ this.isReadable = true;
108
+ };
109
+ BindProperty.prototype.makeWritable = function (bindType) {
110
+ this.bindType = bindType;
111
+ this.isWritable = true;
112
+ };
113
+ BindProperty.prototype.toString = function () {
114
+ return (this.bindType + ' ' + this.name);
115
+ };
116
+ return BindProperty;
117
+ }());
118
+ exports.BindProperty = BindProperty;
119
+ /** Type-safe Function.bind, name inspired by Dojo. */
120
+ function hitch(obj, method) {
121
+ return method.bind(obj);
122
+ }
123
+ var Reflect = (function () {
124
+ function Reflect(binding) {
125
+ var _this = this;
126
+ this.constructType = (function (kind, spec) {
127
+ var construct = (kind == 2048 /* isClass */) ? BindClass : BindType;
128
+ var bindType = new construct(spec);
129
+ _this.typeNameTbl[spec.name] = bindType;
130
+ _this.typeIdTbl[spec.id] = bindType;
131
+ return (bindType);
132
+ }).bind(this);
133
+ this.skipNameTbl = {
134
+ 'Int64': true,
135
+ 'NBind': true,
136
+ 'NBindID': true
137
+ };
138
+ this.typeIdTbl = {};
139
+ this.typeNameTbl = {};
140
+ this.classList = [];
141
+ this.binding = binding;
142
+ // Bind value type on Emscripten target
143
+ // (equivalent Node.js type has no toJS method).
144
+ binding.bind('NBindID', NBindID);
145
+ binding.reflect(hitch(this, this.readPrimitive), hitch(this, this.readType), hitch(this, this.readClass), hitch(this, this.readSuper), hitch(this, this.readMethod));
146
+ function compareName(_a, _b) {
147
+ var a = _a.name;
148
+ var b = _b.name;
149
+ return (~~(a > b) - ~~(a < b));
150
+ }
151
+ this.classList.sort(compareName);
152
+ if (this.globalScope)
153
+ this.globalScope.methodList.sort(compareName);
154
+ }
155
+ Reflect.prototype.readPrimitive = function (id, size, flags) {
156
+ makeType(this.constructType, {
157
+ flags: 1024 /* isArithmetic */ | flags,
158
+ id: id,
159
+ ptrSize: size
160
+ });
161
+ };
162
+ Reflect.prototype.readType = function (id, name) {
163
+ makeType(this.constructType, {
164
+ flags: 10240 /* isOther */,
165
+ id: id,
166
+ name: name
167
+ });
168
+ };
169
+ Reflect.prototype.readClass = function (id, name) {
170
+ var bindClass = makeType(this.constructType, {
171
+ flags: 2048 /* isClass */,
172
+ id: id,
173
+ name: name
174
+ });
175
+ if (!this.skipNameTbl[bindClass.name])
176
+ this.classList.push(bindClass);
177
+ };
178
+ Reflect.prototype.readSuper = function (classId, superIdList) {
179
+ var bindClass = this.getType(classId);
180
+ for (var _i = 0, superIdList_1 = superIdList; _i < superIdList_1.length; _i++) {
181
+ var superId = superIdList_1[_i];
182
+ bindClass.addSuper(this.getType(superId));
183
+ }
184
+ };
185
+ Reflect.prototype.readMethod = function (classId, name, kind, typeIdList, policyList) {
186
+ var _this = this;
187
+ var bindClass = this.getType(classId);
188
+ if (!bindClass) {
189
+ if (!this.globalScope) {
190
+ bindClass = this.constructType(2048 /* isClass */, { flags: 0 /* none */, id: classId, name: 'global' });
191
+ this.globalScope = bindClass;
192
+ }
193
+ else {
194
+ throw (new Error('Unknown class ID ' + classId + ' for method ' + name));
195
+ }
196
+ }
197
+ var typeList = typeIdList.map(function (id) { return getComplexType(id, _this.constructType, hitch(_this, _this.getType), hitch(_this, _this.queryType), 'reflect ' + bindClass.name + '.' + name); });
198
+ switch (kind) {
199
+ case 5 /* construct */:
200
+ case 1 /* func */:
201
+ case 2 /* method */:
202
+ bindClass.addMethod(name, kind, typeList, policyList);
203
+ break;
204
+ case 3 /* getter */:
205
+ case 4 /* setter */:
206
+ bindClass.addProperty(name, kind, typeList, policyList);
207
+ break;
208
+ default:
209
+ break;
210
+ }
211
+ };
212
+ Reflect.prototype.getType = function (id) { return (this.typeIdTbl[id]); };
213
+ Reflect.prototype.queryType = function (id) {
214
+ return (this.binding.queryType(id, function (kind, target, param) { return ({
215
+ paramList: [target, param],
216
+ placeholderFlag: kind
217
+ }); }));
218
+ };
219
+ Reflect.prototype.dumpPseudo = function () {
220
+ var classCodeList = [];
221
+ var indent;
222
+ var staticPrefix;
223
+ for (var _i = 0, _a = this.classList.concat([this.globalScope]); _i < _a.length; _i++) {
224
+ var bindClass = _a[_i];
225
+ if (bindClass.isClass) {
226
+ indent = '\t';
227
+ staticPrefix = 'static ';
228
+ }
229
+ else {
230
+ indent = '';
231
+ staticPrefix = '';
232
+ }
233
+ var methodBlock = bindClass.methodList.map(function (method) { return (indent +
234
+ (method.name && method.isStatic ? staticPrefix : '') +
235
+ method + ';' +
236
+ (method.policyList.length ?
237
+ ' // ' + method.policyList.join(', ') :
238
+ '')); }).join('\n');
239
+ var propertyBlock = bindClass.propertyList.map(function (property) { return (indent + property + ';' +
240
+ (!(property.isReadable && property.isWritable) ?
241
+ ' // ' + (property.isReadable ? 'Read-only' : 'Write-only') :
242
+ '')); }).join('\n');
243
+ var classCode = (methodBlock +
244
+ (methodBlock && propertyBlock ? '\n\n' : '') +
245
+ propertyBlock);
246
+ var inheritCode = '';
247
+ if (bindClass.superList.length) {
248
+ inheritCode = ' : ' + bindClass.superList.map(function (superClass) { return 'public ' + superClass.name; }).join(', ');
249
+ }
250
+ if (indent) {
251
+ classCode = ('class ' + bindClass.name + inheritCode + ' {' +
252
+ (classCode ? '\n' + classCode + '\n' : '') +
253
+ '};');
254
+ }
255
+ classCodeList.push(classCode);
256
+ }
257
+ return (classCodeList.join('\n\n') + '\n');
258
+ };
259
+ return Reflect;
260
+ }());
261
+ exports.Reflect = Reflect;
package/dist/shim.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare type Buffer = Uint8Array;
package/dist/shim.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { Reflect } from './reflect';
2
+ export declare function dump(options: {
3
+ reflect: Reflect;
4
+ shim?: boolean;
5
+ }): string;