git ssb

0+

wanderer🌟 / js-primea-hypervisor



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.jschanged
tests/index.jschanged
tests/wasmContainer.jschanged
wasmContainer.jschanged
message.jsdeleted
systemObjects.jsView
@@ -1,5 +1,6 @@
11 const cbor = require('borc')
2+const EventEmitter = require('events')
23
34 const TAGS = {
45 id: 41,
56 link: 42,
@@ -82,9 +83,48 @@
8283 return gen.write(new cbor.Tagged(TAGS.id, this.id))
8384 }
8485 }
8586
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+
86125 module.exports = {
126+ Message,
87127 ID,
88128 FunctionRef,
89129 ModuleRef,
90130 DEFAULTS,
tests/index.jsView
@@ -1,8 +1,7 @@
11 const tape = require('tape')
2-const Message = require('../message.js')
32 const Hypervisor = require('../')
4-const {FunctionRef, ModuleRef} = require('../systemObjects')
3+const {Message, FunctionRef, ModuleRef} = require('../systemObjects')
54
65 const level = require('level-browserify')
76 const EgressDriver = require('../egressDriver')
87 const RadixTree = require('dfinity-radix-tree')
@@ -572,14 +571,14 @@
572571 class BenchmarkContainer extends BaseContainer {
573572 main () {
574573 const refs = [...arguments]
575574 const ref = refs.pop()
576- const last = messageOrder[this.actor.id.toString('hex')]
575+ const last = messageOrder[this.actor.id.id.toString('hex')]
577576 const message = this.actor.currentMessage
578577 if (last) {
579578 t.ok(last <= message._fromTicks, 'message should be in correct order')
580579 }
581- messageOrder[this.actor.id.toString('hex')] = message._fromTicks
580+ messageOrder[this.actor.id.id.toString('hex')] = message._fromTicks
582581 numOfMsg++
583582 this.actor.incrementTicks(10)
584583 if (ref) {
585584 this.actor.send(new Message({
tests/wasmContainer.jsView
@@ -1,8 +1,8 @@
11 const tape = require('tape')
22 const fs = require('fs')
33 const path = require('path')
4-const Message = require('../message.js')
4+const {Message} = require('../systemObjects.js')
55 const Hypervisor = require('../')
66 const WasmContainer = require('../wasmContainer.js')
77
88 const level = require('level-browserify')
wasmContainer.jsView
@@ -1,12 +1,11 @@
11 const {wasm2json, json2wasm} = require('wasm-json-toolkit')
22 const annotations = require('primea-annotations')
33 const wasmMetering = require('wasm-metering')
44 const ReferanceMap = require('reference-map')
5-const Message = require('./message.js')
65 const injectGlobals = require('./injectGlobals.js')
76 const typeCheckWrapper = require('./typeCheckWrapper.js')
8-const {FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js')
7+const {Message, FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js')
98
109 const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64'])
1110 const FUNC_INDEX_OFFSET = 1
1211
message.jsView
@@ -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