git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit bc67c2749ae9d68f54ef3d51c504dd4722172ec7

small clean up

wanderer committed on 2/22/2018, 7:15:50 PM
Parent: 225da49428f17d7ef0fc980e3dbd3cda8967ae99

Files changed

wasmContainer.jschanged
wasmContainer.jsView
@@ -31,11 +31,8 @@
3131 0x40: 'block_type'
3232 }
3333
3434 class ElementBuffer {
35- static get type () {
36- return 'elem'
37- }
3835 constructor (array) {
3936 this._array = array
4037 }
4138
@@ -47,11 +44,8 @@
4744 static deserialize (serialized) {}
4845 }
4946
5047 class DataBuffer {
51- static get type () {
52- return 'data'
53- }
5448 constructor (memory, offset, length) {
5549 this._data = new Uint8Array(this.instance.exports.memory.buffer, offset, length)
5650 }
5751 serialize () {
@@ -60,37 +54,30 @@
6054 static deserialize (serialized) {}
6155 }
6256
6357 class LinkRef {
64- static get type () {
65- return 'link'
66- }
6758 serialize () {
6859 return Buffer.concat(Buffer.from([LANGUAGE_TYPES['link'], this]))
6960 }
7061 static deserialize (serialized) {}
7162 }
7263
7364 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
8067 this.destId = id
8168 let funcIndex
82- if (type === 'export') {
69+ if (location === 'export') {
8370 this.indentifier = identifier
8471 funcIndex = json.exports[identifier]
8572 } else {
8673 this.indentifier = identifier.tableIndex
8774 funcIndex = Number(identifier.name) - 1
8875 }
8976 const typeIndex = json.indexes[funcIndex]
90- const funcType = json.types[typeIndex]
77+ this.type = json.types[typeIndex]
9178
92- const wrapper = typeCheckWrapper(funcType)
79+ const wrapper = typeCheckWrapper(this.type)
9380 const wasm = json2wasm(wrapper)
9481 const mod = WebAssembly.Module(wasm)
9582 const self = this
9683 this.wrapper = WebAssembly.Instance(mod, {
@@ -121,12 +108,8 @@
121108 }
122109 }
123110
124111 class ModuleRef {
125- static get type () {
126- return 'mod'
127- }
128-
129112 constructor (json, id) {
130113 this._json = json
131114 this.id = id
132115 }
@@ -148,11 +131,11 @@
148131 this.refs = new ReferanceMap()
149132 }
150133
151134 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+ }
155138 let moduleJSON = wasm2json(wasm)
156139 const json = customTypes.mergeTypeSections(moduleJSON)
157140 moduleJSON = wasmMetering.meterJSON(moduleJSON, {
158141 meterType: 'i32'
@@ -280,16 +263,17 @@
280263 func.tableIndex = length
281264 }
282265 }
283266 }
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)) {
286270 return arg
287271 } else {
288- return this.refs.add(arg, arg.constructor.type)
272+ return this.refs.add(arg, type)
289273 }
290274 })
291- if (funcRef.type === 'export') {
275+ if (funcRef.location === 'export') {
292276 this.instance.exports[funcRef.indentifier](...args)
293277 } else {
294278 this.instance.exports.table.get(funcRef.indentifier)(...args)
295279 }

Built with git-ssb-web