@scion-scxml/core 2.6.23 → 2.6.25
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.
package/dist/core.js
CHANGED
|
@@ -51,586 +51,271 @@
|
|
|
51
51
|
}return o;
|
|
52
52
|
}return r;
|
|
53
53
|
}()({ 1: [function (require, module, exports) {
|
|
54
|
-
|
|
55
|
-
'use strict';
|
|
54
|
+
'use strict';
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
function defineProperties(target, props) {
|
|
59
|
-
for (var i = 0; i < props.length; i++) {
|
|
60
|
-
var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
61
|
-
}
|
|
62
|
-
}return function (Constructor, protoProps, staticProps) {
|
|
63
|
-
if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
64
|
-
};
|
|
65
|
-
}();
|
|
56
|
+
/* begin ArraySet */
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
if (Array.isArray(arr)) {
|
|
69
|
-
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
|
|
70
|
-
arr2[i] = arr[i];
|
|
71
|
-
}return arr2;
|
|
72
|
-
} else {
|
|
73
|
-
return Array.from(arr);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
58
|
+
/** @constructor */
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
60
|
+
function ArraySet(l) {
|
|
61
|
+
l = l || [];
|
|
62
|
+
this.o = new Set(l);
|
|
63
|
+
}
|
|
82
64
|
|
|
83
|
-
|
|
84
|
-
if (!self) {
|
|
85
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
86
|
-
}return call && ((typeof call === "undefined" ? "undefined" : _typeof2(call)) === "object" || typeof call === "function") ? call : self;
|
|
87
|
-
}
|
|
65
|
+
ArraySet.prototype = {
|
|
88
66
|
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
93
|
-
}
|
|
67
|
+
add: function add(x) {
|
|
68
|
+
this.o.add(x);
|
|
69
|
+
},
|
|
94
70
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
transitionComparator = base.helpers.transitionComparator;
|
|
71
|
+
remove: function remove(x) {
|
|
72
|
+
return this.o.delete(x);
|
|
73
|
+
},
|
|
99
74
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* @extends BaseInterpreter
|
|
105
|
-
*/
|
|
75
|
+
union: function union(l) {
|
|
76
|
+
var _iteratorNormalCompletion = true;
|
|
77
|
+
var _didIteratorError = false;
|
|
78
|
+
var _iteratorError = undefined;
|
|
106
79
|
|
|
107
|
-
|
|
108
|
-
|
|
80
|
+
try {
|
|
81
|
+
for (var _iterator = l.o[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
82
|
+
var v = _step.value;
|
|
109
83
|
|
|
110
|
-
|
|
111
|
-
|
|
84
|
+
this.o.add(v);
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
_didIteratorError = true;
|
|
88
|
+
_iteratorError = err;
|
|
89
|
+
} finally {
|
|
90
|
+
try {
|
|
91
|
+
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
92
|
+
_iterator.return();
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
if (_didIteratorError) {
|
|
96
|
+
throw _iteratorError;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
112
100
|
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
return this;
|
|
102
|
+
},
|
|
115
103
|
|
|
116
|
-
|
|
117
|
-
|
|
104
|
+
difference: function difference(l) {
|
|
105
|
+
var _iteratorNormalCompletion2 = true;
|
|
106
|
+
var _didIteratorError2 = false;
|
|
107
|
+
var _iteratorError2 = undefined;
|
|
118
108
|
|
|
119
|
-
|
|
109
|
+
try {
|
|
110
|
+
for (var _iterator2 = l.o[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
111
|
+
var v = _step2.value;
|
|
120
112
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
this.o.delete(v);
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
_didIteratorError2 = true;
|
|
117
|
+
_iteratorError2 = err;
|
|
118
|
+
} finally {
|
|
119
|
+
try {
|
|
120
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
121
|
+
_iterator2.return();
|
|
122
|
+
}
|
|
123
|
+
} finally {
|
|
124
|
+
if (_didIteratorError2) {
|
|
125
|
+
throw _iteratorError2;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
126
129
|
|
|
127
|
-
|
|
130
|
+
return this;
|
|
131
|
+
},
|
|
128
132
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
var _iteratorError = undefined;
|
|
133
|
+
contains: function contains(x) {
|
|
134
|
+
return this.o.has(x);
|
|
135
|
+
},
|
|
133
136
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
var _iteratorNormalCompletion2 = true;
|
|
138
|
-
var _didIteratorError2 = false;
|
|
139
|
-
var _iteratorError2 = undefined;
|
|
137
|
+
iter: function iter() {
|
|
138
|
+
return Array.from(this.o);
|
|
139
|
+
},
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
var _iteratorNormalCompletion3 = true;
|
|
145
|
-
var _didIteratorError3 = false;
|
|
146
|
-
var _iteratorError3 = undefined;
|
|
141
|
+
isEmpty: function isEmpty() {
|
|
142
|
+
return !this.o.size;
|
|
143
|
+
},
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
size: function size() {
|
|
146
|
+
return this.o.size;
|
|
147
|
+
},
|
|
151
148
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
} catch (err) {
|
|
158
|
-
_didIteratorError3 = true;
|
|
159
|
-
_iteratorError3 = err;
|
|
160
|
-
} finally {
|
|
161
|
-
try {
|
|
162
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
163
|
-
_iterator3.return();
|
|
164
|
-
}
|
|
165
|
-
} finally {
|
|
166
|
-
if (_didIteratorError3) {
|
|
167
|
-
throw _iteratorError3;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
} catch (err) {
|
|
173
|
-
_didIteratorError2 = true;
|
|
174
|
-
_iteratorError2 = err;
|
|
175
|
-
} finally {
|
|
176
|
-
try {
|
|
177
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
178
|
-
_iterator2.return();
|
|
179
|
-
}
|
|
180
|
-
} finally {
|
|
181
|
-
if (_didIteratorError2) {
|
|
182
|
-
throw _iteratorError2;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} catch (err) {
|
|
188
|
-
_didIteratorError = true;
|
|
189
|
-
_iteratorError = err;
|
|
190
|
-
} finally {
|
|
191
|
-
try {
|
|
192
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
193
|
-
_iterator.return();
|
|
194
|
-
}
|
|
195
|
-
} finally {
|
|
196
|
-
if (_didIteratorError) {
|
|
197
|
-
throw _iteratorError;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
149
|
+
equals: function equals(s2) {
|
|
150
|
+
if (this.o.size !== s2.size()) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
201
153
|
|
|
202
|
-
|
|
154
|
+
var _iteratorNormalCompletion3 = true;
|
|
155
|
+
var _didIteratorError3 = false;
|
|
156
|
+
var _iteratorError3 = undefined;
|
|
203
157
|
|
|
204
|
-
|
|
158
|
+
try {
|
|
159
|
+
for (var _iterator3 = this.o[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
160
|
+
var v = _step3.value;
|
|
205
161
|
|
|
206
|
-
|
|
162
|
+
if (!s2.contains(v)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
207
165
|
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
_didIteratorError3 = true;
|
|
168
|
+
_iteratorError3 = err;
|
|
169
|
+
} finally {
|
|
170
|
+
try {
|
|
171
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
172
|
+
_iterator3.return();
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
if (_didIteratorError3) {
|
|
176
|
+
throw _iteratorError3;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
208
180
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}, {
|
|
212
|
-
key: '_removeConflictingTransition',
|
|
213
|
-
value: function _removeConflictingTransition(enabledTransitions) {
|
|
214
|
-
var _this2 = this;
|
|
181
|
+
return true;
|
|
182
|
+
},
|
|
215
183
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
var _iteratorError4 = undefined;
|
|
184
|
+
toString: function toString() {
|
|
185
|
+
return this.o.size === 0 ? '<empty>' : Array.from(this.o).join(',\n');
|
|
186
|
+
}
|
|
187
|
+
};
|
|
221
188
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
189
|
+
module.exports = ArraySet;
|
|
190
|
+
}, {}], 2: [function (require, module, exports) {
|
|
191
|
+
'use strict';
|
|
225
192
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
193
|
+
var STATE_TYPES = {
|
|
194
|
+
BASIC: 0,
|
|
195
|
+
COMPOSITE: 1,
|
|
196
|
+
PARALLEL: 2,
|
|
197
|
+
HISTORY: 3,
|
|
198
|
+
INITIAL: 4,
|
|
199
|
+
FINAL: 5
|
|
200
|
+
};
|
|
231
201
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
202
|
+
var SCXML_IOPROCESSOR_TYPE = 'http://www.w3.org/TR/scxml/#SCXMLEventProcessor';
|
|
203
|
+
var HTTP_IOPROCESSOR_TYPE = 'http://www.w3.org/TR/scxml/#BasicHTTPEventProcessor';
|
|
204
|
+
var RX_TRAILING_WILDCARD = /\.\*$/;
|
|
235
205
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
_this2._log('t1ExitSet', t1.source.id, [].concat(_toConsumableArray(t1ExitSet)).map(function (s) {
|
|
245
|
-
return s.id;
|
|
246
|
-
}));
|
|
247
|
-
_this2._log('t2ExitSet', t2.source.id, [].concat(_toConsumableArray(t2ExitSet)).map(function (s) {
|
|
248
|
-
return s.id;
|
|
249
|
-
}));
|
|
250
|
-
_this2._log('hasIntersection', hasIntersection);
|
|
251
|
-
if (hasIntersection) {
|
|
252
|
-
if (t2.source.descendants.indexOf(t1.source) > -1) {
|
|
253
|
-
//is this the same as being ancestrally related?
|
|
254
|
-
transitionsToRemove.add(t2);
|
|
255
|
-
} else {
|
|
256
|
-
t1Preempted = true;
|
|
257
|
-
return 'break';
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
};
|
|
206
|
+
module.exports = {
|
|
207
|
+
STATE_TYPES: STATE_TYPES,
|
|
208
|
+
SCXML_IOPROCESSOR_TYPE: SCXML_IOPROCESSOR_TYPE,
|
|
209
|
+
HTTP_IOPROCESSOR_TYPE: HTTP_IOPROCESSOR_TYPE,
|
|
210
|
+
RX_TRAILING_WILDCARD: RX_TRAILING_WILDCARD
|
|
211
|
+
};
|
|
212
|
+
}, {}], 3: [function (require, module, exports) {
|
|
213
|
+
'use strict';
|
|
261
214
|
|
|
262
|
-
|
|
263
|
-
|
|
215
|
+
var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
|
|
216
|
+
return typeof obj === "undefined" ? "undefined" : _typeof2(obj);
|
|
217
|
+
} : function (obj) {
|
|
218
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj);
|
|
219
|
+
};
|
|
264
220
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
_didIteratorError5 = true;
|
|
269
|
-
_iteratorError5 = err;
|
|
270
|
-
} finally {
|
|
271
|
-
try {
|
|
272
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
|
273
|
-
_iterator5.return();
|
|
274
|
-
}
|
|
275
|
-
} finally {
|
|
276
|
-
if (_didIteratorError5) {
|
|
277
|
-
throw _iteratorError5;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
221
|
+
var constants = require('./constants'),
|
|
222
|
+
STATE_TYPES = constants.STATE_TYPES,
|
|
223
|
+
RX_TRAILING_WILDCARD = constants.RX_TRAILING_WILDCARD;
|
|
281
224
|
|
|
282
|
-
|
|
283
|
-
var _iteratorNormalCompletion6 = true;
|
|
284
|
-
var _didIteratorError6 = false;
|
|
285
|
-
var _iteratorError6 = undefined;
|
|
225
|
+
var printTrace = false;
|
|
286
226
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
227
|
+
module.exports = {
|
|
228
|
+
extend: extend,
|
|
229
|
+
transitionWithTargets: transitionWithTargets,
|
|
230
|
+
transitionComparator: transitionComparator,
|
|
231
|
+
initializeModel: initializeModel,
|
|
232
|
+
isEventPrefixMatch: isEventPrefixMatch,
|
|
233
|
+
isTransitionMatch: isTransitionMatch,
|
|
234
|
+
scxmlPrefixTransitionSelector: scxmlPrefixTransitionSelector,
|
|
235
|
+
eventlessTransitionSelector: eventlessTransitionSelector,
|
|
236
|
+
getTransitionWithHigherSourceChildPriority: getTransitionWithHigherSourceChildPriority,
|
|
237
|
+
sortInEntryOrder: sortInEntryOrder,
|
|
238
|
+
getStateWithHigherSourceChildPriority: getStateWithHigherSourceChildPriority,
|
|
239
|
+
initializeModelGeneratorFn: initializeModelGeneratorFn,
|
|
240
|
+
deserializeSerializedConfiguration: deserializeSerializedConfiguration,
|
|
241
|
+
deserializeHistory: deserializeHistory
|
|
242
|
+
};
|
|
290
243
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
try {
|
|
298
|
-
if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
|
299
|
-
_iterator6.return();
|
|
300
|
-
}
|
|
301
|
-
} finally {
|
|
302
|
-
if (_didIteratorError6) {
|
|
303
|
-
throw _iteratorError6;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
244
|
+
function extend(to, from) {
|
|
245
|
+
Object.keys(from).forEach(function (k) {
|
|
246
|
+
to[k] = from[k];
|
|
247
|
+
});
|
|
248
|
+
return to;
|
|
249
|
+
};
|
|
307
250
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
} catch (err) {
|
|
312
|
-
_didIteratorError4 = true;
|
|
313
|
-
_iteratorError4 = err;
|
|
314
|
-
} finally {
|
|
315
|
-
try {
|
|
316
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
|
317
|
-
_iterator4.return();
|
|
318
|
-
}
|
|
319
|
-
} finally {
|
|
320
|
-
if (_didIteratorError4) {
|
|
321
|
-
throw _iteratorError4;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
251
|
+
function transitionWithTargets(t) {
|
|
252
|
+
return t.targets;
|
|
253
|
+
}
|
|
325
254
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
255
|
+
function transitionComparator(t1, t2) {
|
|
256
|
+
return t1.documentOrder - t2.documentOrder;
|
|
257
|
+
}
|
|
329
258
|
|
|
330
|
-
|
|
331
|
-
|
|
259
|
+
function initializeModel(rootState, opts) {
|
|
260
|
+
var transitions = [],
|
|
261
|
+
idToStateMap = new Map(),
|
|
262
|
+
documentOrder = 0;
|
|
332
263
|
|
|
333
|
-
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
"http://www.w3.org/TR/scxml/": function httpWwwW3OrgTRScxml(invokingSession, invokeObj, invokerExecutionContext, cb) {
|
|
337
|
-
//put invoke logic here:
|
|
338
|
-
var method = void 0,
|
|
339
|
-
arg = void 0;
|
|
340
|
-
if (invokeObj.constructorFunction) {
|
|
341
|
-
var fnModel = invokeObj.constructorFunction;
|
|
342
|
-
var options = {
|
|
343
|
-
invokeid: invokeObj.id,
|
|
344
|
-
params: invokeObj.params,
|
|
345
|
-
parentSession: invokingSession,
|
|
346
|
-
docUrl: invokeObj.docUrl
|
|
347
|
-
//sessionid : //TODO: construct or generate a sessionid for invoked session
|
|
348
|
-
};
|
|
349
|
-
var model = invokerExecutionContext;
|
|
350
|
-
var interpreter = void 0;
|
|
351
|
-
if (options.parentSession instanceof Statechart) {
|
|
352
|
-
interpreter = new Statechart(fnModel, options);
|
|
353
|
-
}
|
|
354
|
-
cb(null, interpreter, fnModel, model);
|
|
355
|
-
//we introduce a delay here before starting the interpreter to give clients that are subscribed to onInvokedSessionInitialized event a chance to subscribe to events on the newly instantiated interpreter
|
|
356
|
-
setImmediate(function () {
|
|
357
|
-
return interpreter.start();
|
|
358
|
-
});
|
|
359
|
-
} else {
|
|
360
|
-
throw new Error('Invoke object needs a constructorFunction property');
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
base.InterpreterScriptingContext.invokers[undefined] = base.InterpreterScriptingContext.invokers[null] = base.InterpreterScriptingContext.invokers['scxml'] = base.InterpreterScriptingContext.invokers["http://www.w3.org/TR/scxml/"];
|
|
264
|
+
//TODO: need to add fake ids to anyone that doesn't have them
|
|
265
|
+
//FIXME: make this safer - break into multiple passes
|
|
266
|
+
var idCount = {};
|
|
365
267
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}, { "@scion-scxml/core-base": 6, "timers": 9 }], 2: [function (require, module, exports) {
|
|
369
|
-
'use strict';
|
|
268
|
+
function generateId(type) {
|
|
269
|
+
if (idCount[type] === undefined) idCount[type] = 0;
|
|
370
270
|
|
|
371
|
-
|
|
271
|
+
do {
|
|
272
|
+
var count = idCount[type]++;
|
|
273
|
+
var id = '$generated-' + type + '-' + count;
|
|
274
|
+
} while (idToStateMap.has(id));
|
|
372
275
|
|
|
373
|
-
|
|
276
|
+
return id;
|
|
277
|
+
}
|
|
374
278
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
279
|
+
function wrapInFakeRootState(state) {
|
|
280
|
+
return {
|
|
281
|
+
$deserializeDatamodel: state.$deserializeDatamodel || function () {},
|
|
282
|
+
$serializeDatamodel: state.$serializeDatamodel || function () {
|
|
283
|
+
return null;
|
|
284
|
+
},
|
|
285
|
+
$idToStateMap: idToStateMap, //keep this for handy deserialization of serialized configuration
|
|
286
|
+
docUrl: state.docUrl,
|
|
287
|
+
name: state.name,
|
|
288
|
+
states: [{
|
|
289
|
+
$type: 'initial',
|
|
290
|
+
transitions: [{
|
|
291
|
+
target: state
|
|
292
|
+
}]
|
|
293
|
+
}, state],
|
|
294
|
+
modelFnName: state.modelFnName
|
|
295
|
+
};
|
|
296
|
+
}
|
|
379
297
|
|
|
380
|
-
|
|
298
|
+
var statesWithInitialAttributes = [];
|
|
381
299
|
|
|
382
|
-
|
|
383
|
-
this
|
|
384
|
-
|
|
300
|
+
/**
|
|
301
|
+
@this {SCTransition}
|
|
302
|
+
*/
|
|
303
|
+
function transitionToString(sourceState) {
|
|
304
|
+
return sourceState + ' -- ' + (this.events ? '(' + this.events.join(',') + ')' : null) + (this.cond ? '[' + this.cond.name + ']' : '') + ' --> ' + (this.targets ? this.targets.join(',') : null);
|
|
305
|
+
}
|
|
385
306
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
307
|
+
/**
|
|
308
|
+
@this {SCState}
|
|
309
|
+
*/
|
|
310
|
+
function stateToString() {
|
|
311
|
+
return this.id;
|
|
312
|
+
}
|
|
389
313
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
try {
|
|
396
|
-
for (var _iterator = l.o[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
397
|
-
var v = _step.value;
|
|
398
|
-
|
|
399
|
-
this.o.add(v);
|
|
400
|
-
}
|
|
401
|
-
} catch (err) {
|
|
402
|
-
_didIteratorError = true;
|
|
403
|
-
_iteratorError = err;
|
|
404
|
-
} finally {
|
|
405
|
-
try {
|
|
406
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
407
|
-
_iterator.return();
|
|
408
|
-
}
|
|
409
|
-
} finally {
|
|
410
|
-
if (_didIteratorError) {
|
|
411
|
-
throw _iteratorError;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return this;
|
|
417
|
-
},
|
|
418
|
-
|
|
419
|
-
difference: function difference(l) {
|
|
420
|
-
var _iteratorNormalCompletion2 = true;
|
|
421
|
-
var _didIteratorError2 = false;
|
|
422
|
-
var _iteratorError2 = undefined;
|
|
423
|
-
|
|
424
|
-
try {
|
|
425
|
-
for (var _iterator2 = l.o[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
426
|
-
var v = _step2.value;
|
|
427
|
-
|
|
428
|
-
this.o.delete(v);
|
|
429
|
-
}
|
|
430
|
-
} catch (err) {
|
|
431
|
-
_didIteratorError2 = true;
|
|
432
|
-
_iteratorError2 = err;
|
|
433
|
-
} finally {
|
|
434
|
-
try {
|
|
435
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
436
|
-
_iterator2.return();
|
|
437
|
-
}
|
|
438
|
-
} finally {
|
|
439
|
-
if (_didIteratorError2) {
|
|
440
|
-
throw _iteratorError2;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
return this;
|
|
446
|
-
},
|
|
447
|
-
|
|
448
|
-
contains: function contains(x) {
|
|
449
|
-
return this.o.has(x);
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
iter: function iter() {
|
|
453
|
-
return Array.from(this.o);
|
|
454
|
-
},
|
|
455
|
-
|
|
456
|
-
isEmpty: function isEmpty() {
|
|
457
|
-
return !this.o.size;
|
|
458
|
-
},
|
|
459
|
-
|
|
460
|
-
size: function size() {
|
|
461
|
-
return this.o.size;
|
|
462
|
-
},
|
|
463
|
-
|
|
464
|
-
equals: function equals(s2) {
|
|
465
|
-
if (this.o.size !== s2.size()) {
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
var _iteratorNormalCompletion3 = true;
|
|
470
|
-
var _didIteratorError3 = false;
|
|
471
|
-
var _iteratorError3 = undefined;
|
|
472
|
-
|
|
473
|
-
try {
|
|
474
|
-
for (var _iterator3 = this.o[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
475
|
-
var v = _step3.value;
|
|
476
|
-
|
|
477
|
-
if (!s2.contains(v)) {
|
|
478
|
-
return false;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
} catch (err) {
|
|
482
|
-
_didIteratorError3 = true;
|
|
483
|
-
_iteratorError3 = err;
|
|
484
|
-
} finally {
|
|
485
|
-
try {
|
|
486
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
487
|
-
_iterator3.return();
|
|
488
|
-
}
|
|
489
|
-
} finally {
|
|
490
|
-
if (_didIteratorError3) {
|
|
491
|
-
throw _iteratorError3;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return true;
|
|
497
|
-
},
|
|
498
|
-
|
|
499
|
-
toString: function toString() {
|
|
500
|
-
return this.o.size === 0 ? '<empty>' : Array.from(this.o).join(',\n');
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
module.exports = ArraySet;
|
|
505
|
-
}, {}], 3: [function (require, module, exports) {
|
|
506
|
-
'use strict';
|
|
507
|
-
|
|
508
|
-
var STATE_TYPES = {
|
|
509
|
-
BASIC: 0,
|
|
510
|
-
COMPOSITE: 1,
|
|
511
|
-
PARALLEL: 2,
|
|
512
|
-
HISTORY: 3,
|
|
513
|
-
INITIAL: 4,
|
|
514
|
-
FINAL: 5
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
var SCXML_IOPROCESSOR_TYPE = 'http://www.w3.org/TR/scxml/#SCXMLEventProcessor';
|
|
518
|
-
var HTTP_IOPROCESSOR_TYPE = 'http://www.w3.org/TR/scxml/#BasicHTTPEventProcessor';
|
|
519
|
-
var RX_TRAILING_WILDCARD = /\.\*$/;
|
|
520
|
-
|
|
521
|
-
module.exports = {
|
|
522
|
-
STATE_TYPES: STATE_TYPES,
|
|
523
|
-
SCXML_IOPROCESSOR_TYPE: SCXML_IOPROCESSOR_TYPE,
|
|
524
|
-
HTTP_IOPROCESSOR_TYPE: HTTP_IOPROCESSOR_TYPE,
|
|
525
|
-
RX_TRAILING_WILDCARD: RX_TRAILING_WILDCARD
|
|
526
|
-
};
|
|
527
|
-
}, {}], 4: [function (require, module, exports) {
|
|
528
|
-
'use strict';
|
|
529
|
-
|
|
530
|
-
var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
|
|
531
|
-
return typeof obj === "undefined" ? "undefined" : _typeof2(obj);
|
|
532
|
-
} : function (obj) {
|
|
533
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj);
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
var constants = require('./constants'),
|
|
537
|
-
STATE_TYPES = constants.STATE_TYPES,
|
|
538
|
-
RX_TRAILING_WILDCARD = constants.RX_TRAILING_WILDCARD;
|
|
539
|
-
|
|
540
|
-
var printTrace = false;
|
|
541
|
-
|
|
542
|
-
module.exports = {
|
|
543
|
-
extend: extend,
|
|
544
|
-
transitionWithTargets: transitionWithTargets,
|
|
545
|
-
transitionComparator: transitionComparator,
|
|
546
|
-
initializeModel: initializeModel,
|
|
547
|
-
isEventPrefixMatch: isEventPrefixMatch,
|
|
548
|
-
isTransitionMatch: isTransitionMatch,
|
|
549
|
-
scxmlPrefixTransitionSelector: scxmlPrefixTransitionSelector,
|
|
550
|
-
eventlessTransitionSelector: eventlessTransitionSelector,
|
|
551
|
-
getTransitionWithHigherSourceChildPriority: getTransitionWithHigherSourceChildPriority,
|
|
552
|
-
sortInEntryOrder: sortInEntryOrder,
|
|
553
|
-
getStateWithHigherSourceChildPriority: getStateWithHigherSourceChildPriority,
|
|
554
|
-
initializeModelGeneratorFn: initializeModelGeneratorFn,
|
|
555
|
-
deserializeSerializedConfiguration: deserializeSerializedConfiguration,
|
|
556
|
-
deserializeHistory: deserializeHistory
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
function extend(to, from) {
|
|
560
|
-
Object.keys(from).forEach(function (k) {
|
|
561
|
-
to[k] = from[k];
|
|
562
|
-
});
|
|
563
|
-
return to;
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
function transitionWithTargets(t) {
|
|
567
|
-
return t.targets;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function transitionComparator(t1, t2) {
|
|
571
|
-
return t1.documentOrder - t2.documentOrder;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function initializeModel(rootState, opts) {
|
|
575
|
-
var transitions = [],
|
|
576
|
-
idToStateMap = new Map(),
|
|
577
|
-
documentOrder = 0;
|
|
578
|
-
|
|
579
|
-
//TODO: need to add fake ids to anyone that doesn't have them
|
|
580
|
-
//FIXME: make this safer - break into multiple passes
|
|
581
|
-
var idCount = {};
|
|
582
|
-
|
|
583
|
-
function generateId(type) {
|
|
584
|
-
if (idCount[type] === undefined) idCount[type] = 0;
|
|
585
|
-
|
|
586
|
-
do {
|
|
587
|
-
var count = idCount[type]++;
|
|
588
|
-
var id = '$generated-' + type + '-' + count;
|
|
589
|
-
} while (idToStateMap.has(id));
|
|
590
|
-
|
|
591
|
-
return id;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
function wrapInFakeRootState(state) {
|
|
595
|
-
return {
|
|
596
|
-
$deserializeDatamodel: state.$deserializeDatamodel || function () {},
|
|
597
|
-
$serializeDatamodel: state.$serializeDatamodel || function () {
|
|
598
|
-
return null;
|
|
599
|
-
},
|
|
600
|
-
$idToStateMap: idToStateMap, //keep this for handy deserialization of serialized configuration
|
|
601
|
-
docUrl: state.docUrl,
|
|
602
|
-
name: state.name,
|
|
603
|
-
states: [{
|
|
604
|
-
$type: 'initial',
|
|
605
|
-
transitions: [{
|
|
606
|
-
target: state
|
|
607
|
-
}]
|
|
608
|
-
}, state],
|
|
609
|
-
modelFnName: state.modelFnName
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
var statesWithInitialAttributes = [];
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
@this {SCTransition}
|
|
617
|
-
*/
|
|
618
|
-
function transitionToString(sourceState) {
|
|
619
|
-
return sourceState + ' -- ' + (this.events ? '(' + this.events.join(',') + ')' : null) + (this.cond ? '[' + this.cond.name + ']' : '') + ' --> ' + (this.targets ? this.targets.join(',') : null);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
@this {SCState}
|
|
624
|
-
*/
|
|
625
|
-
function stateToString() {
|
|
626
|
-
return this.id;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
function populateStateIdMap(state) {
|
|
630
|
-
//populate state id map
|
|
631
|
-
if (state.id) {
|
|
632
|
-
idToStateMap.set(state.id, state);
|
|
633
|
-
}
|
|
314
|
+
function populateStateIdMap(state) {
|
|
315
|
+
//populate state id map
|
|
316
|
+
if (state.id) {
|
|
317
|
+
idToStateMap.set(state.id, state);
|
|
318
|
+
}
|
|
634
319
|
|
|
635
320
|
if (state.states) {
|
|
636
321
|
for (var j = 0, len = state.states.length; j < len; j++) {
|
|
@@ -985,7 +670,7 @@
|
|
|
985
670
|
});
|
|
986
671
|
return o;
|
|
987
672
|
}
|
|
988
|
-
}, { "./constants":
|
|
673
|
+
}, { "./constants": 2 }], 4: [function (require, module, exports) {
|
|
989
674
|
'use strict';
|
|
990
675
|
|
|
991
676
|
var constants = require('./constants');
|
|
@@ -1029,7 +714,7 @@
|
|
|
1029
714
|
};
|
|
1030
715
|
|
|
1031
716
|
module.exports = query;
|
|
1032
|
-
}, { "./constants":
|
|
717
|
+
}, { "./constants": 2 }], 5: [function (require, module, exports) {
|
|
1033
718
|
(function (process, setImmediate) {
|
|
1034
719
|
// Copyright 2012-2012 Jacob Beard, INFICON, and other SCION contributors
|
|
1035
720
|
//
|
|
@@ -1251,6 +936,7 @@
|
|
|
1251
936
|
_this._isStepping = false;
|
|
1252
937
|
|
|
1253
938
|
_this._scriptingContext = _this.opts.interpreterScriptingContext || (_this.opts.InterpreterScriptingContext ? new _this.opts.InterpreterScriptingContext(_this) : {});
|
|
939
|
+
_this._scriptingContext._invokeMap = _this.opts._invokeMap || _this._scriptingContext._invokeMap;
|
|
1254
940
|
|
|
1255
941
|
_this.opts.generateSessionid = _this.opts.generateSessionid || BaseInterpreter.generateSessionid;
|
|
1256
942
|
_this.opts.sessionid = _this.opts.sessionid || _this.opts.generateSessionid();
|
|
@@ -1334,7 +1020,11 @@
|
|
|
1334
1020
|
_createClass(BaseInterpreter, [{
|
|
1335
1021
|
key: 'cancel',
|
|
1336
1022
|
value: function cancel() {
|
|
1337
|
-
|
|
1023
|
+
var _this2 = this;
|
|
1024
|
+
|
|
1025
|
+
setImmediate(function () {
|
|
1026
|
+
return delete _this2.opts.parentSession;
|
|
1027
|
+
}); // run this asynchronously, as we still need a reference to the parent session to send the final <done> event
|
|
1338
1028
|
if (this._isInFinalState) return;
|
|
1339
1029
|
this._isInFinalState = true;
|
|
1340
1030
|
this._log('session cancelled ' + this.opts.invokeid);
|
|
@@ -1343,7 +1033,7 @@
|
|
|
1343
1033
|
}, {
|
|
1344
1034
|
key: '_exitInterpreter',
|
|
1345
1035
|
value: function _exitInterpreter(event) {
|
|
1346
|
-
var
|
|
1036
|
+
var _this3 = this;
|
|
1347
1037
|
|
|
1348
1038
|
//TODO: cancel invoked sessions
|
|
1349
1039
|
//cancel all delayed sends when we enter into a final state.
|
|
@@ -1371,7 +1061,7 @@
|
|
|
1371
1061
|
|
|
1372
1062
|
//cancel invoked session
|
|
1373
1063
|
if (stateExited.invokes) stateExited.invokes.forEach(function (invoke) {
|
|
1374
|
-
|
|
1064
|
+
_this3._scriptingContext.cancelInvoke(invoke.id);
|
|
1375
1065
|
});
|
|
1376
1066
|
|
|
1377
1067
|
//if he is a top-level <final> state, then return the done event
|
|
@@ -1455,7 +1145,7 @@
|
|
|
1455
1145
|
}, {
|
|
1456
1146
|
key: '_initStart',
|
|
1457
1147
|
value: function _initStart(cb) {
|
|
1458
|
-
var
|
|
1148
|
+
var _this4 = this;
|
|
1459
1149
|
|
|
1460
1150
|
if (typeof cb !== 'function') {
|
|
1461
1151
|
cb = nop;
|
|
@@ -1467,7 +1157,7 @@
|
|
|
1467
1157
|
//but if we want it to be parallel, then this becomes more complex. so when initializing the model, we add a 'fake' root state, which
|
|
1468
1158
|
//makes the following operation safe.
|
|
1469
1159
|
this._model.initialRef.forEach(function (s) {
|
|
1470
|
-
return
|
|
1160
|
+
return _this4._configuration.add(s);
|
|
1471
1161
|
});
|
|
1472
1162
|
|
|
1473
1163
|
return cb;
|
|
@@ -1605,7 +1295,7 @@
|
|
|
1605
1295
|
}, {
|
|
1606
1296
|
key: '_startBigStep',
|
|
1607
1297
|
value: function _startBigStep(e) {
|
|
1608
|
-
var
|
|
1298
|
+
var _this5 = this;
|
|
1609
1299
|
|
|
1610
1300
|
this.emit('onBigStepBegin', e);
|
|
1611
1301
|
|
|
@@ -1614,7 +1304,7 @@
|
|
|
1614
1304
|
if (state.invokes) state.invokes.forEach(function (invoke) {
|
|
1615
1305
|
if (invoke.autoforward) {
|
|
1616
1306
|
//autoforward
|
|
1617
|
-
|
|
1307
|
+
_this5._scriptingContext.send({
|
|
1618
1308
|
target: '#_' + invoke.id,
|
|
1619
1309
|
name: e.name,
|
|
1620
1310
|
data: e.data
|
|
@@ -1623,7 +1313,7 @@
|
|
|
1623
1313
|
if (invoke.id === e.invokeid) {
|
|
1624
1314
|
//applyFinalize
|
|
1625
1315
|
if (invoke.finalize) invoke.finalize.forEach(function (action) {
|
|
1626
|
-
return
|
|
1316
|
+
return _this5._evaluateAction(e, action);
|
|
1627
1317
|
});
|
|
1628
1318
|
}
|
|
1629
1319
|
});
|
|
@@ -1640,23 +1330,23 @@
|
|
|
1640
1330
|
}, {
|
|
1641
1331
|
key: '_finishBigStep',
|
|
1642
1332
|
value: function _finishBigStep(e, allStatesEntered, allStatesExited, cb) {
|
|
1643
|
-
var
|
|
1333
|
+
var _this6 = this;
|
|
1644
1334
|
|
|
1645
|
-
var statesToInvoke = Array.from(
|
|
1646
|
-
return s.invokes
|
|
1647
|
-
})
|
|
1335
|
+
var statesToInvoke = Array.from(allStatesEntered).filter(function (s) {
|
|
1336
|
+
return s.invokes;
|
|
1337
|
+
}).sort(sortInEntryOrder);
|
|
1648
1338
|
|
|
1649
1339
|
// Here we invoke whatever needs to be invoked. The implementation of 'invoke' is platform-specific
|
|
1650
1340
|
statesToInvoke.forEach(function (s) {
|
|
1651
1341
|
s.invokes.forEach(function (f) {
|
|
1652
|
-
return
|
|
1342
|
+
return _this6._evaluateAction(e, f);
|
|
1653
1343
|
});
|
|
1654
1344
|
});
|
|
1655
1345
|
|
|
1656
1346
|
// cancel invoke for allStatesExited
|
|
1657
1347
|
allStatesExited.forEach(function (s) {
|
|
1658
1348
|
if (s.invokes) s.invokes.forEach(function (invoke) {
|
|
1659
|
-
|
|
1349
|
+
_this6._scriptingContext.cancelInvoke(invoke.id);
|
|
1660
1350
|
});
|
|
1661
1351
|
});
|
|
1662
1352
|
|
|
@@ -1923,7 +1613,7 @@
|
|
|
1923
1613
|
}, {
|
|
1924
1614
|
key: '_enterStates',
|
|
1925
1615
|
value: function _enterStates(currentEvent, selectedTransitionsWithTargets) {
|
|
1926
|
-
var
|
|
1616
|
+
var _this7 = this;
|
|
1927
1617
|
|
|
1928
1618
|
this._log("entering states");
|
|
1929
1619
|
|
|
@@ -2027,7 +1717,7 @@
|
|
|
2027
1717
|
this._internalEventQueue.push({ name: "done.state." + parent.id, data: stateEntered.donedata && stateEntered.donedata.call(this._scriptingContext, currentEvent) });
|
|
2028
1718
|
if (grandparent && grandparent.typeEnum === PARALLEL) {
|
|
2029
1719
|
if (grandparent.states.every(function (s) {
|
|
2030
|
-
return
|
|
1720
|
+
return _this7.isInFinalState(s);
|
|
2031
1721
|
})) {
|
|
2032
1722
|
this._internalEventQueue.push({ name: "done.state." + grandparent.id });
|
|
2033
1723
|
}
|
|
@@ -2212,7 +1902,7 @@
|
|
|
2212
1902
|
}, {
|
|
2213
1903
|
key: '_addAncestorStatesToEnter',
|
|
2214
1904
|
value: function _addAncestorStatesToEnter(state, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent) {
|
|
2215
|
-
var
|
|
1905
|
+
var _this8 = this;
|
|
2216
1906
|
|
|
2217
1907
|
var traverse = function traverse(anc) {
|
|
2218
1908
|
if (anc.typeEnum === PARALLEL) {
|
|
@@ -2227,7 +1917,7 @@
|
|
|
2227
1917
|
if (child.typeEnum !== HISTORY && ![].concat(_toConsumableArray(statesToEnter)).some(function (s) {
|
|
2228
1918
|
return query.isDescendant(s, child);
|
|
2229
1919
|
})) {
|
|
2230
|
-
|
|
1920
|
+
_this8._addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
|
|
2231
1921
|
}
|
|
2232
1922
|
};
|
|
2233
1923
|
|
|
@@ -2281,7 +1971,7 @@
|
|
|
2281
1971
|
}, {
|
|
2282
1972
|
key: '_addDescendantStatesToEnter',
|
|
2283
1973
|
value: function _addDescendantStatesToEnter(state, statesToEnter, statesForDefaultEntry, defaultHistoryContent) {
|
|
2284
|
-
var
|
|
1974
|
+
var _this9 = this;
|
|
2285
1975
|
|
|
2286
1976
|
if (state.typeEnum === HISTORY) {
|
|
2287
1977
|
if (this._historyValue[state.id]) {
|
|
@@ -2501,7 +2191,7 @@
|
|
|
2501
2191
|
if (child.typeEnum !== HISTORY && ![].concat(_toConsumableArray(statesToEnter)).some(function (s) {
|
|
2502
2192
|
return query.isDescendant(s, child);
|
|
2503
2193
|
})) {
|
|
2504
|
-
|
|
2194
|
+
_this9._addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
|
|
2505
2195
|
}
|
|
2506
2196
|
};
|
|
2507
2197
|
|
|
@@ -2527,574 +2217,966 @@
|
|
|
2527
2217
|
}
|
|
2528
2218
|
}
|
|
2529
2219
|
}, {
|
|
2530
|
-
key: 'isInFinalState',
|
|
2531
|
-
value: function isInFinalState(s) {
|
|
2532
|
-
var
|
|
2220
|
+
key: 'isInFinalState',
|
|
2221
|
+
value: function isInFinalState(s) {
|
|
2222
|
+
var _this10 = this;
|
|
2223
|
+
|
|
2224
|
+
if (s.typeEnum === COMPOSITE) {
|
|
2225
|
+
return s.states.some(function (s) {
|
|
2226
|
+
return s.typeEnum === FINAL && _this10._configuration.contains(s);
|
|
2227
|
+
});
|
|
2228
|
+
} else if (s.typeEnum === PARALLEL) {
|
|
2229
|
+
return s.states.every(this.isInFinalState.bind(this));
|
|
2230
|
+
} else {
|
|
2231
|
+
return false;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
/** @private */
|
|
2236
|
+
|
|
2237
|
+
}, {
|
|
2238
|
+
key: '_evaluateAction',
|
|
2239
|
+
value: function _evaluateAction(currentEvent, actionRef) {
|
|
2240
|
+
try {
|
|
2241
|
+
return actionRef.call(this._scriptingContext, currentEvent); //SCXML system variables
|
|
2242
|
+
} catch (e) {
|
|
2243
|
+
this._handleError(e, actionRef);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}, {
|
|
2247
|
+
key: '_handleError',
|
|
2248
|
+
value: function _handleError(e, actionRef) {
|
|
2249
|
+
var event = e instanceof Error || typeof e.__proto__.name === 'string' && e.__proto__.name.match(/^.*Error$/) ? //we can't just do 'e instanceof Error', because the Error object in the sandbox is from a different context, and instanceof will return false
|
|
2250
|
+
{
|
|
2251
|
+
name: 'error.execution',
|
|
2252
|
+
data: {
|
|
2253
|
+
tagname: actionRef.tagname,
|
|
2254
|
+
line: actionRef.line,
|
|
2255
|
+
column: actionRef.column,
|
|
2256
|
+
reason: e.message
|
|
2257
|
+
},
|
|
2258
|
+
type: 'platform'
|
|
2259
|
+
} : e.name ? e : {
|
|
2260
|
+
name: 'error.execution',
|
|
2261
|
+
data: e,
|
|
2262
|
+
type: 'platform'
|
|
2263
|
+
};
|
|
2264
|
+
this._internalEventQueue.push(event);
|
|
2265
|
+
this.emit('onError', event);
|
|
2266
|
+
}
|
|
2267
|
+
}, {
|
|
2268
|
+
key: '_log',
|
|
2269
|
+
value: function _log() {
|
|
2270
|
+
if (printTrace) {
|
|
2271
|
+
var args = Array.from(arguments);
|
|
2272
|
+
this.opts.console.log(args[0] + ': ' + args.slice(1).map(function (arg) {
|
|
2273
|
+
return arg === null ? 'null' : arg === undefined ? 'undefined' : typeof arg === 'string' ? arg : arg.toString() === '[object Object]' ? util.inspect(arg) : arg.toString();
|
|
2274
|
+
}).join(', ') + '\n');
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/**
|
|
2279
|
+
* @interface Listener
|
|
2280
|
+
*/
|
|
2281
|
+
|
|
2282
|
+
/**
|
|
2283
|
+
* @function
|
|
2284
|
+
* @name Listener#onEntry
|
|
2285
|
+
* @param {string} stateId
|
|
2286
|
+
*/
|
|
2287
|
+
|
|
2288
|
+
/**
|
|
2289
|
+
* @function
|
|
2290
|
+
* @name Listener#onExit
|
|
2291
|
+
* @param {string} stateId
|
|
2292
|
+
*/
|
|
2293
|
+
|
|
2294
|
+
/**
|
|
2295
|
+
* @function
|
|
2296
|
+
* @name Listener#onTransition
|
|
2297
|
+
* @param {string} sourceStateId Id of the source state
|
|
2298
|
+
* @param {Array<string>} targetStatesIds Ids of the target states
|
|
2299
|
+
* @param {number} transitionIndex Index of the transition relative to other transitions originating from source state.
|
|
2300
|
+
*/
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* @function
|
|
2304
|
+
* @name Listener#onError
|
|
2305
|
+
* @param {Error} errorInfo
|
|
2306
|
+
*/
|
|
2307
|
+
|
|
2308
|
+
/**
|
|
2309
|
+
* @function
|
|
2310
|
+
* @name Listener#onBigStepBegin
|
|
2311
|
+
*/
|
|
2312
|
+
|
|
2313
|
+
/**
|
|
2314
|
+
* @function
|
|
2315
|
+
* @name Listener#onBigStepResume
|
|
2316
|
+
*/
|
|
2317
|
+
|
|
2318
|
+
/**
|
|
2319
|
+
* @function
|
|
2320
|
+
* @name Listener#onBigStepSuspend
|
|
2321
|
+
*/
|
|
2322
|
+
|
|
2323
|
+
/**
|
|
2324
|
+
* @function
|
|
2325
|
+
* @name Listener#onBigStepEnd
|
|
2326
|
+
*/
|
|
2327
|
+
|
|
2328
|
+
/**
|
|
2329
|
+
* @function
|
|
2330
|
+
* @name Listener#onSmallStepBegin
|
|
2331
|
+
* @param {string} event
|
|
2332
|
+
*/
|
|
2333
|
+
|
|
2334
|
+
/**
|
|
2335
|
+
* @function
|
|
2336
|
+
* @name Listener#onSmallStepEnd
|
|
2337
|
+
*/
|
|
2338
|
+
|
|
2339
|
+
/**
|
|
2340
|
+
* Provides a generic mechanism to subscribe to state change and runtime
|
|
2341
|
+
* error notifications. Can be used for logging and debugging. For example,
|
|
2342
|
+
* can attach a logger that simply logs the state changes. Or can attach a
|
|
2343
|
+
* network debugging client that sends state change notifications to a
|
|
2344
|
+
* debugging server.
|
|
2345
|
+
* This is an alternative interface to {@link EventEmitter.prototype#on}.
|
|
2346
|
+
* @memberof BaseInterpreter.prototype
|
|
2347
|
+
* @param {Listener} listener
|
|
2348
|
+
*/
|
|
2349
|
+
|
|
2350
|
+
}, {
|
|
2351
|
+
key: 'registerListener',
|
|
2352
|
+
value: function registerListener(listener) {
|
|
2353
|
+
BaseInterpreter.EVENTS.forEach(function (event) {
|
|
2354
|
+
if (listener[event]) this.on(event, listener[event]);
|
|
2355
|
+
}, this);
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
/**
|
|
2359
|
+
* Unregister a Listener
|
|
2360
|
+
* @memberof BaseInterpreter.prototype
|
|
2361
|
+
* @param {Listener} listener
|
|
2362
|
+
*/
|
|
2363
|
+
|
|
2364
|
+
}, {
|
|
2365
|
+
key: 'unregisterListener',
|
|
2366
|
+
value: function unregisterListener(listener) {
|
|
2367
|
+
BaseInterpreter.EVENTS.forEach(function (event) {
|
|
2368
|
+
if (listener[event]) this.off(event, listener[event]);
|
|
2369
|
+
}, this);
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
/**
|
|
2373
|
+
* Query the model to get all transition events.
|
|
2374
|
+
* @return {Array<string>} Transition events.
|
|
2375
|
+
* @memberof BaseInterpreter.prototype
|
|
2376
|
+
*/
|
|
2377
|
+
|
|
2378
|
+
}, {
|
|
2379
|
+
key: 'getAllTransitionEvents',
|
|
2380
|
+
value: function getAllTransitionEvents() {
|
|
2381
|
+
var events = {};
|
|
2382
|
+
function getEvents(state) {
|
|
2383
|
+
|
|
2384
|
+
if (state.transitions) {
|
|
2385
|
+
for (var txIdx = 0, txLen = state.transitions.length; txIdx < txLen; txIdx++) {
|
|
2386
|
+
events[state.transitions[txIdx].event] = true;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
if (state.states) {
|
|
2391
|
+
for (var stateIdx = 0, stateLen = state.states.length; stateIdx < stateLen; stateIdx++) {
|
|
2392
|
+
getEvents(state.states[stateIdx]);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
getEvents(this._model);
|
|
2398
|
+
|
|
2399
|
+
return Object.keys(events);
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
/**
|
|
2403
|
+
* Three things capture the current snapshot of a running SCION interpreter:
|
|
2404
|
+
*
|
|
2405
|
+
* <ul>
|
|
2406
|
+
* <li> basic configuration (the set of basic states the state machine is in)</li>
|
|
2407
|
+
* <li> history state values (the states the state machine was in last time it was in the parent of a history state)</li>
|
|
2408
|
+
* <li> the datamodel</li>
|
|
2409
|
+
* </ul>
|
|
2410
|
+
*
|
|
2411
|
+
* The snapshot object can be serialized as JSON and saved to a database. It can
|
|
2412
|
+
* later be passed to the SCXML constructor to restore the state machine
|
|
2413
|
+
* using the snapshot argument.
|
|
2414
|
+
*
|
|
2415
|
+
* @return {Snapshot}
|
|
2416
|
+
* @memberof BaseInterpreter.prototype
|
|
2417
|
+
*/
|
|
2418
|
+
|
|
2419
|
+
}, {
|
|
2420
|
+
key: 'getSnapshot',
|
|
2421
|
+
value: function getSnapshot() {
|
|
2422
|
+
return [this.getConfiguration(), this._serializeHistory(), this._isInFinalState, this._model.$serializeDatamodel(), this._internalEventQueue.slice()];
|
|
2423
|
+
}
|
|
2424
|
+
}, {
|
|
2425
|
+
key: '_serializeHistory',
|
|
2426
|
+
value: function _serializeHistory() {
|
|
2427
|
+
var o = {};
|
|
2428
|
+
Object.keys(this._historyValue).forEach(function (sid) {
|
|
2429
|
+
o[sid] = this._historyValue[sid].map(function (state) {
|
|
2430
|
+
return state.id;
|
|
2431
|
+
});
|
|
2432
|
+
}, this);
|
|
2433
|
+
return o;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
/**
|
|
2437
|
+
* @interface Event
|
|
2438
|
+
*/
|
|
2439
|
+
|
|
2440
|
+
/**
|
|
2441
|
+
* @member name
|
|
2442
|
+
* @memberof Event.prototype
|
|
2443
|
+
* @type string
|
|
2444
|
+
* @description The name of the event
|
|
2445
|
+
*/
|
|
2446
|
+
|
|
2447
|
+
/**
|
|
2448
|
+
* @member data
|
|
2449
|
+
* @memberof Event.prototype
|
|
2450
|
+
* @type any
|
|
2451
|
+
* @description The event data
|
|
2452
|
+
*/
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* An SCXML interpreter takes SCXML events as input, where an SCXML event is an
|
|
2456
|
+
* object with "name" and "data" properties. These can be passed to method `gen`
|
|
2457
|
+
* as two positional arguments, or as a single object.
|
|
2458
|
+
* @param {string|Event} evtObjOrName
|
|
2459
|
+
* @param {any=} optionalData
|
|
2460
|
+
* @emits scion.BaseInterpreter#onEntry
|
|
2461
|
+
* @emits scion.BaseInterpreter#onExit
|
|
2462
|
+
* @emits scion.BaseInterpreter#onTransition
|
|
2463
|
+
* @emits scion.BaseInterpreter#onDefaultEntry
|
|
2464
|
+
* @emits scion.BaseInterpreter#onError
|
|
2465
|
+
* @emits scion.BaseInterpreter#onBigStepBegin
|
|
2466
|
+
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2467
|
+
* @emits scion.BaseInterpreter#onBigStepSuspend
|
|
2468
|
+
* @emits scion.BaseInterpreter#onBigStepResume
|
|
2469
|
+
* @emits scion.BaseInterpreter#onSmallStepBegin
|
|
2470
|
+
* @emits scion.BaseInterpreter#onSmallStepEnd
|
|
2471
|
+
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2472
|
+
* @emits scion.BaseInterpreter#onExitInterpreter
|
|
2473
|
+
*/
|
|
2474
|
+
|
|
2475
|
+
}, {
|
|
2476
|
+
key: 'gen',
|
|
2477
|
+
value: function gen(evtObjOrName, optionalData) {
|
|
2478
|
+
var currentEvent;
|
|
2479
|
+
switch (typeof evtObjOrName === 'undefined' ? 'undefined' : _typeof(evtObjOrName)) {
|
|
2480
|
+
case 'string':
|
|
2481
|
+
currentEvent = { name: evtObjOrName, data: optionalData };
|
|
2482
|
+
break;
|
|
2483
|
+
case 'object':
|
|
2484
|
+
if (typeof evtObjOrName.name === 'string') {
|
|
2485
|
+
currentEvent = evtObjOrName;
|
|
2486
|
+
} else {
|
|
2487
|
+
throw new Error('Event object must have "name" property of type string.');
|
|
2488
|
+
}
|
|
2489
|
+
break;
|
|
2490
|
+
default:
|
|
2491
|
+
throw new Error('First argument to gen must be a string or object.');
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
if (this._isStepping) throw new Error('Cannot call gen during a big-step');
|
|
2495
|
+
|
|
2496
|
+
//otherwise, kick him off
|
|
2497
|
+
this._isStepping = true;
|
|
2498
|
+
|
|
2499
|
+
this._performBigStep(currentEvent);
|
|
2500
|
+
|
|
2501
|
+
this._isStepping = false;
|
|
2502
|
+
return this.getConfiguration();
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
/**
|
|
2506
|
+
* Injects an external event into the interpreter asynchronously
|
|
2507
|
+
* @param {Event} currentEvent The event to inject
|
|
2508
|
+
* @param {genCallback} cb Callback invoked with an error or the interpreter's stable configuration
|
|
2509
|
+
* @emits scion.BaseInterpreter#onEntry
|
|
2510
|
+
* @emits scion.BaseInterpreter#onExit
|
|
2511
|
+
* @emits scion.BaseInterpreter#onTransition
|
|
2512
|
+
* @emits scion.BaseInterpreter#onDefaultEntry
|
|
2513
|
+
* @emits scion.BaseInterpreter#onError
|
|
2514
|
+
* @emits scion.BaseInterpreter#onBigStepBegin
|
|
2515
|
+
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2516
|
+
* @emits scion.BaseInterpreter#onBigStepSuspend
|
|
2517
|
+
* @emits scion.BaseInterpreter#onBigStepResume
|
|
2518
|
+
* @emits scion.BaseInterpreter#onSmallStepBegin
|
|
2519
|
+
* @emits scion.BaseInterpreter#onSmallStepEnd
|
|
2520
|
+
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2521
|
+
* @emits scion.BaseInterpreter#onExitInterpreter
|
|
2522
|
+
*/
|
|
2523
|
+
|
|
2524
|
+
}, {
|
|
2525
|
+
key: 'genAsync',
|
|
2526
|
+
value: function genAsync(currentEvent, cb) {
|
|
2527
|
+
if (currentEvent !== null && ((typeof currentEvent === 'undefined' ? 'undefined' : _typeof(currentEvent)) !== 'object' || !currentEvent || typeof currentEvent.name !== 'string')) {
|
|
2528
|
+
throw new Error('Expected currentEvent to be null or an Object with a name');
|
|
2529
|
+
}
|
|
2530
|
+
|
|
2531
|
+
if (typeof cb !== 'function') {
|
|
2532
|
+
cb = nop;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
this._externalEventQueue.push([currentEvent, cb]);
|
|
2536
|
+
|
|
2537
|
+
//the semantics we want are to return to the cb the results of processing that particular event.
|
|
2538
|
+
function nextStep(e, c) {
|
|
2539
|
+
this._performBigStepAsync(e, function (err, config) {
|
|
2540
|
+
c(err, config);
|
|
2541
|
+
|
|
2542
|
+
if (this._externalEventQueue.length) {
|
|
2543
|
+
nextStep.apply(this, this._externalEventQueue.shift());
|
|
2544
|
+
} else {
|
|
2545
|
+
this._isStepping = false;
|
|
2546
|
+
}
|
|
2547
|
+
}.bind(this));
|
|
2548
|
+
}
|
|
2549
|
+
if (!this._isStepping) {
|
|
2550
|
+
this._isStepping = true;
|
|
2551
|
+
nextStep.apply(this, this._externalEventQueue.shift());
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
}]);
|
|
2555
|
+
|
|
2556
|
+
return BaseInterpreter;
|
|
2557
|
+
}(EventEmitter);
|
|
2558
|
+
|
|
2559
|
+
BaseInterpreter.EVENTS = ['onEntry', 'onExit', 'onTransition', 'onDefaultEntry', 'onError', 'onBigStepBegin', 'onBigStepSuspend', 'onBigStepResume', 'onSmallStepBegin', 'onSmallStepEnd', 'onBigStepEnd', 'onExitInterpreter'];
|
|
2560
|
+
|
|
2561
|
+
//some global singletons to use to generate in-memory session ids, in case the user does not specify these data structures
|
|
2562
|
+
BaseInterpreter.sessionIdCounter = 1;
|
|
2563
|
+
BaseInterpreter.generateSessionid = function () {
|
|
2564
|
+
return BaseInterpreter.sessionIdCounter++;
|
|
2565
|
+
};
|
|
2566
|
+
BaseInterpreter.sessionRegistry = new Map();
|
|
2567
|
+
|
|
2568
|
+
// Do nothing
|
|
2569
|
+
|
|
2570
|
+
function nop() {}
|
|
2571
|
+
|
|
2572
|
+
var InterpreterScriptingContext = function () {
|
|
2573
|
+
function InterpreterScriptingContext(interpreter) {
|
|
2574
|
+
_classCallCheck(this, InterpreterScriptingContext);
|
|
2575
|
+
|
|
2576
|
+
this._interpreter = interpreter;
|
|
2577
|
+
this._timeoutMap = {};
|
|
2578
|
+
this._invokeMap = {};
|
|
2579
|
+
this._timeouts = new Set();
|
|
2580
|
+
|
|
2581
|
+
//Regex from:
|
|
2582
|
+
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
|
|
2583
|
+
// http://stackoverflow.com/a/6927878
|
|
2584
|
+
this.validateUriRegex = /(#_.*)|\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
|
|
2585
|
+
|
|
2586
|
+
this.invokeSendTargetRegex = /^#_(.*)$/;
|
|
2587
|
+
this.scxmlSendTargetRegex = /^#_scxml_(.*)$/;
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
_createClass(InterpreterScriptingContext, [{
|
|
2591
|
+
key: 'raise',
|
|
2592
|
+
value: function raise(event) {
|
|
2593
|
+
this._installDefaultPropsOnEvent(event, true);
|
|
2594
|
+
this._interpreter._internalEventQueue.push(event);
|
|
2595
|
+
}
|
|
2596
|
+
}, {
|
|
2597
|
+
key: 'parseXmlStringAsDOM',
|
|
2598
|
+
value: function parseXmlStringAsDOM(xmlString) {
|
|
2599
|
+
return (this._interpreter.opts.xmlParser || InterpreterScriptingContext.xmlParser).parse(xmlString);
|
|
2600
|
+
}
|
|
2601
|
+
}, {
|
|
2602
|
+
key: 'invoke',
|
|
2603
|
+
value: function invoke(invokeObj) {
|
|
2604
|
+
var _this11 = this;
|
|
2605
|
+
|
|
2606
|
+
//look up invoker by type. assume invokers are passed in as an option to constructor
|
|
2607
|
+
this._invokeMap[invokeObj.id] = new Promise(function (resolve, reject) {
|
|
2608
|
+
(_this11._interpreter.opts.invokers || InterpreterScriptingContext.invokers)[invokeObj.type](_this11._interpreter, invokeObj, _this11._interpreter.opts.invokerExecutionContext, function (err, session) {
|
|
2609
|
+
if (err) return reject(err);
|
|
2610
|
+
|
|
2611
|
+
_this11._interpreter.emit('onInvokedSessionInitialized', session);
|
|
2612
|
+
resolve(session);
|
|
2613
|
+
});
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
}, {
|
|
2617
|
+
key: 'cancelInvoke',
|
|
2618
|
+
value: function cancelInvoke(invokeid) {
|
|
2619
|
+
var _this12 = this;
|
|
2533
2620
|
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2621
|
+
//TODO: on cancel invoke clean up this._invokeMap
|
|
2622
|
+
var sessionPromise = this._invokeMap[invokeid];
|
|
2623
|
+
this._interpreter._log('cancelling session with invokeid ' + invokeid);
|
|
2624
|
+
if (sessionPromise) {
|
|
2625
|
+
this._interpreter._log('sessionPromise found');
|
|
2626
|
+
sessionPromise.then(function (session) {
|
|
2627
|
+
_this12._interpreter._log('resolved session ' + invokeid + '. cancelling... ');
|
|
2628
|
+
session.cancel();
|
|
2629
|
+
//clean up
|
|
2630
|
+
delete _this12._invokeMap[invokeid];
|
|
2631
|
+
}, function (err) {
|
|
2632
|
+
//TODO: dispatch error back into the state machine as error.communication
|
|
2537
2633
|
});
|
|
2538
|
-
} else if (s.typeEnum === PARALLEL) {
|
|
2539
|
-
return s.states.every(this.isInFinalState.bind(this));
|
|
2540
|
-
} else {
|
|
2541
|
-
return false;
|
|
2542
2634
|
}
|
|
2543
2635
|
}
|
|
2544
|
-
|
|
2545
|
-
/** @private */
|
|
2546
|
-
|
|
2547
2636
|
}, {
|
|
2548
|
-
key: '
|
|
2549
|
-
value: function
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
this._handleError(e, actionRef);
|
|
2637
|
+
key: '_installDefaultPropsOnEvent',
|
|
2638
|
+
value: function _installDefaultPropsOnEvent(event, isInternal) {
|
|
2639
|
+
if (!isInternal) {
|
|
2640
|
+
event.origin = this._interpreter.opts._x._ioprocessors.scxml.location; //TODO: preserve original origin when we autoforward?
|
|
2641
|
+
event.origintype = event.type || SCXML_IOPROCESSOR_TYPE;
|
|
2554
2642
|
}
|
|
2643
|
+
if (typeof event.type === 'undefined') {
|
|
2644
|
+
event.type = isInternal ? 'internal' : 'external';
|
|
2645
|
+
}
|
|
2646
|
+
['name', 'sendid', 'invokeid', 'data', 'origin', 'origintype'].forEach(function (prop) {
|
|
2647
|
+
if (typeof event[prop] === 'undefined') {
|
|
2648
|
+
event[prop] = undefined;
|
|
2649
|
+
}
|
|
2650
|
+
});
|
|
2555
2651
|
}
|
|
2556
2652
|
}, {
|
|
2557
|
-
key: '
|
|
2558
|
-
value: function
|
|
2559
|
-
|
|
2560
|
-
{
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
}
|
|
2577
|
-
}, {
|
|
2578
|
-
key: '_log',
|
|
2579
|
-
value: function _log() {
|
|
2580
|
-
if (printTrace) {
|
|
2581
|
-
var args = Array.from(arguments);
|
|
2582
|
-
this.opts.console.log(args[0] + ': ' + args.slice(1).map(function (arg) {
|
|
2583
|
-
return arg === null ? 'null' : arg === undefined ? 'undefined' : typeof arg === 'string' ? arg : arg.toString() === '[object Object]' ? util.inspect(arg) : arg.toString();
|
|
2584
|
-
}).join(', ') + '\n');
|
|
2653
|
+
key: 'send',
|
|
2654
|
+
value: function send(event, options) {
|
|
2655
|
+
this._interpreter._log('send event', event, options);
|
|
2656
|
+
options = options || {};
|
|
2657
|
+
var sendType = options.type || SCXML_IOPROCESSOR_TYPE;
|
|
2658
|
+
//TODO: move these out
|
|
2659
|
+
function validateSend(event, options, sendAction) {
|
|
2660
|
+
if (event.target) {
|
|
2661
|
+
var targetIsValidUri = this.validateUriRegex.test(event.target);
|
|
2662
|
+
if (!targetIsValidUri) {
|
|
2663
|
+
throw { name: "error.execution", data: 'Target is not valid URI', sendid: event.sendid, type: 'platform' };
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
if (sendType !== SCXML_IOPROCESSOR_TYPE) {
|
|
2667
|
+
//TODO: extend this to support HTTP, and other IO processors
|
|
2668
|
+
throw { name: "error.execution", data: 'Unsupported event processor type', sendid: event.sendid, type: 'platform' };
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
sendAction.call(this, event, options);
|
|
2585
2672
|
}
|
|
2586
|
-
}
|
|
2587
2673
|
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
*/
|
|
2674
|
+
function defaultSendAction(event, options) {
|
|
2675
|
+
var _this13 = this;
|
|
2591
2676
|
|
|
2592
|
-
|
|
2593
|
-
* @function
|
|
2594
|
-
* @name Listener#onEntry
|
|
2595
|
-
* @param {string} stateId
|
|
2596
|
-
*/
|
|
2677
|
+
if (typeof setTimeout === 'undefined') throw new Error('Default implementation of BaseInterpreter.prototype.send will not work unless setTimeout is defined globally.');
|
|
2597
2678
|
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2679
|
+
var match;
|
|
2680
|
+
if (event.target === '#_internal') {
|
|
2681
|
+
this.raise(event);
|
|
2682
|
+
} else {
|
|
2683
|
+
this._installDefaultPropsOnEvent(event, false);
|
|
2684
|
+
event.origintype = SCXML_IOPROCESSOR_TYPE; //TODO: extend this to support HTTP, and other IO processors
|
|
2685
|
+
//TODO : paramterize this based on send/@type?
|
|
2686
|
+
if (!event.target) {
|
|
2687
|
+
doSend.call(this, this._interpreter);
|
|
2688
|
+
} else if (event.target === '#_parent') {
|
|
2689
|
+
if (this._interpreter.opts.parentSession) {
|
|
2690
|
+
event.invokeid = this._interpreter.opts.invokeid;
|
|
2691
|
+
doSend.call(this, this._interpreter.opts.parentSession);
|
|
2692
|
+
} else {
|
|
2693
|
+
throw { name: "error.communication", data: 'Parent session not specified', sendid: event.sendid, type: 'platform' };
|
|
2694
|
+
}
|
|
2695
|
+
} else if (match = event.target.match(this.scxmlSendTargetRegex)) {
|
|
2696
|
+
var targetSessionId = match[1];
|
|
2697
|
+
var session = this._interpreter.opts.sessionRegistry.get(targetSessionId);
|
|
2698
|
+
if (session) {
|
|
2699
|
+
doSend.call(this, session);
|
|
2700
|
+
} else {
|
|
2701
|
+
throw { name: 'error.communication', sendid: event.sendid, type: 'platform' };
|
|
2702
|
+
}
|
|
2703
|
+
} else if (match = event.target.match(this.invokeSendTargetRegex)) {
|
|
2704
|
+
//TODO: test this code path.
|
|
2705
|
+
var invokeId = match[1];
|
|
2706
|
+
this._invokeMap[invokeId].then(function (session) {
|
|
2707
|
+
doSend.call(_this13, session);
|
|
2708
|
+
});
|
|
2709
|
+
} else {
|
|
2710
|
+
throw new Error('Unrecognized send target.'); //TODO: dispatch error back into the state machine
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2603
2713
|
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2714
|
+
function doSend(session) {
|
|
2715
|
+
//TODO: we probably now need to refactor data structures:
|
|
2716
|
+
// this._timeouts
|
|
2717
|
+
// this._timeoutMap
|
|
2718
|
+
var timeoutHandle = setTimeout(function () {
|
|
2719
|
+
if (event.sendid) delete this._timeoutMap[event.sendid];
|
|
2720
|
+
this._timeouts.delete(timeoutOptions);
|
|
2721
|
+
var _doSend = this._interpreter.opts.doSend || BaseInterpreter.doSend;
|
|
2722
|
+
if (_doSend) {
|
|
2723
|
+
_doSend(session, event);
|
|
2724
|
+
} else {
|
|
2725
|
+
session[this._interpreter.opts.sendAsync ? 'genAsync' : 'gen'](event);
|
|
2726
|
+
}
|
|
2727
|
+
}.bind(this), options.delay || 0);
|
|
2611
2728
|
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2729
|
+
var timeoutOptions = {
|
|
2730
|
+
sendOptions: options,
|
|
2731
|
+
timeoutHandle: timeoutHandle
|
|
2732
|
+
};
|
|
2733
|
+
if (event.sendid) this._timeoutMap[event.sendid] = timeoutHandle;
|
|
2734
|
+
this._timeouts.add(timeoutOptions);
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2617
2737
|
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
*/
|
|
2738
|
+
function publish() {
|
|
2739
|
+
this._interpreter.emit(event.name, event.data);
|
|
2740
|
+
}
|
|
2622
2741
|
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2742
|
+
//choose send function
|
|
2743
|
+
//TODO: rethink how this custom send works
|
|
2744
|
+
var sendFn;
|
|
2745
|
+
if (event.type === 'https://github.com/jbeard4/SCION#publish') {
|
|
2746
|
+
sendFn = publish;
|
|
2747
|
+
} else if (this._interpreter.opts.customSend) {
|
|
2748
|
+
sendFn = this._interpreter.opts.customSend;
|
|
2749
|
+
} else {
|
|
2750
|
+
sendFn = defaultSendAction;
|
|
2751
|
+
}
|
|
2627
2752
|
|
|
2628
|
-
|
|
2629
|
-
* @function
|
|
2630
|
-
* @name Listener#onBigStepSuspend
|
|
2631
|
-
*/
|
|
2753
|
+
options = options || {};
|
|
2632
2754
|
|
|
2633
|
-
|
|
2634
|
-
* @function
|
|
2635
|
-
* @name Listener#onBigStepEnd
|
|
2636
|
-
*/
|
|
2755
|
+
this._interpreter._log("sending event", event.name, "with content", event.data, "after delay", options.delay);
|
|
2637
2756
|
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2757
|
+
validateSend.call(this, event, options, sendFn);
|
|
2758
|
+
}
|
|
2759
|
+
}, {
|
|
2760
|
+
key: 'cancel',
|
|
2761
|
+
value: function cancel(sendid) {
|
|
2762
|
+
if (this._interpreter.opts.customCancel) {
|
|
2763
|
+
return this._interpreter.opts.customCancel.apply(this, [sendid]);
|
|
2764
|
+
}
|
|
2643
2765
|
|
|
2644
|
-
|
|
2645
|
-
* @function
|
|
2646
|
-
* @name Listener#onSmallStepEnd
|
|
2647
|
-
*/
|
|
2766
|
+
if (typeof clearTimeout === 'undefined') throw new Error('Default implementation of BaseInterpreter.prototype.cancel will not work unless setTimeout is defined globally.');
|
|
2648
2767
|
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2768
|
+
if (sendid in this._timeoutMap) {
|
|
2769
|
+
this._interpreter._log("cancelling ", sendid, " with timeout id ", this._timeoutMap[sendid]);
|
|
2770
|
+
clearTimeout(this._timeoutMap[sendid]);
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
}]);
|
|
2774
|
+
|
|
2775
|
+
return InterpreterScriptingContext;
|
|
2776
|
+
}();
|
|
2777
|
+
|
|
2778
|
+
module.exports = extend(new EventEmitter(), {
|
|
2779
|
+
BaseInterpreter: BaseInterpreter,
|
|
2780
|
+
ArraySet: ArraySet,
|
|
2781
|
+
STATE_TYPES: constants.STATE_TYPES,
|
|
2782
|
+
initializeModel: initializeModel,
|
|
2783
|
+
InterpreterScriptingContext: InterpreterScriptingContext,
|
|
2784
|
+
helpers: helpers,
|
|
2785
|
+
query: query
|
|
2786
|
+
});
|
|
2787
|
+
}).call(this, require('_process'), require("timers").setImmediate);
|
|
2788
|
+
}, { "./ArraySet": 1, "./constants": 2, "./helpers": 3, "./query": 4, "_process": 9, "timers": 10, "tiny-events": 6, "util": 12 }], 6: [function (require, module, exports) {
|
|
2789
|
+
function EventEmitter() {
|
|
2790
|
+
this._listeners = {};
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
EventEmitter.prototype.on = function _on(type, listener) {
|
|
2794
|
+
if (!Array.isArray(this._listeners[type])) {
|
|
2795
|
+
this._listeners[type] = [];
|
|
2796
|
+
}
|
|
2659
2797
|
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
BaseInterpreter.EVENTS.forEach(function (event) {
|
|
2664
|
-
if (listener[event]) this.on(event, listener[event]);
|
|
2665
|
-
}, this);
|
|
2666
|
-
}
|
|
2798
|
+
if (this._listeners[type].indexOf(listener) === -1) {
|
|
2799
|
+
this._listeners[type].push(listener);
|
|
2800
|
+
}
|
|
2667
2801
|
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
* @memberof BaseInterpreter.prototype
|
|
2671
|
-
* @param {Listener} listener
|
|
2672
|
-
*/
|
|
2802
|
+
return this;
|
|
2803
|
+
};
|
|
2673
2804
|
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
value: function unregisterListener(listener) {
|
|
2677
|
-
BaseInterpreter.EVENTS.forEach(function (event) {
|
|
2678
|
-
if (listener[event]) this.off(event, listener[event]);
|
|
2679
|
-
}, this);
|
|
2680
|
-
}
|
|
2805
|
+
EventEmitter.prototype.once = function _once(type, listener) {
|
|
2806
|
+
var self = this;
|
|
2681
2807
|
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
*/
|
|
2808
|
+
function __once() {
|
|
2809
|
+
for (var args = [], i = 0; i < arguments.length; i += 1) {
|
|
2810
|
+
args[i] = arguments[i];
|
|
2811
|
+
}
|
|
2687
2812
|
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
var events = {};
|
|
2692
|
-
function getEvents(state) {
|
|
2813
|
+
self.off(type, __once);
|
|
2814
|
+
listener.apply(self, args);
|
|
2815
|
+
}
|
|
2693
2816
|
|
|
2694
|
-
|
|
2695
|
-
for (var txIdx = 0, txLen = state.transitions.length; txIdx < txLen; txIdx++) {
|
|
2696
|
-
events[state.transitions[txIdx].event] = true;
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2817
|
+
__once.listener = listener;
|
|
2699
2818
|
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
getEvents(state.states[stateIdx]);
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2819
|
+
return this.on(type, __once);
|
|
2820
|
+
};
|
|
2706
2821
|
|
|
2707
|
-
|
|
2822
|
+
EventEmitter.prototype.off = function _off(type, listener) {
|
|
2823
|
+
if (!Array.isArray(this._listeners[type])) {
|
|
2824
|
+
return this;
|
|
2825
|
+
}
|
|
2708
2826
|
|
|
2709
|
-
|
|
2710
|
-
|
|
2827
|
+
if (typeof listener === 'undefined') {
|
|
2828
|
+
this._listeners[type] = [];
|
|
2829
|
+
return this;
|
|
2830
|
+
}
|
|
2711
2831
|
|
|
2712
|
-
|
|
2713
|
-
* Three things capture the current snapshot of a running SCION interpreter:
|
|
2714
|
-
*
|
|
2715
|
-
* <ul>
|
|
2716
|
-
* <li> basic configuration (the set of basic states the state machine is in)</li>
|
|
2717
|
-
* <li> history state values (the states the state machine was in last time it was in the parent of a history state)</li>
|
|
2718
|
-
* <li> the datamodel</li>
|
|
2719
|
-
* </ul>
|
|
2720
|
-
*
|
|
2721
|
-
* The snapshot object can be serialized as JSON and saved to a database. It can
|
|
2722
|
-
* later be passed to the SCXML constructor to restore the state machine
|
|
2723
|
-
* using the snapshot argument.
|
|
2724
|
-
*
|
|
2725
|
-
* @return {Snapshot}
|
|
2726
|
-
* @memberof BaseInterpreter.prototype
|
|
2727
|
-
*/
|
|
2832
|
+
var index = this._listeners[type].indexOf(listener);
|
|
2728
2833
|
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
}, {
|
|
2735
|
-
key: '_serializeHistory',
|
|
2736
|
-
value: function _serializeHistory() {
|
|
2737
|
-
var o = {};
|
|
2738
|
-
Object.keys(this._historyValue).forEach(function (sid) {
|
|
2739
|
-
o[sid] = this._historyValue[sid].map(function (state) {
|
|
2740
|
-
return state.id;
|
|
2741
|
-
});
|
|
2742
|
-
}, this);
|
|
2743
|
-
return o;
|
|
2834
|
+
if (index === -1) {
|
|
2835
|
+
for (var i = 0; i < this._listeners[type].length; i += 1) {
|
|
2836
|
+
if (this._listeners[type][i].listener === listener) {
|
|
2837
|
+
index = i;
|
|
2838
|
+
break;
|
|
2744
2839
|
}
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2745
2842
|
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2843
|
+
this._listeners[type].splice(index, 1);
|
|
2844
|
+
return this;
|
|
2845
|
+
};
|
|
2749
2846
|
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
* @description The name of the event
|
|
2755
|
-
*/
|
|
2847
|
+
EventEmitter.prototype.emit = function _emit(type) {
|
|
2848
|
+
if (!Array.isArray(this._listeners[type])) {
|
|
2849
|
+
return this;
|
|
2850
|
+
}
|
|
2756
2851
|
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
* @type any
|
|
2761
|
-
* @description The event data
|
|
2762
|
-
*/
|
|
2852
|
+
for (var args = [], i = 1; i < arguments.length; i += 1) {
|
|
2853
|
+
args[i - 1] = arguments[i];
|
|
2854
|
+
}
|
|
2763
2855
|
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
* as two positional arguments, or as a single object.
|
|
2768
|
-
* @param {string|Event} evtObjOrName
|
|
2769
|
-
* @param {any=} optionalData
|
|
2770
|
-
* @emits scion.BaseInterpreter#onEntry
|
|
2771
|
-
* @emits scion.BaseInterpreter#onExit
|
|
2772
|
-
* @emits scion.BaseInterpreter#onTransition
|
|
2773
|
-
* @emits scion.BaseInterpreter#onDefaultEntry
|
|
2774
|
-
* @emits scion.BaseInterpreter#onError
|
|
2775
|
-
* @emits scion.BaseInterpreter#onBigStepBegin
|
|
2776
|
-
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2777
|
-
* @emits scion.BaseInterpreter#onBigStepSuspend
|
|
2778
|
-
* @emits scion.BaseInterpreter#onBigStepResume
|
|
2779
|
-
* @emits scion.BaseInterpreter#onSmallStepBegin
|
|
2780
|
-
* @emits scion.BaseInterpreter#onSmallStepEnd
|
|
2781
|
-
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2782
|
-
* @emits scion.BaseInterpreter#onExitInterpreter
|
|
2783
|
-
*/
|
|
2856
|
+
this._listeners[type].forEach(function __emit(listener) {
|
|
2857
|
+
listener.apply(this, args);
|
|
2858
|
+
}, this);
|
|
2784
2859
|
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
value: function gen(evtObjOrName, optionalData) {
|
|
2788
|
-
var currentEvent;
|
|
2789
|
-
switch (typeof evtObjOrName === 'undefined' ? 'undefined' : _typeof(evtObjOrName)) {
|
|
2790
|
-
case 'string':
|
|
2791
|
-
currentEvent = { name: evtObjOrName, data: optionalData };
|
|
2792
|
-
break;
|
|
2793
|
-
case 'object':
|
|
2794
|
-
if (typeof evtObjOrName.name === 'string') {
|
|
2795
|
-
currentEvent = evtObjOrName;
|
|
2796
|
-
} else {
|
|
2797
|
-
throw new Error('Event object must have "name" property of type string.');
|
|
2798
|
-
}
|
|
2799
|
-
break;
|
|
2800
|
-
default:
|
|
2801
|
-
throw new Error('First argument to gen must be a string or object.');
|
|
2802
|
-
}
|
|
2860
|
+
return this;
|
|
2861
|
+
};
|
|
2803
2862
|
|
|
2804
|
-
|
|
2863
|
+
module.exports.EventEmitter = EventEmitter;
|
|
2864
|
+
}, {}], 7: [function (require, module, exports) {
|
|
2865
|
+
(function (setImmediate) {
|
|
2866
|
+
'use strict';
|
|
2805
2867
|
|
|
2806
|
-
|
|
2807
|
-
|
|
2868
|
+
var _createClass = function () {
|
|
2869
|
+
function defineProperties(target, props) {
|
|
2870
|
+
for (var i = 0; i < props.length; i++) {
|
|
2871
|
+
var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
2872
|
+
}
|
|
2873
|
+
}return function (Constructor, protoProps, staticProps) {
|
|
2874
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
2875
|
+
};
|
|
2876
|
+
}();
|
|
2808
2877
|
|
|
2809
|
-
|
|
2878
|
+
function _toConsumableArray(arr) {
|
|
2879
|
+
if (Array.isArray(arr)) {
|
|
2880
|
+
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
|
|
2881
|
+
arr2[i] = arr[i];
|
|
2882
|
+
}return arr2;
|
|
2883
|
+
} else {
|
|
2884
|
+
return Array.from(arr);
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2810
2887
|
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2888
|
+
function _classCallCheck(instance, Constructor) {
|
|
2889
|
+
if (!(instance instanceof Constructor)) {
|
|
2890
|
+
throw new TypeError("Cannot call a class as a function");
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2814
2893
|
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
* @emits scion.BaseInterpreter#onExit
|
|
2821
|
-
* @emits scion.BaseInterpreter#onTransition
|
|
2822
|
-
* @emits scion.BaseInterpreter#onDefaultEntry
|
|
2823
|
-
* @emits scion.BaseInterpreter#onError
|
|
2824
|
-
* @emits scion.BaseInterpreter#onBigStepBegin
|
|
2825
|
-
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2826
|
-
* @emits scion.BaseInterpreter#onBigStepSuspend
|
|
2827
|
-
* @emits scion.BaseInterpreter#onBigStepResume
|
|
2828
|
-
* @emits scion.BaseInterpreter#onSmallStepBegin
|
|
2829
|
-
* @emits scion.BaseInterpreter#onSmallStepEnd
|
|
2830
|
-
* @emits scion.BaseInterpreter#onBigStepEnd
|
|
2831
|
-
* @emits scion.BaseInterpreter#onExitInterpreter
|
|
2832
|
-
*/
|
|
2894
|
+
function _possibleConstructorReturn(self, call) {
|
|
2895
|
+
if (!self) {
|
|
2896
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
2897
|
+
}return call && ((typeof call === "undefined" ? "undefined" : _typeof2(call)) === "object" || typeof call === "function") ? call : self;
|
|
2898
|
+
}
|
|
2833
2899
|
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2900
|
+
function _inherits(subClass, superClass) {
|
|
2901
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
2902
|
+
throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === "undefined" ? "undefined" : _typeof2(superClass)));
|
|
2903
|
+
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
var base = require('@scion-scxml/core-base'),
|
|
2907
|
+
helpers = base.helpers,
|
|
2908
|
+
query = base.query,
|
|
2909
|
+
transitionComparator = base.helpers.transitionComparator;
|
|
2910
|
+
|
|
2911
|
+
/**
|
|
2912
|
+
* @description Implements semantics described in Algorithm D of the SCXML specification.
|
|
2913
|
+
* See {@link scion.BaseInterpreter} for information on the constructor arguments.
|
|
2914
|
+
* @class SCInterpreter
|
|
2915
|
+
* @extends BaseInterpreter
|
|
2916
|
+
*/
|
|
2840
2917
|
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
}
|
|
2918
|
+
var Statechart = function (_base$BaseInterpreter) {
|
|
2919
|
+
_inherits(Statechart, _base$BaseInterpreter);
|
|
2844
2920
|
|
|
2845
|
-
|
|
2921
|
+
function Statechart(modelOrModelFactory, opts) {
|
|
2922
|
+
_classCallCheck(this, Statechart);
|
|
2846
2923
|
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
this._performBigStepAsync(e, function (err, config) {
|
|
2850
|
-
c(err, config);
|
|
2924
|
+
opts = opts || {};
|
|
2925
|
+
opts.legacySemantics = false;
|
|
2851
2926
|
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
} else {
|
|
2855
|
-
this._isStepping = false;
|
|
2856
|
-
}
|
|
2857
|
-
}.bind(this));
|
|
2858
|
-
}
|
|
2859
|
-
if (!this._isStepping) {
|
|
2860
|
-
this._isStepping = true;
|
|
2861
|
-
nextStep.apply(this, this._externalEventQueue.shift());
|
|
2862
|
-
}
|
|
2863
|
-
}
|
|
2864
|
-
}]);
|
|
2927
|
+
return _possibleConstructorReturn(this, (Statechart.__proto__ || Object.getPrototypeOf(Statechart)).call(this, modelOrModelFactory, opts));
|
|
2928
|
+
}
|
|
2865
2929
|
|
|
2866
|
-
|
|
2867
|
-
}(EventEmitter);
|
|
2930
|
+
/** @private */
|
|
2868
2931
|
|
|
2869
|
-
|
|
2932
|
+
_createClass(Statechart, [{
|
|
2933
|
+
key: '_selectTransitions',
|
|
2934
|
+
value: function _selectTransitions(currentEvent, selectEventlessTransitions) {
|
|
2935
|
+
var transitionSelector = this.opts.transitionSelector;
|
|
2936
|
+
var enabledTransitions = new this.opts.Set();
|
|
2870
2937
|
|
|
2871
|
-
|
|
2872
|
-
BaseInterpreter.sessionIdCounter = 1;
|
|
2873
|
-
BaseInterpreter.generateSessionid = function () {
|
|
2874
|
-
return BaseInterpreter.sessionIdCounter++;
|
|
2875
|
-
};
|
|
2876
|
-
BaseInterpreter.sessionRegistry = new Map();
|
|
2938
|
+
var e = this._evaluateAction.bind(this, currentEvent);
|
|
2877
2939
|
|
|
2878
|
-
|
|
2940
|
+
var atomicStates = this._configuration.iter().sort(transitionComparator);
|
|
2941
|
+
var _iteratorNormalCompletion = true;
|
|
2942
|
+
var _didIteratorError = false;
|
|
2943
|
+
var _iteratorError = undefined;
|
|
2879
2944
|
|
|
2880
|
-
|
|
2945
|
+
try {
|
|
2946
|
+
for (var _iterator = atomicStates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
2947
|
+
var state = _step.value;
|
|
2948
|
+
var _iteratorNormalCompletion2 = true;
|
|
2949
|
+
var _didIteratorError2 = false;
|
|
2950
|
+
var _iteratorError2 = undefined;
|
|
2881
2951
|
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2952
|
+
try {
|
|
2953
|
+
loop: for (var _iterator2 = [state].concat(query.getAncestors(state))[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
2954
|
+
var s = _step2.value;
|
|
2955
|
+
var _iteratorNormalCompletion3 = true;
|
|
2956
|
+
var _didIteratorError3 = false;
|
|
2957
|
+
var _iteratorError3 = undefined;
|
|
2885
2958
|
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
this._timeouts = new Set();
|
|
2959
|
+
try {
|
|
2960
|
+
for (var _iterator3 = s.transitions[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
2961
|
+
var t = _step3.value;
|
|
2890
2962
|
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2963
|
+
if (transitionSelector(t, currentEvent, e, selectEventlessTransitions)) {
|
|
2964
|
+
enabledTransitions.add(t);
|
|
2965
|
+
break loop;
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
} catch (err) {
|
|
2969
|
+
_didIteratorError3 = true;
|
|
2970
|
+
_iteratorError3 = err;
|
|
2971
|
+
} finally {
|
|
2972
|
+
try {
|
|
2973
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
2974
|
+
_iterator3.return();
|
|
2975
|
+
}
|
|
2976
|
+
} finally {
|
|
2977
|
+
if (_didIteratorError3) {
|
|
2978
|
+
throw _iteratorError3;
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
} catch (err) {
|
|
2984
|
+
_didIteratorError2 = true;
|
|
2985
|
+
_iteratorError2 = err;
|
|
2986
|
+
} finally {
|
|
2987
|
+
try {
|
|
2988
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
2989
|
+
_iterator2.return();
|
|
2990
|
+
}
|
|
2991
|
+
} finally {
|
|
2992
|
+
if (_didIteratorError2) {
|
|
2993
|
+
throw _iteratorError2;
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
} catch (err) {
|
|
2999
|
+
_didIteratorError = true;
|
|
3000
|
+
_iteratorError = err;
|
|
3001
|
+
} finally {
|
|
3002
|
+
try {
|
|
3003
|
+
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
3004
|
+
_iterator.return();
|
|
3005
|
+
}
|
|
3006
|
+
} finally {
|
|
3007
|
+
if (_didIteratorError) {
|
|
3008
|
+
throw _iteratorError;
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
2895
3012
|
|
|
2896
|
-
|
|
2897
|
-
this.scxmlSendTargetRegex = /^#_scxml_(.*)$/;
|
|
2898
|
-
}
|
|
3013
|
+
var priorityEnabledTransitions = this._removeConflictingTransition(enabledTransitions);
|
|
2899
3014
|
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
this._installDefaultPropsOnEvent(event, true);
|
|
2904
|
-
this._interpreter._internalEventQueue.push(event);
|
|
2905
|
-
}
|
|
2906
|
-
}, {
|
|
2907
|
-
key: 'parseXmlStringAsDOM',
|
|
2908
|
-
value: function parseXmlStringAsDOM(xmlString) {
|
|
2909
|
-
return (this._interpreter.opts.xmlParser || InterpreterScriptingContext.xmlParser).parse(xmlString);
|
|
3015
|
+
this._log("priorityEnabledTransitions", priorityEnabledTransitions);
|
|
3016
|
+
|
|
3017
|
+
return priorityEnabledTransitions;
|
|
2910
3018
|
}
|
|
2911
|
-
}, {
|
|
2912
|
-
key: 'invoke',
|
|
2913
|
-
value: function invoke(invokeObj) {
|
|
2914
|
-
var _this10 = this;
|
|
2915
3019
|
|
|
2916
|
-
|
|
2917
|
-
this._invokeMap[invokeObj.id] = new Promise(function (resolve, reject) {
|
|
2918
|
-
(_this10._interpreter.opts.invokers || InterpreterScriptingContext.invokers)[invokeObj.type](_this10._interpreter, invokeObj, _this10._interpreter.opts.invokerExecutionContext, function (err, session) {
|
|
2919
|
-
if (err) return reject(err);
|
|
3020
|
+
/** @private */
|
|
2920
3021
|
|
|
2921
|
-
_this10._interpreter.emit('onInvokedSessionInitialized', session);
|
|
2922
|
-
resolve(session);
|
|
2923
|
-
});
|
|
2924
|
-
});
|
|
2925
|
-
}
|
|
2926
3022
|
}, {
|
|
2927
|
-
key: '
|
|
2928
|
-
value: function
|
|
2929
|
-
var
|
|
3023
|
+
key: '_removeConflictingTransition',
|
|
3024
|
+
value: function _removeConflictingTransition(enabledTransitions) {
|
|
3025
|
+
var _this2 = this;
|
|
2930
3026
|
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
sessionPromise.then(function (session) {
|
|
2937
|
-
_this11._interpreter._log('resolved session ' + invokeid + '. cancelling... ');
|
|
2938
|
-
session.cancel();
|
|
2939
|
-
//clean up
|
|
2940
|
-
delete _this11._invokeMap[invokeid];
|
|
2941
|
-
}, function (err) {
|
|
2942
|
-
//TODO: dispatch error back into the state machine as error.communication
|
|
2943
|
-
});
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
}, {
|
|
2947
|
-
key: '_installDefaultPropsOnEvent',
|
|
2948
|
-
value: function _installDefaultPropsOnEvent(event, isInternal) {
|
|
2949
|
-
if (!isInternal) {
|
|
2950
|
-
event.origin = this._interpreter.opts._x._ioprocessors.scxml.location; //TODO: preserve original origin when we autoforward?
|
|
2951
|
-
event.origintype = event.type || SCXML_IOPROCESSOR_TYPE;
|
|
2952
|
-
}
|
|
2953
|
-
if (typeof event.type === 'undefined') {
|
|
2954
|
-
event.type = isInternal ? 'internal' : 'external';
|
|
2955
|
-
}
|
|
2956
|
-
['name', 'sendid', 'invokeid', 'data', 'origin', 'origintype'].forEach(function (prop) {
|
|
2957
|
-
if (typeof event[prop] === 'undefined') {
|
|
2958
|
-
event[prop] = undefined;
|
|
2959
|
-
}
|
|
2960
|
-
});
|
|
2961
|
-
}
|
|
2962
|
-
}, {
|
|
2963
|
-
key: 'send',
|
|
2964
|
-
value: function send(event, options) {
|
|
2965
|
-
this._interpreter._log('send event', event, options);
|
|
2966
|
-
options = options || {};
|
|
2967
|
-
var sendType = options.type || SCXML_IOPROCESSOR_TYPE;
|
|
2968
|
-
//TODO: move these out
|
|
2969
|
-
function validateSend(event, options, sendAction) {
|
|
2970
|
-
if (event.target) {
|
|
2971
|
-
var targetIsValidUri = this.validateUriRegex.test(event.target);
|
|
2972
|
-
if (!targetIsValidUri) {
|
|
2973
|
-
throw { name: "error.execution", data: 'Target is not valid URI', sendid: event.sendid, type: 'platform' };
|
|
2974
|
-
}
|
|
2975
|
-
}
|
|
2976
|
-
if (sendType !== SCXML_IOPROCESSOR_TYPE) {
|
|
2977
|
-
//TODO: extend this to support HTTP, and other IO processors
|
|
2978
|
-
throw { name: "error.execution", data: 'Unsupported event processor type', sendid: event.sendid, type: 'platform' };
|
|
2979
|
-
}
|
|
3027
|
+
var filteredTransitions = new this.opts.Set();
|
|
3028
|
+
//toList sorts the transitions in the order of the states that selected them
|
|
3029
|
+
var _iteratorNormalCompletion4 = true;
|
|
3030
|
+
var _didIteratorError4 = false;
|
|
3031
|
+
var _iteratorError4 = undefined;
|
|
2980
3032
|
|
|
2981
|
-
|
|
2982
|
-
|
|
3033
|
+
try {
|
|
3034
|
+
for (var _iterator4 = enabledTransitions.iter()[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
3035
|
+
var t1 = _step4.value;
|
|
2983
3036
|
|
|
2984
|
-
|
|
2985
|
-
|
|
3037
|
+
var t1Preempted = false;
|
|
3038
|
+
var transitionsToRemove = new Set();
|
|
3039
|
+
var _iteratorNormalCompletion5 = true;
|
|
3040
|
+
var _didIteratorError5 = false;
|
|
3041
|
+
var _iteratorError5 = undefined;
|
|
2986
3042
|
|
|
2987
|
-
|
|
3043
|
+
try {
|
|
3044
|
+
var _loop = function _loop() {
|
|
3045
|
+
var t2 = _step5.value;
|
|
3046
|
+
|
|
3047
|
+
//TODO: can we compute this statically? for example, by checking if the transition scopes are arena orthogonal?
|
|
3048
|
+
var t1ExitSet = _this2._computeExitSet([t1]);
|
|
3049
|
+
var t2ExitSet = _this2._computeExitSet([t2]);
|
|
3050
|
+
var hasIntersection = [].concat(_toConsumableArray(t1ExitSet)).some(function (s) {
|
|
3051
|
+
return t2ExitSet.has(s);
|
|
3052
|
+
}) || [].concat(_toConsumableArray(t2ExitSet)).some(function (s) {
|
|
3053
|
+
return t1ExitSet.has(s);
|
|
3054
|
+
});
|
|
3055
|
+
_this2._log('t1ExitSet', t1.source.id, [].concat(_toConsumableArray(t1ExitSet)).map(function (s) {
|
|
3056
|
+
return s.id;
|
|
3057
|
+
}));
|
|
3058
|
+
_this2._log('t2ExitSet', t2.source.id, [].concat(_toConsumableArray(t2ExitSet)).map(function (s) {
|
|
3059
|
+
return s.id;
|
|
3060
|
+
}));
|
|
3061
|
+
_this2._log('hasIntersection', hasIntersection);
|
|
3062
|
+
if (hasIntersection) {
|
|
3063
|
+
if (t2.source.descendants.indexOf(t1.source) > -1) {
|
|
3064
|
+
//is this the same as being ancestrally related?
|
|
3065
|
+
transitionsToRemove.add(t2);
|
|
3066
|
+
} else {
|
|
3067
|
+
t1Preempted = true;
|
|
3068
|
+
return 'break';
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
};
|
|
3072
|
+
|
|
3073
|
+
for (var _iterator5 = filteredTransitions.iter()[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
3074
|
+
var _ret = _loop();
|
|
2988
3075
|
|
|
2989
|
-
|
|
2990
|
-
if (event.target === '#_internal') {
|
|
2991
|
-
this.raise(event);
|
|
2992
|
-
} else {
|
|
2993
|
-
this._installDefaultPropsOnEvent(event, false);
|
|
2994
|
-
event.origintype = SCXML_IOPROCESSOR_TYPE; //TODO: extend this to support HTTP, and other IO processors
|
|
2995
|
-
//TODO : paramterize this based on send/@type?
|
|
2996
|
-
if (!event.target) {
|
|
2997
|
-
doSend.call(this, this._interpreter);
|
|
2998
|
-
} else if (event.target === '#_parent') {
|
|
2999
|
-
if (this._interpreter.opts.parentSession) {
|
|
3000
|
-
event.invokeid = this._interpreter.opts.invokeid;
|
|
3001
|
-
doSend.call(this, this._interpreter.opts.parentSession);
|
|
3002
|
-
} else {
|
|
3003
|
-
throw { name: "error.communication", data: 'Parent session not specified', sendid: event.sendid, type: 'platform' };
|
|
3076
|
+
if (_ret === 'break') break;
|
|
3004
3077
|
}
|
|
3005
|
-
}
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3078
|
+
} catch (err) {
|
|
3079
|
+
_didIteratorError5 = true;
|
|
3080
|
+
_iteratorError5 = err;
|
|
3081
|
+
} finally {
|
|
3082
|
+
try {
|
|
3083
|
+
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
|
3084
|
+
_iterator5.return();
|
|
3085
|
+
}
|
|
3086
|
+
} finally {
|
|
3087
|
+
if (_didIteratorError5) {
|
|
3088
|
+
throw _iteratorError5;
|
|
3089
|
+
}
|
|
3012
3090
|
}
|
|
3013
|
-
} else if (match = event.target.match(this.invokeSendTargetRegex)) {
|
|
3014
|
-
//TODO: test this code path.
|
|
3015
|
-
var invokeId = match[1];
|
|
3016
|
-
this._invokeMap[invokeId].then(function (session) {
|
|
3017
|
-
doSend.call(_this12, session);
|
|
3018
|
-
});
|
|
3019
|
-
} else {
|
|
3020
|
-
throw new Error('Unrecognized send target.'); //TODO: dispatch error back into the state machine
|
|
3021
3091
|
}
|
|
3022
|
-
}
|
|
3023
3092
|
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
var timeoutHandle = setTimeout(function () {
|
|
3029
|
-
if (event.sendid) delete this._timeoutMap[event.sendid];
|
|
3030
|
-
this._timeouts.delete(timeoutOptions);
|
|
3031
|
-
if (this._interpreter.opts.doSend) {
|
|
3032
|
-
this._interpreter.opts.doSend(session, event);
|
|
3033
|
-
} else {
|
|
3034
|
-
session[this._interpreter.opts.sendAsync ? 'genAsync' : 'gen'](event);
|
|
3035
|
-
}
|
|
3036
|
-
}.bind(this), options.delay || 0);
|
|
3093
|
+
if (!t1Preempted) {
|
|
3094
|
+
var _iteratorNormalCompletion6 = true;
|
|
3095
|
+
var _didIteratorError6 = false;
|
|
3096
|
+
var _iteratorError6 = undefined;
|
|
3037
3097
|
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
};
|
|
3042
|
-
if (event.sendid) this._timeoutMap[event.sendid] = timeoutHandle;
|
|
3043
|
-
this._timeouts.add(timeoutOptions);
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3098
|
+
try {
|
|
3099
|
+
for (var _iterator6 = transitionsToRemove[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
3100
|
+
var t3 = _step6.value;
|
|
3046
3101
|
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3102
|
+
filteredTransitions.remove(t3);
|
|
3103
|
+
}
|
|
3104
|
+
} catch (err) {
|
|
3105
|
+
_didIteratorError6 = true;
|
|
3106
|
+
_iteratorError6 = err;
|
|
3107
|
+
} finally {
|
|
3108
|
+
try {
|
|
3109
|
+
if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
|
3110
|
+
_iterator6.return();
|
|
3111
|
+
}
|
|
3112
|
+
} finally {
|
|
3113
|
+
if (_didIteratorError6) {
|
|
3114
|
+
throw _iteratorError6;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3050
3118
|
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3119
|
+
filteredTransitions.add(t1);
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
} catch (err) {
|
|
3123
|
+
_didIteratorError4 = true;
|
|
3124
|
+
_iteratorError4 = err;
|
|
3125
|
+
} finally {
|
|
3126
|
+
try {
|
|
3127
|
+
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
|
3128
|
+
_iterator4.return();
|
|
3129
|
+
}
|
|
3130
|
+
} finally {
|
|
3131
|
+
if (_didIteratorError4) {
|
|
3132
|
+
throw _iteratorError4;
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3060
3135
|
}
|
|
3061
3136
|
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
this._interpreter._log("sending event", event.name, "with content", event.data, "after delay", options.delay);
|
|
3065
|
-
|
|
3066
|
-
validateSend.call(this, event, options, sendFn);
|
|
3137
|
+
return filteredTransitions;
|
|
3067
3138
|
}
|
|
3068
|
-
}
|
|
3069
|
-
key: 'cancel',
|
|
3070
|
-
value: function cancel(sendid) {
|
|
3071
|
-
if (this._interpreter.opts.customCancel) {
|
|
3072
|
-
return this._interpreter.opts.customCancel.apply(this, [sendid]);
|
|
3073
|
-
}
|
|
3139
|
+
}]);
|
|
3074
3140
|
|
|
3075
|
-
|
|
3141
|
+
return Statechart;
|
|
3142
|
+
}(base.BaseInterpreter);
|
|
3076
3143
|
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3144
|
+
base.Statechart = Statechart;
|
|
3145
|
+
//simple default invoker
|
|
3146
|
+
base.InterpreterScriptingContext.invokers = {
|
|
3147
|
+
"http://www.w3.org/TR/scxml/": function httpWwwW3OrgTRScxml(invokingSession, invokeObj, invokerExecutionContext, cb) {
|
|
3148
|
+
//put invoke logic here:
|
|
3149
|
+
var method = void 0,
|
|
3150
|
+
arg = void 0;
|
|
3151
|
+
if (invokeObj.constructorFunction) {
|
|
3152
|
+
var fnModel = invokeObj.constructorFunction;
|
|
3153
|
+
var options = {
|
|
3154
|
+
invokeid: invokeObj.id,
|
|
3155
|
+
params: invokeObj.params,
|
|
3156
|
+
parentSession: invokingSession,
|
|
3157
|
+
docUrl: invokeObj.docUrl
|
|
3158
|
+
//sessionid : //TODO: construct or generate a sessionid for invoked session
|
|
3159
|
+
};
|
|
3160
|
+
var model = invokerExecutionContext;
|
|
3161
|
+
var interpreter = void 0;
|
|
3162
|
+
if (options.parentSession instanceof Statechart) {
|
|
3163
|
+
interpreter = new Statechart(fnModel, options);
|
|
3080
3164
|
}
|
|
3165
|
+
cb(null, interpreter, fnModel, model);
|
|
3166
|
+
//we introduce a delay here before starting the interpreter to give clients that are subscribed to onInvokedSessionInitialized event a chance to subscribe to events on the newly instantiated interpreter
|
|
3167
|
+
setImmediate(function () {
|
|
3168
|
+
return interpreter.start();
|
|
3169
|
+
});
|
|
3170
|
+
} else {
|
|
3171
|
+
throw new Error('Invoke object needs a constructorFunction property');
|
|
3081
3172
|
}
|
|
3082
|
-
}
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
}();
|
|
3173
|
+
}
|
|
3174
|
+
};
|
|
3175
|
+
base.InterpreterScriptingContext.invokers[undefined] = base.InterpreterScriptingContext.invokers[null] = base.InterpreterScriptingContext.invokers['scxml'] = base.InterpreterScriptingContext.invokers["http://www.w3.org/TR/scxml/"];
|
|
3086
3176
|
|
|
3087
|
-
module.exports =
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
STATE_TYPES: constants.STATE_TYPES,
|
|
3091
|
-
initializeModel: initializeModel,
|
|
3092
|
-
InterpreterScriptingContext: InterpreterScriptingContext,
|
|
3093
|
-
helpers: helpers,
|
|
3094
|
-
query: query
|
|
3095
|
-
});
|
|
3096
|
-
}).call(this, require('_process'), require("timers").setImmediate);
|
|
3097
|
-
}, { "./ArraySet": 2, "./constants": 3, "./helpers": 4, "./query": 5, "_process": 8, "timers": 9, "tiny-events": 10, "util": 12 }], 7: [function (require, module, exports) {
|
|
3177
|
+
module.exports = base;
|
|
3178
|
+
}).call(this, require("timers").setImmediate);
|
|
3179
|
+
}, { "@scion-scxml/core-base": 5, "timers": 10 }], 8: [function (require, module, exports) {
|
|
3098
3180
|
if (typeof Object.create === 'function') {
|
|
3099
3181
|
// implementation from standard node.js 'util' module
|
|
3100
3182
|
module.exports = function inherits(ctor, superCtor) {
|
|
@@ -3118,7 +3200,7 @@
|
|
|
3118
3200
|
ctor.prototype.constructor = ctor;
|
|
3119
3201
|
};
|
|
3120
3202
|
}
|
|
3121
|
-
}, {}],
|
|
3203
|
+
}, {}], 9: [function (require, module, exports) {
|
|
3122
3204
|
// shim for using process in browser
|
|
3123
3205
|
var process = module.exports = {};
|
|
3124
3206
|
|
|
@@ -3304,7 +3386,7 @@
|
|
|
3304
3386
|
process.umask = function () {
|
|
3305
3387
|
return 0;
|
|
3306
3388
|
};
|
|
3307
|
-
}, {}],
|
|
3389
|
+
}, {}], 10: [function (require, module, exports) {
|
|
3308
3390
|
(function (setImmediate, clearImmediate) {
|
|
3309
3391
|
var nextTick = require('process/browser.js').nextTick;
|
|
3310
3392
|
var apply = Function.prototype.apply;
|
|
@@ -3383,83 +3465,7 @@
|
|
|
3383
3465
|
delete immediateIds[id];
|
|
3384
3466
|
};
|
|
3385
3467
|
}).call(this, require("timers").setImmediate, require("timers").clearImmediate);
|
|
3386
|
-
}, { "process/browser.js":
|
|
3387
|
-
function EventEmitter() {
|
|
3388
|
-
this._listeners = {};
|
|
3389
|
-
}
|
|
3390
|
-
|
|
3391
|
-
EventEmitter.prototype.on = function _on(type, listener) {
|
|
3392
|
-
if (!Array.isArray(this._listeners[type])) {
|
|
3393
|
-
this._listeners[type] = [];
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
if (this._listeners[type].indexOf(listener) === -1) {
|
|
3397
|
-
this._listeners[type].push(listener);
|
|
3398
|
-
}
|
|
3399
|
-
|
|
3400
|
-
return this;
|
|
3401
|
-
};
|
|
3402
|
-
|
|
3403
|
-
EventEmitter.prototype.once = function _once(type, listener) {
|
|
3404
|
-
var self = this;
|
|
3405
|
-
|
|
3406
|
-
function __once() {
|
|
3407
|
-
for (var args = [], i = 0; i < arguments.length; i += 1) {
|
|
3408
|
-
args[i] = arguments[i];
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
self.off(type, __once);
|
|
3412
|
-
listener.apply(self, args);
|
|
3413
|
-
}
|
|
3414
|
-
|
|
3415
|
-
__once.listener = listener;
|
|
3416
|
-
|
|
3417
|
-
return this.on(type, __once);
|
|
3418
|
-
};
|
|
3419
|
-
|
|
3420
|
-
EventEmitter.prototype.off = function _off(type, listener) {
|
|
3421
|
-
if (!Array.isArray(this._listeners[type])) {
|
|
3422
|
-
return this;
|
|
3423
|
-
}
|
|
3424
|
-
|
|
3425
|
-
if (typeof listener === 'undefined') {
|
|
3426
|
-
this._listeners[type] = [];
|
|
3427
|
-
return this;
|
|
3428
|
-
}
|
|
3429
|
-
|
|
3430
|
-
var index = this._listeners[type].indexOf(listener);
|
|
3431
|
-
|
|
3432
|
-
if (index === -1) {
|
|
3433
|
-
for (var i = 0; i < this._listeners[type].length; i += 1) {
|
|
3434
|
-
if (this._listeners[type][i].listener === listener) {
|
|
3435
|
-
index = i;
|
|
3436
|
-
break;
|
|
3437
|
-
}
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3440
|
-
|
|
3441
|
-
this._listeners[type].splice(index, 1);
|
|
3442
|
-
return this;
|
|
3443
|
-
};
|
|
3444
|
-
|
|
3445
|
-
EventEmitter.prototype.emit = function _emit(type) {
|
|
3446
|
-
if (!Array.isArray(this._listeners[type])) {
|
|
3447
|
-
return this;
|
|
3448
|
-
}
|
|
3449
|
-
|
|
3450
|
-
for (var args = [], i = 1; i < arguments.length; i += 1) {
|
|
3451
|
-
args[i - 1] = arguments[i];
|
|
3452
|
-
}
|
|
3453
|
-
|
|
3454
|
-
this._listeners[type].forEach(function __emit(listener) {
|
|
3455
|
-
listener.apply(this, args);
|
|
3456
|
-
}, this);
|
|
3457
|
-
|
|
3458
|
-
return this;
|
|
3459
|
-
};
|
|
3460
|
-
|
|
3461
|
-
module.exports.EventEmitter = EventEmitter;
|
|
3462
|
-
}, {}], 11: [function (require, module, exports) {
|
|
3468
|
+
}, { "process/browser.js": 9, "timers": 10 }], 11: [function (require, module, exports) {
|
|
3463
3469
|
module.exports = function isBuffer(arg) {
|
|
3464
3470
|
return arg && (typeof arg === "undefined" ? "undefined" : _typeof2(arg)) === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function';
|
|
3465
3471
|
};
|
|
@@ -4010,7 +4016,7 @@
|
|
|
4010
4016
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
4011
4017
|
}
|
|
4012
4018
|
}).call(this, require('_process'), typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
|
|
4013
|
-
}, { "./support/isBuffer": 11, "_process":
|
|
4019
|
+
}, { "./support/isBuffer": 11, "_process": 9, "inherits": 8 }] }, {}, [7])(7);
|
|
4014
4020
|
});
|
|
4015
4021
|
});
|
|
4016
4022
|
//# sourceMappingURL=core.js.map
|