Commit bc67c2749ae9d68f54ef3d51c504dd4722172ec7
small clean up
wanderer committed on 2/22/2018, 7:15:50 PMParent: 225da49428f17d7ef0fc980e3dbd3cda8967ae99
Files changed
wasmContainer.js | changed |
wasmContainer.js | ||
---|---|---|
@@ -31,11 +31,8 @@ | ||
31 | 31 | 0x40: 'block_type' |
32 | 32 | } |
33 | 33 | |
34 | 34 | class ElementBuffer { |
35 | - static get type () { | |
36 | - return 'elem' | |
37 | - } | |
38 | 35 | constructor (array) { |
39 | 36 | this._array = array |
40 | 37 | } |
41 | 38 | |
@@ -47,11 +44,8 @@ | ||
47 | 44 | static deserialize (serialized) {} |
48 | 45 | } |
49 | 46 | |
50 | 47 | class DataBuffer { |
51 | - static get type () { | |
52 | - return 'data' | |
53 | - } | |
54 | 48 | constructor (memory, offset, length) { |
55 | 49 | this._data = new Uint8Array(this.instance.exports.memory.buffer, offset, length) |
56 | 50 | } |
57 | 51 | serialize () { |
@@ -60,37 +54,30 @@ | ||
60 | 54 | static deserialize (serialized) {} |
61 | 55 | } |
62 | 56 | |
63 | 57 | class LinkRef { |
64 | - static get type () { | |
65 | - return 'link' | |
66 | - } | |
67 | 58 | serialize () { |
68 | 59 | return Buffer.concat(Buffer.from([LANGUAGE_TYPES['link'], this])) |
69 | 60 | } |
70 | 61 | static deserialize (serialized) {} |
71 | 62 | } |
72 | 63 | |
73 | 64 | class FunctionRef { |
74 | - static get type () { | |
75 | - return 'func' | |
76 | - } | |
77 | - | |
78 | - constructor (type, identifier, json, id) { | |
79 | - this.type = type | |
65 | + constructor (location, identifier, json, id) { | |
66 | + this.location = location | |
80 | 67 | this.destId = id |
81 | 68 | let funcIndex |
82 | - if (type === 'export') { | |
69 | + if (location === 'export') { | |
83 | 70 | this.indentifier = identifier |
84 | 71 | funcIndex = json.exports[identifier] |
85 | 72 | } else { |
86 | 73 | this.indentifier = identifier.tableIndex |
87 | 74 | funcIndex = Number(identifier.name) - 1 |
88 | 75 | } |
89 | 76 | const typeIndex = json.indexes[funcIndex] |
90 | - const funcType = json.types[typeIndex] | |
77 | + this.type = json.types[typeIndex] | |
91 | 78 | |
92 | - const wrapper = typeCheckWrapper(funcType) | |
79 | + const wrapper = typeCheckWrapper(this.type) | |
93 | 80 | const wasm = json2wasm(wrapper) |
94 | 81 | const mod = WebAssembly.Module(wasm) |
95 | 82 | const self = this |
96 | 83 | this.wrapper = WebAssembly.Instance(mod, { |
@@ -121,12 +108,8 @@ | ||
121 | 108 | } |
122 | 109 | } |
123 | 110 | |
124 | 111 | class ModuleRef { |
125 | - static get type () { | |
126 | - return 'mod' | |
127 | - } | |
128 | - | |
129 | 112 | constructor (json, id) { |
130 | 113 | this._json = json |
131 | 114 | this.id = id |
132 | 115 | } |
@@ -148,11 +131,11 @@ | ||
148 | 131 | this.refs = new ReferanceMap() |
149 | 132 | } |
150 | 133 | |
151 | 134 | static async onCreation (wasm, id, cachedb) { |
152 | - // if (!WebAssembly.validate(wasm)) { | |
153 | - // throw new Error('invalid wasm binary') | |
154 | - // } | |
135 | + if (!WebAssembly.validate(wasm)) { | |
136 | + throw new Error('invalid wasm binary') | |
137 | + } | |
155 | 138 | let moduleJSON = wasm2json(wasm) |
156 | 139 | const json = customTypes.mergeTypeSections(moduleJSON) |
157 | 140 | moduleJSON = wasmMetering.meterJSON(moduleJSON, { |
158 | 141 | meterType: 'i32' |
@@ -280,16 +263,17 @@ | ||
280 | 263 | func.tableIndex = length |
281 | 264 | } |
282 | 265 | } |
283 | 266 | } |
284 | - const args = message.funcArguments.map(arg => { | |
285 | - if (typeof arg === 'number') { | |
267 | + const args = message.funcArguments.map((arg, index) => { | |
268 | + const type = funcRef.type.params[index] | |
269 | + if (nativeTypes.has(type)) { | |
286 | 270 | return arg |
287 | 271 | } else { |
288 | - return this.refs.add(arg, arg.constructor.type) | |
272 | + return this.refs.add(arg, type) | |
289 | 273 | } |
290 | 274 | }) |
291 | - if (funcRef.type === 'export') { | |
275 | + if (funcRef.location === 'export') { | |
292 | 276 | this.instance.exports[funcRef.indentifier](...args) |
293 | 277 | } else { |
294 | 278 | this.instance.exports.table.get(funcRef.indentifier)(...args) |
295 | 279 | } |
Built with git-ssb-web