@@ -12,6 +12,46 @@ const extensions = {
1212
1313const multipleInboundSource = factory . resource ( 'multiple-multiple-inbound.bpmn' ) . toString ( ) ;
1414
15+ class TestScripts {
16+ constructor ( ) {
17+ this . javaScripts = new Scripts ( ) ;
18+ this . scripts = new Map ( ) ;
19+ }
20+ register ( { id, type, behaviour } ) {
21+ if ( ! behaviour . conditionExpression ) return ;
22+
23+ const scriptBody = behaviour . conditionExpression . body ;
24+ const sync = ! / n e x t \( / . test ( scriptBody ) ;
25+
26+ const registered = this . javaScripts . register ( {
27+ id,
28+ type,
29+ behaviour : {
30+ conditionExpression : {
31+ ...behaviour . conditionExpression ,
32+ language : 'javascript' ,
33+ } ,
34+ } ,
35+ } ) ;
36+
37+ this . scripts . set ( id , { sync, registered } ) ;
38+ }
39+ getScript ( language , { id } ) {
40+ const { sync, registered } = this . scripts . get ( id ) ;
41+ return {
42+ execute,
43+ } ;
44+
45+ function execute ( executionContext , callback ) {
46+ if ( sync ) {
47+ const result = registered . script . runInNewContext ( executionContext ) ;
48+ return callback ( null , result ) ;
49+ }
50+ return registered . script . runInNewContext ( { ...executionContext , next : callback } ) ;
51+ }
52+ }
53+ }
54+
1555describe ( 'SequenceFlow' , ( ) => {
1656 describe ( 'properties' , ( ) => {
1757 let context ;
@@ -616,43 +656,3 @@ describe('SequenceFlow', () => {
616656 } ) ;
617657 } ) ;
618658} ) ;
619-
620- class TestScripts {
621- constructor ( ) {
622- this . javaScripts = new Scripts ( ) ;
623- this . scripts = new Map ( ) ;
624- }
625- register ( { id, type, behaviour } ) {
626- if ( ! behaviour . conditionExpression ) return ;
627-
628- const scriptBody = behaviour . conditionExpression . body ;
629- const sync = ! / n e x t \( / . test ( scriptBody ) ;
630-
631- const registered = this . javaScripts . register ( {
632- id,
633- type,
634- behaviour : {
635- conditionExpression : {
636- ...behaviour . conditionExpression ,
637- language : 'javascript' ,
638- } ,
639- } ,
640- } ) ;
641-
642- this . scripts . set ( id , { sync, registered } ) ;
643- }
644- getScript ( language , { id } ) {
645- const { sync, registered } = this . scripts . get ( id ) ;
646- return {
647- execute,
648- } ;
649-
650- function execute ( executionContext , callback ) {
651- if ( sync ) {
652- const result = registered . script . runInNewContext ( executionContext ) ;
653- return callback ( null , result ) ;
654- }
655- return registered . script . runInNewContext ( { ...executionContext , next : callback } ) ;
656- }
657- }
658- }
0 commit comments