Commit fad57dff2dd8eeb05b10062b336a4c44cf1bd050
move message to systemObjects
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 3/27/2018, 5:12:05 PM
Parent: acd65bd28b852ab061aad493bc85901d386b2b9b
Files changed
systemObjects.js | changed |
tests/index.js | changed |
tests/wasmContainer.js | changed |
wasmContainer.js | changed |
message.js | deleted |
systemObjects.js | ||
---|---|---|
@@ -1,5 +1,6 @@ | ||
1 | 1 | const cbor = require('borc') |
2 | +const EventEmitter = require('events') | |
2 | 3 | |
3 | 4 | const TAGS = { |
4 | 5 | id: 41, |
5 | 6 | link: 42, |
@@ -82,9 +83,48 @@ | ||
82 | 83 | return gen.write(new cbor.Tagged(TAGS.id, this.id)) |
83 | 84 | } |
84 | 85 | } |
85 | 86 | |
87 | +/** | |
88 | + * This implements Messages for Primea | |
89 | + * @module primea-message | |
90 | + */ | |
91 | +class Message extends EventEmitter { | |
92 | + /** | |
93 | + * @param {Object} opts | |
94 | + * @param {ArrayBuffer} opts.data - the payload of the message | |
95 | + * @param {Array<Object>} opts.caps - an array of capabilities to send in the message | |
96 | + */ | |
97 | + constructor (opts) { | |
98 | + super() | |
99 | + const defaults = this.constructor.defaults | |
100 | + this._opts = Object.assign(defaults, opts) | |
101 | + Object.keys(this._opts).forEach(key => { | |
102 | + Object.defineProperty(this, key, { | |
103 | + get: function () { | |
104 | + return this._opts[key] | |
105 | + }, | |
106 | + set: function (y) { | |
107 | + this._opts[key] = y | |
108 | + } | |
109 | + }) | |
110 | + }) | |
111 | + } | |
112 | + | |
113 | + static get defaults () { | |
114 | + return { | |
115 | + ticks: 0, | |
116 | + funcRef: null, | |
117 | + funcArguments: [], | |
118 | + funcParameters: [], | |
119 | + _fromId: new ID(Buffer.alloc(20)), | |
120 | + _fromTicks: 0 | |
121 | + } | |
122 | + } | |
123 | +} | |
124 | + | |
86 | 125 | module.exports = { |
126 | + Message, | |
87 | 127 | ID, |
88 | 128 | FunctionRef, |
89 | 129 | ModuleRef, |
90 | 130 | DEFAULTS, |
tests/index.js | ||
---|---|---|
@@ -1,8 +1,7 @@ | ||
1 | 1 | const tape = require('tape') |
2 | -const Message = require('../message.js') | |
3 | 2 | const Hypervisor = require('../') |
4 | -const {FunctionRef, ModuleRef} = require('../systemObjects') | |
3 | +const {Message, FunctionRef, ModuleRef} = require('../systemObjects') | |
5 | 4 | |
6 | 5 | const level = require('level-browserify') |
7 | 6 | const EgressDriver = require('../egressDriver') |
8 | 7 | const RadixTree = require('dfinity-radix-tree') |
@@ -572,14 +571,14 @@ | ||
572 | 571 | class BenchmarkContainer extends BaseContainer { |
573 | 572 | main () { |
574 | 573 | const refs = [...arguments] |
575 | 574 | const ref = refs.pop() |
576 | - const last = messageOrder[this.actor.id.toString('hex')] | |
575 | + const last = messageOrder[this.actor.id.id.toString('hex')] | |
577 | 576 | const message = this.actor.currentMessage |
578 | 577 | if (last) { |
579 | 578 | t.ok(last <= message._fromTicks, 'message should be in correct order') |
580 | 579 | } |
581 | - messageOrder[this.actor.id.toString('hex')] = message._fromTicks | |
580 | + messageOrder[this.actor.id.id.toString('hex')] = message._fromTicks | |
582 | 581 | numOfMsg++ |
583 | 582 | this.actor.incrementTicks(10) |
584 | 583 | if (ref) { |
585 | 584 | this.actor.send(new Message({ |
tests/wasmContainer.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | const tape = require('tape') |
2 | 2 | const fs = require('fs') |
3 | 3 | const path = require('path') |
4 | -const Message = require('../message.js') | |
4 | +const {Message} = require('../systemObjects.js') | |
5 | 5 | const Hypervisor = require('../') |
6 | 6 | const WasmContainer = require('../wasmContainer.js') |
7 | 7 | |
8 | 8 | const level = require('level-browserify') |
wasmContainer.js | ||
---|---|---|
@@ -1,12 +1,11 @@ | ||
1 | 1 | const {wasm2json, json2wasm} = require('wasm-json-toolkit') |
2 | 2 | const annotations = require('primea-annotations') |
3 | 3 | const wasmMetering = require('wasm-metering') |
4 | 4 | const ReferanceMap = require('reference-map') |
5 | -const Message = require('./message.js') | |
6 | 5 | const injectGlobals = require('./injectGlobals.js') |
7 | 6 | const typeCheckWrapper = require('./typeCheckWrapper.js') |
8 | -const {FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js') | |
7 | +const {Message, FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js') | |
9 | 8 | |
10 | 9 | const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64']) |
11 | 10 | const FUNC_INDEX_OFFSET = 1 |
12 | 11 |
message.js | ||
---|---|---|
@@ -1,40 +1,0 @@ | ||
1 | -const EventEmitter = require('events') | |
2 | -const {ID} = require('./systemObjects.js') | |
3 | - | |
4 | -/** | |
5 | - * This implements Messages for Primea | |
6 | - * @module primea-message | |
7 | - */ | |
8 | -module.exports = class Message extends EventEmitter { | |
9 | - /** | |
10 | - * @param {Object} opts | |
11 | - * @param {ArrayBuffer} opts.data - the payload of the message | |
12 | - * @param {Array<Object>} opts.caps - an array of capabilities to send in the message | |
13 | - */ | |
14 | - constructor (opts) { | |
15 | - super() | |
16 | - const defaults = this.constructor.defaults | |
17 | - this._opts = Object.assign(defaults, opts) | |
18 | - Object.keys(this._opts).forEach(key => { | |
19 | - Object.defineProperty(this, key, { | |
20 | - get: function () { | |
21 | - return this._opts[key] | |
22 | - }, | |
23 | - set: function (y) { | |
24 | - this._opts[key] = y | |
25 | - } | |
26 | - }) | |
27 | - }) | |
28 | - } | |
29 | - | |
30 | - static get defaults () { | |
31 | - return { | |
32 | - ticks: 0, | |
33 | - funcRef: null, | |
34 | - funcArguments: [], | |
35 | - funcParameters: [], | |
36 | - _fromId: new ID(Buffer.alloc(20)), | |
37 | - _fromTicks: 0 | |
38 | - } | |
39 | - } | |
40 | -} |
Built with git-ssb-web