-
Notifications
You must be signed in to change notification settings - Fork 0
/
serenix_module.js
1483 lines (1421 loc) · 50.1 KB
/
serenix_module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* The MIT License
*
* Copyright 2020-2021 Marc KAMGA Olivier (kamga_marco@yahoo.com;mkamga.olivier@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* For dynamic modules loading, serenix_js_load.js must first of all loaded
* @doc
*/
//require serenix_js_load.js
if (typeof inBrowser === 'undefined') {
/**
* True value specifies that we are runing in a brower.
* @type Boolean
*/
var inBrowser = typeof window !== 'undefined';
}
/**
* The global namespace/this.
* <ul>
* <li>When runing in a browser, the value is window global variable.</li>
* <li>When not runing in a browser, global value window will be setted to and the value of global variable (global||self||this) will be setted to window.</li>
* </ul>
* @type Object
*/
var globalNS = typeof window ==="undefined"
? typeof global!=="undefined"
? global : typeof self!=="undefined" ? self: this
: window;
if (typeof isArray !== 'function')
isArray = Array.isArray;
/**
*
* @param {Object} o The object
* @param {String} n Property name
* @returns {Boolean}
*/
function hasOwnProp(o, n) {
return Object.prototype.hasOwnProperty.call(o, n);
}
/**
* Check if the given value is a plain object: <b>an object that is not an array
* nor a function</b>.
* Returns <b color="blue">true</b> if it's a plain object and
* <b color="blue">false</b> otherwise.
*
* @param {*} val The value to check if it's a plain object
* @returns {Boolean}
*/
function isPlainObject(val) {
return typeof val === 'object'
&& Object.prototype.toString.call(val) === '[object Object]';
}
/**
*
* @param {Object} o
* @param {String} [valueType]
* @returns {Boolean|Array}
*/
function pairKeys(o, valueType) {
if (isArray(o)) {
if (o.length !== 2) {
return null;
}
return isOfType(o[1], valueType) ? [0, 1] : null;
}
var keys = Object.keys(o), name, val;
if (keys.length !== 2) {
return null;
}
if (keys.indexOf(name= "name") >= 0 || keys.indexOf(name="Name") >= 0 || keys.indexOf(name= "key") >= 0 || keys.indexOf(name="Key") >= 0) {
if (keys.indexOf("value") >= 0) {
val = "value";
} else if (keys.indexOf("Value") >= 0) {
val = "value";
} else if (keys.indexOf("object") >= 0) {
val = "object";
} else if (keys.indexOf("Object") >= 0) {
val = "Object";
} else {
return null;
}
} else {
return null;
}
return isOfType(o[val], valueType) ? [name, val] : false;
}
/**
*
* @param {type} v
* @param {String|Function} type
* @returns {Boolean}
*/
function isOfType(v, type) {
if (type instanceof Function) {
type = type.valueOf();
}
if (typeof type === 'function') {
if (!(v instanceof type)) {
return false;
}
} else if (type === 'array' || type === 'Array') {
if (!isArray(v)) {
return false;
}
} else if (type) {
if (Object.prototype.toString.call(v) !== '[object ' + type + ']') {
var ltyp = type.toLowerCase();
if (typeof v !== ltyp) {
return false;
}
}
}
return true;
}
var ofType = isOfType;
var isTypeOf = isOfType;
/**
*
* @param {type} arr
* @param {type} n
* @returns {Boolean|Array}
*/
function isPairs(arr, n) {
if (arguments.length < 2) {
n = arr.length;
}
var keys,name, val;
for (var i = 0; i < n; i++) {
keys = Object.keys(arr[i]);
if (keys.length === 2) {
if (!name) {
if (keys.indexOf("name") >= 0) {
name = "name";
if (keys.indexOf("value") >= 0) {
val = "value";
} else if (keys.indexOf("Value") >= 0) {
val = "value";
} else if (keys.indexOf("object") >= 0) {
val = "object";
} else if (keys.indexOf("Object") >= 0) {
val = "Object";
} else {
return false;
}
} else if (keys.indexOf("Name") >= 0) {
name = "Name";
if (keys.indexOf("value") >= 0) {
val = "value";
} else if (keys.indexOf("Value") >= 0) {
val = "value";
} else if (keys.indexOf("object") >= 0) {
val = "object";
} else if (keys.indexOf("Object") >= 0) {
val = "Object";
} else {
return false;
}
} else {
return false;
}
} else {
if (keys.indexOf(name) < 0) {
return false;
}
if (keys.indexOf(val) < 0) {
return false;
}
break;
}
} else {
return true;
}
}
if (name) {
return [name, val];
}
}
if (!globalNS.DEFAULT_MODULE_EXTENSION) {
/**
* The default module extension: starts with '.' character
* @type String
*/
globalNS.DEFAULT_MODULE_EXTENSION = ".js";
}
/**
* The modules container.
* @type type
*/
var modules = { __bindings___: {}};
(function() {
/**
*
* @param {String} m
* @returns {Module}
* @class Module
*/
function Module(m) {
if (!(this instanceof Module)) {
return new Module(m);
}
if (m instanceof String) {
m = m.valueOf();
}
this.__map__ = {};
if (typeof m === 'string') {
if (modules.__bindings___[m]) {
throw new Error("Module already exists with the same name: '" + m + "'");
}
this._name = m;
modules.__bindings___[m] = this;
}
}
var M = Module;
/**
* Returns the class full name.
* @returns {String}
*/
M.getFullClassName = function() {
return "modules.Module";
};
Object.defineProperty(M, 'fullClassName', {get: M.getFullClassName, set: function() { throw new Error("Read only property"); }});
/**
*
* @type Function
*/
M.__CLASS__ = M;
/**
* @type String
*/
M.__CLASS_NAME__ = "Module";
var p = M.prototype;
/**
*
* @type Function
*/
p.__CLASS__ = M;
/**
* @type String
*/
p.__CLASS_NAME__ = "Module";
/**
* <p>Exports the given value/object if the variable name is specified or can be
* extracted from the class or function (when the first argument value is a
* class or a function) or exports export object entries as module
* variables.</p>
* <p>To mimic javascript es6 declaration export, invoke this import method
* with a plain object. In this case, each entry will be individually exported
* as a module variable with the key as variable name and the entry value as
* the value of the variable.</p>
* @param {type} e What to export (function, Object, value, array, ...) or
* object to export entries a module variables.
* @param {String|Boolean} [alias]
* <ul>
* <li>When the value is true, it specify that it's a default export: the value
* of the first argument is exported with the 'default' name.</li>
* <li>When alias is a string and the argument key is true, the value of the
* first argument is exported with the valueof e[alias] as name.</li>
* </ul>
* @param {Boolean} [key=false]
* @returns {Module}
*/
p.export = function(e, alias, key) {
function put(name, e, self) {
self.__map__[name] = e;
function _get() {
return this.__map__[_get.__name__];
}
_get.__name__ = name;
Object.defineProperty(self, name , {
get : _get,
set : function() { throw new Error("Read only property"); }
});
}
var name;
if (arguments.length > 2 && key) {
if (typeof e !== 'object' && typeof e !== 'function') {
throw new Error("Incorrect arguments: when the argument key is true, the first argument must be a plain object or a class or a function");
}
key = "" + alias;
name = e[key]||"";
} else {
if (alias instanceof String || alias instanceof Boolean) {
alias = alias.valueOf();
} else if (arguments.length > 1 && typeof alias !== 'string') {
throw new Error("Incorrect arguments");
}
if (alias === true) {
alias = 'default';
}
if (alias) {
if (typeof alias !== 'string') {
throw new Error("Incorrect alias argument: expected string");
}
name = alias;
} else if (isPlainObject(e)) {
for (var k in e) {
if (hasOwnProp(e, k)) {
put(k, e[k], this);
}
}
return this;
} else {
if (typeof e === 'function' || e instanceof Function) {
if (e.__CLASS__ === e) {
if (typeof e.getClassFullName === 'function') {
name = e.getClassFullName();
} else if (typeof e.getFullClassName === 'function') {
name = e.getFullClassName();
} else if (typeof e.getFullName === 'function') {
name = e.getFullName();
} else if (e.__CLASS_FULL_NAME__) {
name = e.__CLASS_FULL_NAME__;
} else if (e.__FULL_NAME__) {
name = e.__FULL_NAME__;
} else if (e.__CLASS_NAME__) {
name = e.__CLASS_NAME__;
} else if (e.__NAME__) {
name = e.__NAME__;
}
if (!name) {
name = e.name;
}
} else {
name = e.name;
if (!name) {
if (e.__CLASS__ && e.__CLASS__ !== e) {
var c = e.__CLASS__;
name = c.__CLASS_NAME__||c.__NAME__||c.CLASS_NAME||c.NAME||c.className||c.ClassName||c.name||c.Name;
}
}
}
}
if (!name) {
name = "default";
}
}
}
put(name, e, this);
return this;
};
/**
*
* @param {Object|Array} e
* @returns {undefined}
*/
p.exportAll = function(e) {
if (arguments.length > 1) {
e = [].slice.call(arguments);
}
if (isPlainObject(e)) {
for (var name in e) {
if (hasOwnProp(e, name)) {
this.export(e[name], name);
}
}
} else if (isArray(e)) {
var n = e.length, pair;
var _e = e[0];
if (isArray(_e)) {
for (var i = 0; i < n; i++) {
_e = e[i];
this.export(/* value */ _e[1], /* key */ _e[0]);
}
} else if (Object.keys(_e).length === 1) {
var key, keys;
for (var i = 0; i < n; i++) {
_e = e[i];
keys = Object.keys(_e);
if (keys.length !== 1) {
throw new Error("Incorrect argument: element/item with many keys");
}
key = keys[0];
this.export(/* value */ _e[key], key);
}
} else if ((pair = isPairs(e, n))) {
var name = pair[0], val = pair[1];
for (var i = 0; i < n; i++) {
_e = e[i];
this.export(_e[val], _e[name]);
}
} else if (typeof _e === 'string' || e instanceof String) {
n = (n - (n % 2))/2;
var name;
for (var i = 0; i < n; i++) {
name = e[2*i];
if (name instanceof String) {
name = name.valueOf();
}
if (typeof name !== 'string') {
throw new Error("Incorrect argument: string expected at index " + (2*i));
}
this.export(e[2*i + 1], name);
}
} else {
for (var i = 0; i < n; i++) {
this.export(e[i]);
}
}
}
};
/**
*
* @param {String} name
* @returns {type}
*/
p.getExport = function(name) {
return this.__map__[name];
};
/**
*
* @param {String} name
* @returns {type}
*/
p.fromName = p.getExport;
/**
*
* @param {String} name
* @returns {type}
*/
p.fromname = p.getExport;
/**
*
* @param {String} name
* @returns {type}
*/
p.forname = p.getExport;
/**
*
* @param {String} name
* @returns {type}
*/
p.get = p.getExport;
/**
*
* @param {String} name
* @returns {type}
*/
p.__get__ = p.getExport;
/**
* Computes the module name from the path and returns the computed name.
* @param {String} path
* @returns {String}
*/
M.getName = function(path) {
var name = path, ext = DEFAULT_MODULE_EXTENSION||"";
if (ext) {
if (ext[0] !== '.') {
ext = '.' + ext;
}
}
if (name.startsWith(".")) {
return ext && name.endsWith(ext) ? name.substring(0, name.length - ext.length) : name;
}
if (ext) {
if (name.endsWith(ext)) {
name = name.substring(0, name.length - ext.length);
}
}
var dirbase = modules.__dirbase__||modules.dirbase;
var pos;
if (name.startsWith(dirbase)) {
if (['/', '\\'].indexOf(name[pos = dirbase.length]) >= 0) {
return name.substring(pos + 1);
}
pos = dirbase.lastIndexOf("/");
if (pos >= 0) {
return ".." + name.substring(pos);
}
}
var tokens = dirbase.split('/'),
i = 0,
n = tokens.length,
str = "",
ofs = 0;
for (; i < n; i++) {
str = tokens[i] + "/";
if (!name.startsWith(str, ofs)) {
break;
}
ofs += str.length;
}
if (i > 0) {
str = "";
for ( i = n - i; i > 0; i--) {
str += "../";
}
return str + name.substring(ofs);
}
return name;
};
/**
* Returns the file name/path that correspond to the given module name.
* @param {String} module The module name to get the file name/path
* @returns {String}
*/
M.getFileName = function(module) {
var ext = DEFAULT_MODULE_EXTENSION||"";
if (ext) {
if (ext[0] !== '.') {
ext = '.' + ext;
}
}
return ext ? module.endsWith(ext) ? module : module + ext : module;
};
modules.Module = Module;
//Initialize the default module
new Module("default");
})();
/**
* Returns the instance of Module that corresponds to the given module name.
* <p>When there is a module with the given name it is returned; otherwise creates
* a new instance and returns it.</p>
* @param {String} name The module name to get the instanceof Module.
* @returns {Module}
*/
modules.module = function(name) {
var m = this.__bindings___[name];
if (!m) {
m = new modules.Module(name);
}
return m;
};
/**
* Exports function(s), object(s), array(s) or other value(s) to the
* module that corresponds to the javascript file/library where this method is
* called.
* <p>Below are the possible call syntaxes:</p>
* <ul>
* <li>modules.export(String e, String from)</li>
* <li>modules.export(Object e, String from)</li>
* <li>modules.export(Object e)</li>
* <li>modules.export(String from)</li>
* <li>modules.export(Object e, Object options)</li>
* <li>modules.export(Object e, Object|Array variables)</li>
* <li>modules.export(type e, String alias, Boolean key)</li>
* <li>modules.export(type e, String alias, String from)</li>
* <li>modules.export(Array e, Boolean defaultExport)</li>
* <li>modules.export(Array e, String alias)</li>
* <li>modules.export(Array e)
* <p>When modules.export is called only with one argument that is an array,
* if the array has elements with the characteristics below, each element will
* be exported individually. Otherwise, the array will be export as default:
* the module will have an entry named 'default' with the array as value.</p>
* <p><b>Characteristics of individual exports</b>:</p>
* <ul>
* <li>Element is an array of two elements with the first element of type string:
* <p></p>
* </li>
* <li>Element is an array of two elements with the first element not of
* type string and the second element of type string:
* <p></p>
* </li>
* <li>Element is an Object with two entries where the value of the entry with key 'name',
* 'Name', 'key', 'Key', 'alias' or 'Alias' is the key of the pair and the
* value of entry with 'value', 'Value', 'export', 'Export', 'exports' or
* 'Exports' represents the element(s) to export.</li>
* <li>Element is an Object with one entry:
* <p>The value of the entry is exported with the name/key of the entry as alias/name.</p>
* </li>
* </ul>
* </li>
* </ul>
* @param {String|Array|Object} e The element(s) to export or the module to export elements from
* <ul>
* <li>When one argument of type string, it represents the module to export elements from.</li>
* <li>When many arguments, it represents the element(s) to export</li>
* </ul>
* @param {String} [alias]
* @param {Boolean} [key]
* @param {String} [from] The aggregation module name : the module the
* elements to export come from
* @param {String} [module] The module name where to export. Generaly, this
* module name is not specified. In this case, the module name is computed
* from the file name/url that called the method.
* @returns {Object} modules object
*/
modules.export = function(e, alias, key, from, module) {
var variables, varsList, object, destructuring;
if (arguments.length === 2) {
var o = arguments[1];
if (e === '*') {
if (typeof o === 'string') {
from = o;
alias = "";
key = false;
} else if (isPlainObject(o)) {
alias = o.alias||o.Alias||o.identifier||o.Identifier||o.name||o.Name;
from = o.from||o.from||o.src||o.Src||"";
key = false;
}
} else {
if (isPlainObject(o)) {
from = o.from||o.From||o.aggregateFrom||o.aggFrom||o.aggModule||"";
alias = o.alias||o.Alias||o.name||o.Name||"";
key = o.key||o.Key||false;
module = o.to||o.To||o.module||o.Module||o.toModule||"";
}
if (isPlainObject(e)) {
object = e;
if (isArray(arguments[1])) {
varsList = arguments[1];
} else if (isPlainObject(arguments[1])) {
variables = arguments[1];
}
}
}
} else if (arguments.length === 3) {
if (typeof arguments[2] === 'boolean') {
from = "";
} else if (typeof key === 'Boolean') {
from = "";
key = key.valueOf();
} else if (typeof key === 'string') {
from = key;
key = false;
} else if (typeof key === 'string') {
from = key.valueOf();
key = false;
}
} else if (arguments.length > 3) {
if (typeof arguments[3] === 'boolean') {
var _from = key;
key = from;
from = _from;
} else if (arguments[3] instanceof Boolean) {
var _from = key;
key = from.valueOf();
from = _from;
} else {
if (arguments[3] instanceof String) {
from = arguments[3].valueOf();
}
if (arguments[2] instanceof String) {
key = arguments[2].valueOf();
}
if (typeof key === 'string' || typeof from === 'string') {
module = from;
from = key;
key = false;
} else if (typeof key === 'string') {
if ((object = isPlainObject(e)) && isArray(arguments[1])) {
object = e;
alias = key;
varsList = arguments[1];
if (typeof arguments[3] === 'boolean') {
destructuring = arguments[3];
} else {
destructuring = true;
}
from = null;
key = false;
variables = {};
var v, _keys, k, pkeys;
for (var i = 0, len = varsList.length; i < len; i++) {
v= varsList[i];
if (v instanceof String) {
v = v.valueOf();
if (typeof v === 'string') {
variables[v] = v;
} else if (isArray(v)) {
variables[v[0]] = v[1]||"";
} else if (isPlainObject(v)) {
_keys = Object.keys(v);
if (_keys.length === 1) {
variables[k = _keys[0]] = v[k]||"";
} else if ((pkeys = pairKeys(v, 'String'))) {
variables[v[pkeys[0]]] = String(v[pkeys[1]]);
} else {
throw new Error("Incorrect variables");
}
}
}
}
} else if (object && isPlainObject(arguments[1])) {
object = e;
alias = key;
variables = arguments[1];
if (typeof arguments[3] === 'boolean') {
destructuring = arguments[3];
} else {
destructuring = true;
}
from = null;
key = false;
} else {
object = false;
from = key;
key = false;
if (module instanceof String) {
module = module.valueOf();
}
if (typeof module !== 'string') {
module = "";
}
}
}
}
}
var Module = modules.Module;
if (!module) { //if module where to export not specify
try {
if (window.__module_name__ && typeof window.__module_name__ === 'string') {
module = window.__module_name__;
} else {
var l = null;
l.toString(); //throw exception
}
} catch(ex) { //in the catch block, computes module name that is a
//transformation of the path of the current/running
//module file
var err = new Error(), //instantiate an error to get the stack trace
stacktrace = "stacktrace",
stack = "stack",
str = "",
path; //the path of the module file
//Get the stack trace string from the instiated error
if (err.stack) {
str = err.stack||"";
} else if(stacktrace in ex) { // Opera
str = ex.stacktrace||"";
} else if(stack in ex) { // WebKit, Blink and IE10
str = ex.stack||"";
} else if (typeof e.printStacktrace === 'function') {
str = e.printStacktrace();
} else if (typeof e.printStackTrace === 'function') {
str = e.printStackTrace();
}
if (str.indexOf("://") >= 0) {
var tokens = str.split("://"),
n = tokens.length,
i = 1,
tok,
arr;
var re = /[:]\d+[:]\d+/g;
for (; i < n; i++) {
tok = tokens[i];
arr = tok.split(re);
if (arr.length > 1) {
tok = decodeURIComponent(arr[0]);
if (!path) {
path = tok;
} else if (path !== tok) {
path = tok;
break;
}
}
}
}
module = Module.getName(path); //get the module name from the path
} // end computing module name that is a transformation of the path of the current/running module file
}
var m = this.module(module); //create a Module instance
if (from) {
//get the from/source module used for aggregation
var fmod = modules.getModule(Module.getName(from)).__map__;
if (e === '*') {
for (var k in fmod) {
if (hasOwnProp(fmod, k)) {
m.export(fmod[k],k);
}
}
} else if (isArray(e)) {
var i=0, n = e.length, v;
if (n > 0) {
v=e[0];
if (isArray(v)) {
for (; i < n; i++) {
v = e[i];
m.export(fmod[v[0]], v[1]);
}
} else if (isPlainObject(v)) {
var keys = Object.keys(v), k;
if (keys.length === 1 && typeof (k = v[keys[0]]) === 'string' || k instanceof String) {
for (; i < n; i++) {
v = e[i];
keys = Object.keys(v);
k = keys[0].toString();
m.export(fmod[k], v[k]||k);
}
} else if (hasOwnProp(v, 'name')) {
var al;
for (; i < n; i++) {
v = e[i];
k = v[name];
al = v.alias||v.identifier;
m.export(fmod[k], al||k);
}
} else {
throw new Error("Incorrect exports list");
}
} else {
throw new Error("Incorrect exports list");
}
}
} else if (isPlainObject(e)) {
var al;
for (var k in e) {
al = e[k];
if (al instanceof String) {
al =al.valueOf();
}
if (typeof al !== 'string') {
throw new Error("Incorrect alias");
}
if (hasOwnProp(fmod, k)) {
m.export(fmod[k], al);
}
}
}
} else if (variables) {
if (destructuring) {
for (var k in variables) {
if (hasOwnProp(variables, k) && hasOwnProp(e, k)) {
m.export(object[k], variables[k]||k);
}
}
} else {
for (var k in e) {
if (hasOwnProp(e, k)) {
m.export(object[k], variables[k]||k);
}
}
}
} else if (alias) {
m.export(e, alias, key);
} else if (isArray(e)) {
var keys, k, ndx, msg = "incorrect export";
for (var i = 0, _e, n = e.length; i < n; i++) {
_e = e[i];
if (isArray(_e)) {
if (typeof _e[0] === 'string') {
m.export(_e[1], /*alias*/_e[0], /*key*/false);
} else if (typeof _e[1] === 'string') {
m.export(_e[0], /*alias*/_e[1], /*key*/false);
} else {
throw new Error(msg);
}
} else if (isPlainObject(_e)) {
keys = Object.keys(_e);
switch(keys.length) {
case 2:
if ((ndx = keys.indexOf(k = 'name')) >= 0
|| (ndx = keys.indexOf(k = 'Name')) >= 0
|| (ndx = keys.indexOf(k = 'key')) >= 0
|| (ndx = keys.indexOf(k = 'Key')) >= 0) {
m.export(_e[keys[ndx === 0 ? 1 : 0]], /*alias*/_e[k], /*key*/false);
} else {
throw new Error(msg);
}
break;
case 1:
m.export(_e[keys[0]], /*alias*/keys[0], /*key*/false);
break;
default:
throw new Error(msg);
}
} else if (typeof _e === 'function') {
k = _e.__CLASS_NAME__||_e.__NAME__||_e.name;
if (k) {
m.export(_e, k, false);
} else {
throw new Error(msg);
}
}
}
} else {
m.export(e);
}
return this;
};
/**
*
* @param {String} moduleName
* @returns {Object}
*/
modules.getModule = function(moduleName) {
var module = modules.__bindings___[moduleName];
if (!module) {
var jsFileName = modules.Module.getFileName(moduleName);
if (typeof jsSyncLoad === 'function') {
console.log("Loading " + jsFileName + " ..." );
//load the module's javascrip file synchronously
jsSyncLoad(jsFileName);
console.log("Loading of " + jsFileName + " ended" );
module = modules.__bindings___[moduleName];
if (!module) {
throw new Error("'" + jsFileName + "' is not a module");
}
} else {
throw new Error("The javascript file '" + jsFileName + "' not loaded");
}
}
return module;
};
(function() {
var Module = modules.Module;
function loadAndProcess(e, moduleName, ns, onSuccess, onFail) {
if (onSuccess) {
function proc() {
onSuccess(processModule(modules.__bindings___[proc.moduleName].__map__, e, ns));
}
proc.moduleName = moduleName;
asyncLoad(jsFileName, proc, onFail);
} else {
var jsFileName = Module.getFileName(moduleName);
if (typeof jsSyncLoad === 'function') {
console.log("Loading " + jsFileName + " ..." );
//load the module's javascrip file synchronously
jsSyncLoad(jsFileName);
console.log("Loading of " + jsFileName + " ended" );
module = modules.__bindings___[moduleName];
if (!module) {
throw new Error("'" + jsFileName + "' is not a module");
}
processModule(module.__map__, e, ns);
} else {
throw new Error("The javascript file '" + jsFileName + "' not loaded");
}
}
}
/**
*
* @private
* @param {type} e
* @param {type} moduleName
* @param {type} ns
* @returns {undefined}
*/
function syncLoadAndProcess(e, moduleName, ns) {
var jsFileName;
jsSyncLoad(jsFileName = Module.getFileName(moduleName));
module = modules.__bindings___[moduleName];
if (!module) {
throw new Error("'" + jsFileName + "' is not a module");
}
processModule(module.__map__, e, ns);
}
/**
*