This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 336
/
Aura.js
1437 lines (1292 loc) · 53 KB
/
Aura.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
/*
* Copyright (C) 2013 salesforce.com, inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jslint sub: true, debug: true */
// -- Aura Bootstrap ------------------------------------------------------------
if (typeof Aura !== 'undefined') {//eslint-disable-line no-use-before-define
Aura._Aura = Aura;
}
var Aura = {};
window["Aura"] = Aura;
// -- Aura inlinning bootstrap
Aura.time = window.performance && window.performance.now ? window.performance.now.bind(performance) : function(){return Date.now();};
Aura.bootstrap = {};
Aura.bootstrapMark = function (mark, value) {
this.bootstrap[mark] = value || this.time();
};
Aura.bootstrapMark('frameworkInit');
// -- Namespaces ------------------------------------------------------------
Aura.Utils = {};
Aura.Errors = {};
Aura.Context = {};
Aura.System = {};
Aura.Style = {};
Aura.Flavors = {};
Aura.Value = {};
Aura.Model = {};
Aura.Component = {};
Aura.Provider = {};
Aura.Library = {};
Aura.Event = {};
Aura.Layouts = {};
Aura.Controller = {};
Aura.Attribute = {};
Aura.Method = {};
Aura.L10n = {};
Aura.Services = {};
Aura.Storage = {};
/**
* @description This, $A, is supposed to be our ONLY window-polluting top-level variable.
* Everything else in Aura is attached to it.
*/
window['$A'] = {};
// -- Polyfills --------------------------------------------------------
// #include aura.polyfill.Array
// #include aura.polyfill.Function
// #include aura.polyfill.RequestAnimationFrame
// #include aura.polyfill.Object
// #include aura.polyfill.Json
// #include aura.polyfill.Promise
// -- Utils ------------------------------------------------------------
// #include aura.util.ExportSymbolsHelper
// #include aura.util.Style
// #include aura.util.Bitset
// #include aura.util.NumberFormat
// #include aura.util.DocLevelHandler
// #include aura.util.SizeEstimator
// #include aura.util.SecureFilters
// #include aura.util.Util
// #include aura.Logger
// #include aura.util.Override
// -- Errors ------------------------------------------------------------
// #include aura.AuraError
// #include aura.AuraFriendlyError
// -- Context -----------------------------------------------------------
// #include aura.context.AuraContext
// -- System ------------------------------------------------------------
// #include aura.system.DefDescriptor
// -- Style -------------------------------------------------------------
// #include aura.style.StyleDef
// -- Flavors -----------------------------------------------------------
// #include aura.flavors.FlavorDefaultDef
// #include aura.flavors.FlavorsDef
// -- Value -------------------------------------------------------------
// #include aura.value.PropertyReferenceValue
// #include aura.value.FunctionCallValue
// #include aura.value.PassthroughValue
// #include aura.value.ValueFactory
// #include aura.value.ExpressionFunctions
// -- Model -------------------------------------------------------------
// #include aura.model.ValueDef
// #include aura.model.ModelDef
// #include aura.model.Model
// -- Component ---------------------------------------------------------
// #include aura.component.ComponentClassRegistry
// #include aura.component.ComponentDefStorage
// #include aura.component.Component
// #include aura.component.InvalidComponent
// #include aura.component.ComponentDef
// -- Renderer ----------------------------------------------------------
// -- Provider ----------------------------------------------------------
// #include aura.provider.GlobalValueProviders
// #include aura.provider.LabelQueue
// #include aura.provider.LabelValueProvider
// #include aura.provider.ObjectValueProvider
// #include aura.provider.ContextValueProvider
// -- Helper -------------------------------------------------------------
// -- Library ------------------------------------------------------------
// #include aura.library.LibraryIncludeRegistry
// #include aura.library.LibraryRegistry
// -- Event --------------------------------------------------------------
// #include aura.event.EventDef
// #include aura.event.Event
// -- Controller ---------------------------------------------------------
// #include aura.controller.ActionDef
// #include aura.controller.Action
// #include aura.controller.ControllerDef
// -- Attribute ----------------------------------------------------------
// #include aura.attribute.AttributeDef
// #include aura.attribute.AttributeSet
// #include aura.attribute.AttributeDefSet
// -- Method ----------------------------------------------------------
// #include aura.method.MethodDef
// -- RequiredVersion ----------------------------------------------------------
// #include aura.requiredVersion.RequiredVersionDef
// #include aura.requiredVersion.RequiredVersionDefSet
// -- L10n ---------------------------------------------------------------
// #include aura.l10n.AuraLocalizationContext
// -- Storage -------------------------------------------------------------
// #include aura.storage.AuraStorageService
// #include aura.storage.AuraStorage
// -- Services -----------------------------------------------------------
// #include aura.AuraClientService
// #include aura.AuraComponentContext
// #include aura.AuraComponentService
// #include aura.AuraRenderingService
// #include aura.AuraExpressionService
// #include aura.AuraHistoryService
// #include aura.AuraEventService
// #include aura.AuraLocalizationService
// #include aura.AuraStyleService
// #include aura.metrics.AuraMetricsService
// -- Mode injection ------------------------------------------------------
// #include {"excludeModes" : ["PRODUCTION", "PRODUCTIONDEBUG"], "path" : "aura.AuraDevToolService"}
//-- LockerService -----------------------------------------------------------
//#include aura.locker.SecureObject
//#include aura.locker.SecureDOMEvent
//#include aura.locker.SecureIFrameElement
//#include aura.locker.SecureElement
//#include aura.locker.SecureScriptElement
//#include aura.locker.SecureDocument
//#include aura.locker.SecureAura
//#include aura.locker.SecureNavigator
//#include aura.locker.SecureWindow
//#include aura.locker.SecureAuraEvent
//#include aura.locker.SecureAction
//#include aura.locker.SecureComponent
//#include aura.locker.SecureComponentRef
//#include aura.locker.LockerService
/**
* @class Aura
* @classdesc The Aura framework. Default global instance name is $A.
* @constructor
*
* @borrows Aura.Services.AuraClientService#enqueueAction as enqueueAction
* @borrows Aura.Services.AuraClientService#deferAction as deferAction
* @borrows Aura.Services.AuraRenderingService#render as render
* @borrows Aura.Services.AuraRenderingService#rerender as rerender
* @borrows Aura.Services.AuraRenderingService#unrender as unrender
* @borrows Aura.Services.AuraRenderingService#afterRender as afterRender
* @borrows Aura.Services.AuraComponentService#get as getCmp
* @borrows Aura.Services.AuraComponentService#createComponent as createComponent
* @borrows Aura.Services.AuraComponentService#createComponents as createComponents
* @borrows Aura.Services.AuraComponentService#getComponent as getComponent
* @borrows Aura.Services.AuraComponentService#newComponentDeprecated as newCmp
* @borrows Aura.Services.AuraComponentService#newComponentDeprecated as newCmpDeprecated
* @borrows Aura.Services.AuraComponentService#newComponentAsync as newCmpAsync
* @borrows Aura.Services.AuraEventService.newEvent as getEvt
*/
function AuraInstance () {
this.globalValueProviders = {};
this.displayErrors = true;
this.logger = new Aura.Utils.Logger();
/**
* Collection of basic utility methods to operate on the DOM and Aura Components. <br/>
* See the documentation for <a href="#reference?topic=api:Util">Util</a> for the members.
*
* @type $A.ns.Util
* @platform
*/
this.util = new Aura.Utils.Util();
this["util"] = this.util; //Move this? (check prod mangling)
this.auraError = Aura.Errors.AuraError;
this.auraFriendlyError = Aura.Errors.AuraFriendlyError;
/**
* Error severity for categorizing errors
*
* ALERT [default error severity level if error thrower doesn’t explicitly specify a severity level] -
* the current page has issues and we need to alert the user that an error has occurred. The error(s) could potentially be corrected by a page reload
*
* FATAL - the user’s session is now completely broken and cannot continue being used.
* The user should logout and contact Salesforce support or their administrator.
*
* QUIET - An error has occurred but it won’t affect the user/page.
* This is likely something unexpected that a lower level component can just quietly log for later diagnostics by Salesforce (e.g. a perf issue or something else).
*
* @public
*/
this.severity = {
ALERT: "ALERT",
FATAL: "FATAL",
QUIET: "QUIET"
};
this.lastKnownError = null;
/**
* Instance of the AuraLocalizationService which provides utility methods for localizing data or getting formatters for numbers, currencies, dates, etc.<br/>
* See the documentation for <a href="#reference?topic=api:AuraLocalizationService">AuraLocalizationService</a> for the members.
*
* @type AuraLocalizationService
* @platform
*/
this.localizationService = new Aura.Services.AuraLocalizationService();
this.clientService = new Aura.Services.AuraClientService();
this.componentService = new Aura.Services.AuraComponentService();
this.renderingService = new Aura.Services.AuraRenderingService();
this.expressionService = new Aura.Services.AuraExpressionService();
this.historyService = new Aura.Services.AuraHistoryService();
this.eventService = new Aura.Services.AuraEventService();
this.storageService = new Aura.Services.AuraStorageService();
this.styleService = new Aura.Services.AuraStyleService();
this.metricsService = new Aura.Services.MetricsService();
this.lockerService = new Aura.Services.LockerService();
//#if {"excludeModes" : ["PRODUCTION", "PRODUCTIONDEBUG"]}
this.devToolService = new AuraDevToolService();
//#end
/** @field */
this.services = {
/**
* Rendering Service
*
* @public
* @type AuraRenderingService
* @memberOf Aura.Services
*/
rendering : this.renderingService,
/**
* Event Service
*
* @public
* @type AuraEventService
* @memberOf Aura.Services
*/
event : this.eventService,
/**
* Component Service
*
* @public
* @type AuraComponentService
* @memberOf Aura.Services
*/
component : this.componentService,
/**
* Client Service
*
* @public
* @type AuraClientService
* @memberOf AuraInstance.prototype
*/
client : this.clientService,
/**
* History Service
*
* @public
* @type AuraHistoryService
* @memberOf AuraInstance.prototype
*/
history : this.historyService,
/**
* Localization Service
*
* @public
* @type AuraLocalizationService
* @memberOf AuraInstance.prototype
*/
localization : this.localizationService,
/**
* Storage Service
*
* @public
* @type AuraStorageService
* @memberOf AuraInstance.prototype
*/
storage : this.storageService,
/**
* Alias of Component Service
*
* @public
* @type AuraComponentService
* @memberOf AuraInstance.prototype
* @see Aura#services.component
*/
cmp : this.componentService,
/**
* Alias of Event Service
*
* @public
* @type AuraEventService
* @memberOf AuraInstance.prototype
* @see Aura#services.event
*/
e : this.eventService,
/**
* Alias of Localization Service
*
* @public
* @type AuraLocalizationService
* @memberOf AuraInstance.prototype
* @see Aura#service.localization
*/
l10n : this.localizationService,
/**
* Style Service
*
* @public
* @type AuraStyleService
* @memberOf AuraInstance.prototype
*/
style: this.styleService,
/**
* Metrics Service
*
* @public
* @type AuraMetricsService
* @memberOf AuraInstance.prototype
*/
metrics: this.metricsService,
/**
* Locker Service
*
* @public
* @type AuraLockerService
* @memberOf AuraInstance.prototype
*/
locker: this.lockerService,
get : function(key) {
var ret = $A.services[key];
if (!ret && key === "root") {
return $A.getRoot();
}
return ret;
}
};
// Doced at the source by the @borrows statements on the Aura class
this.Component = Component;
this.enqueueAction = this.clientService.enqueueAction.bind(this.clientService);
this.deferAction = this.clientService.deferAction.bind(this.clientService);
this.deferPendingActions = this.clientService.deferPendingActions.bind(this.clientService);
this.runAfterInit = this.clientService.runAfterInitDefs.bind(this.clientService);
this.render = this.renderingService.render.bind(this.renderingService);
this.rerender = this.renderingService.rerender.bind(this.renderingService);
this.unrender = this.renderingService.unrender.bind(this.renderingService);
this.afterRender = this.renderingService.afterRender.bind(this.renderingService);
this.getCmp = this.componentService.get.bind(this.componentService);
this.getComponent = this.componentService.getComponent.bind(this.componentService);
this.createComponent = this.componentService["createComponent"].bind(this.componentService);
this.createComponents = this.componentService["createComponents"].bind(this.componentService);
this.newCmp = this.componentService["newComponentDeprecated"].bind(this.componentService);
this.newCmpDeprecated = this.componentService["newComponentDeprecated"].bind(this.componentService);
this.newCmpAsync = this.componentService["newComponentAsync"].bind(this.componentService);
this.createComponentFromConfig = this.componentService.createComponentFromConfig.bind(this.componentService);
this.getEvt = this.eventService.newEvent.bind(this.eventService);
/**
* Pushes current portion of attribute's creationPath onto stack
* @param {String} creationPath
*
* @public
*/
this.pushCreationPath = function(creationPath) {
var ctx = this.getContext();
if (!ctx) {
return;
}
var act = ctx.getCurrentAction();
if (!act) {
return;
}
act.pushCreationPath(creationPath);
};
/**
* pops current portion of attribute's creationPath from stack
* @param {String} creationPath
*
* @public
*/
this.popCreationPath = function(creationPath) {
var ctx = this.getContext();
if (!ctx) {
return;
}
var act = ctx.getCurrentAction();
if (!act) {
return;
}
act.popCreationPath(creationPath);
};
/**
* sets pathIndex for the current attribute on creationPath's stack
* @param {String} creationPath
*
* @public
*/
this.setCreationPathIndex = function(idx) {
var ctx = this.getContext();
if (!ctx) {
return;
}
var act = ctx.getCurrentAction();
if (!act) {
return;
}
act.setCreationPathIndex(idx);
};
// Google Closure Compiler Symbol Exports
this["runAfterInit"] = this.runAfterInit;
this["clientService"] = this.clientService;
this["componentService"] = this.componentService;
this["renderingService"] = this.renderingService;
this["expressionService"] = this.expressionService;
this["historyService"] = this.historyService;
this["localizationService"] = this.localizationService;
this["eventService"] = this.eventService;
this["layoutService"] = this.layoutService;
this["metricsService"] = this.metricsService;
this["lockerService"] = this.lockerService;
this["storageService"] = this.storageService;
this["styleService"] = this.styleService;
this["services"] = this.services;
this["enqueueAction"] = this.enqueueAction;
this["deferAction"] = this.deferAction;
this["deferPendingActions"] = this.deferPendingActions;
this["render"] = this.render;
this["rerender"] = this.rerender;
this["unrender"] = this.unrender;
this["afterRender"] = this.afterRender;
this["logger"] = this.logger;
this["getCmp"] = this.getCmp;
this["getComponent"] = this.getComponent;
this["pushCreationPath"] = this.pushCreationPath;
this["popCreationPath"] = this.popCreationPath;
this["setCreationPathIndex"] = this.setCreationPathIndex;
//#if {"excludeModes" : ["PRODUCTION", "PRODUCTIONDEBUG"]}
this["devToolService"] = this.devToolService;
this["getQueryStatement"] = this.devToolService.newStatement;
this["qhelp"] = function() { return this.devToolService.help();};
//#end
this["createComponent"] = this.createComponent;
this["createComponents"] = this.createComponents;
this["createComponentFromConfig"] = this.createComponentFromConfig;
this["newCmp"] = this.newCmp;
this["newCmpDeprecated"] = this.newCmpDeprecated;
this["newCmpAsync"] = this.newCmpAsync;
this["getEvt"] = this.getEvt;
this["Component"] = this.Component;
this["auraError"] = this.auraError;
this["auraFriendlyError"] = this.auraFriendlyError;
this["severity"] = this.severity;
this["severity"]["ALERT"] = this.severity.ALERT;
this["severity"]["FATAL"] = this.severity.FATAL;
this["severity"]["QUIET"] = this.severity.QUIET;
// work around closure compiler
this["severity"] = Object.freeze(this["severity"]);
this["hasDefinition"] = this.hasDefinition;
this["getDefinition"] = this.getDefinition;
this["getDefinitions"] = this.getDefinitions;
var services = this.services;
// TODO: convert to //#exportSymbols when available
services["rendering"] = services.rendering;
services["event"] = services.event;
services["component"] = services.component;
services["client"] = services.client;
services["history"] = services.history;
services["l10n"] = services.localization;
services["storage"] = services.storage;
services["metrics"] = services.metrics;
services["cmp"] = services.cmp;
services["e"] = services.e;
services["c"] = {
get: function(name) {
var path = (name||'').split('.');
var controllerDef = path.shift();
var action = path.shift();
return services.component.getControllerDef(controllerDef).get(action);
}
};
this.eventService.addHandler({
event : 'aura:clientRedirect',
"globalId" : "Aura",
"handler" : function(evt) {
var url = evt.getParam('url');
if (url != null) {
window.location = url;
}
}
});
}
/**
* Does nothing.
*
* @public
* @deprecated
*/
AuraInstance.prototype.setCurrentTransactionId = function() { };
/**
* Does nothing.
*
* @returns undefined
* @public
* @deprecated
*/
AuraInstance.prototype.getCurrentTransactionId = function() { return undefined; };
/**
* Initializes Aura with context info about the app that should be loaded.
* @param {Object} config
*
* {
* <code>config.descriptor</code> : The descriptor of the application or component that should be loaded as the root. For example, <code>"markup://foo:bar"</code><br />
* <code>config.attributes</code> : The attributes that should be passed into the root component when it is constructed. For example, <code>{at1 : 1, at2 : "asdf"}</code><br />
* <code>config.defType</code> : The defType of the descriptor. For example, <code>"DEFINITION"</code> or <code>"APPLICATION"</code><br />
* <code>config.lastmod</code> : The timestamp, in millis of the latest changes to the preloaded metadata associated with this application.
* }
* @public
*/
AuraInstance.prototype.initAsync = function(config) {
Aura.bootstrapMark("initAsync");
var regexpDetectURLProcotolSegment = /^(.*?:)?\/\//;
function createAuraContext() {
// Context is created async because of the GVPs go though async storage checks
$A.context = new Aura.Context.AuraContext(config["context"], function(context) {
//
// This hook is to allow for reloading after aura is initialized, including
// any storage setup, as we may well have to clear persistent storage.
//
$A.context = context;
$A.clientService.reloadPointPassed = true;
if ($A.clientService.reloadFunction) {
$A.clientService.reloadFunction();
return;
}
if (!window["$$safe-eval$$"] && !regexpDetectURLProcotolSegment.test(config["host"])) {
throw new $A.auraError("Aura(): Failed to initialize locker worker.", null, $A.severity.QUIET);
}
$A.clientService.initHost(config["host"]);
$A.setLanguage();
$A.metricsService.initialize();
// Restore component definitions from AuraStorage into memory (if persistent)
$A.componentService.restoreDefsFromStorage($A.getContext()).then(function () {
$A.clientService.loadComponent(config["descriptor"], config["attributes"], $A.initPriv, config["deftype"]);
});
});
}
if (!window['$$safe-eval$$'] && !regexpDetectURLProcotolSegment.test(config["host"])) {
// safe eval worker is an iframe that enables the page to run arbitrary evaluation,
// if this iframe is still loading, we should wait for it before continue with
// initialization, in the other hand, if the iframe is not available, we create it,
// and wait for it to be ready.
var el = document.getElementById("safeEvalWorker");
if (!el) {
if (!config["safeEvalWorker"]) {
throw new $A.auraError("Aura(): Missing 'safeEvalWorker' configuration.", null, $A.severity.QUIET);
}
el = document.createElement("iframe");
el.setAttribute("src", config["safeEvalWorker"]);
el.setAttribute("width", "0");
el.setAttribute("height", "0");
el.setAttribute("tabIndex", "-1");
el.setAttribute("aria-hidden", "true");
el.setAttribute("title", "scripts");
el.setAttribute("id", "safeEvalWorker");
el.style.display = "none";
document.body.appendChild(el);
}
$A.util.on(el, "load", createAuraContext);
$A.util.on(el, "error", function () {
throw new $A.auraError("Aura(): Failed to load locker worker.", null, $A.severity.QUIET);
});
} else {
// provision for an alternative safe evaluation. This will open the door to do some
// performance optimization.
createAuraContext();
}
};
/**
* Set the language for the HTML document.
*
* This must be called after the context is initialized and we have our GVPs set up.
*/
AuraInstance.prototype.setLanguage = function() {
var lang = $A.get("$Locale.userLocalLang") || "en";
document["getElementsByTagName"]("html")[0]["setAttribute"]("lang", lang);
};
/**
* Initializes Aura with context info but without retrieving component from server. Used for synchronous initialization.
*
* Whoever named this function should be shot, but I won't rename for now. Eventually we want to use
* startApplication, and make it either auto-require app.js or have the caller load app.js and then invoke
* startApplication with the data.
*
* @param {Object} config The configuration attributes
* @param {Boolean} useExisting
* @param {Boolean} doNotInitializeServices Set to true if the History service should not be initialized, or false if
* it should. Defaults to true for Aura Integration Service.
* @public
*/
AuraInstance.prototype.initConfig = function(config, useExisting, doNotInitializeServices) {
config = $A.util.json.resolveRefsObject(config);
if (!useExisting || $A.util.isUndefined($A.getContext())) {
$A.clientService.initHost(config["host"], config["sid"]);
// creating context.
$A.context = new Aura.Context.AuraContext(config["context"]);
$A.setLanguage();
this.initPriv(config["instance"], config["token"], null, doNotInitializeServices);
$A.context.finishComponentConfigs($A.context.getCurrentAction().getId());
$A.context.setCurrentAction(null);
} else {
// Use the existing context and just join the new context into it
// FIXME: This is used by integration service, and will not work correctly with components.
$A.getContext()['merge'](config["context"]);
}
};
/**
* Initializes Aura in debug environment.
*
* @param {Object} config The descriptor ("markup://foo:bar"), attributes, defType ("APPLICATION" or "COMPONENT"), and
* timestamp of last modified change
* @param {String} token
* @param {Object} container Sets the container for the component.
* @param {Boolean=} doNotInitializeServices True if the History service should not be initialized, or false if
* it should. Defaults to true for Aura Integration Service.
* @private
*/
AuraInstance.prototype.initPriv = function(config, token, container, doNotInitializeServices) {
if (!$A["hasErrors"]) {
Aura.bootstrapMark("createAndRenderAppInit");
$A.addTearDownHandler();
var app = $A.clientService["init"](config, token, $A.util.getElement(container));
$A.setRoot(app);
Aura.bootstrapMark("createAndRenderAppReady");
if (!$A.initialized) {
$A.initialized = true;
$A.addDefaultErrorHandler(app);
$A.finishInit(doNotInitializeServices);
}
}
};
/**
* Add default handler to aura:systemError event
* @private
*/
AuraInstance.prototype.addTearDownHandler = function () {
window.addEventListener('unload', $A.getCallback($A.clientService.tearDown.bind($A.clientService)));
};
/**
* Add default handler to aura:systemError event
* @private
*/
AuraInstance.prototype.addDefaultErrorHandler = function (app) {
$A.eventService.addHandler({
"event": "aura:systemError",
"globalId": app.getGlobalId(),
"handler": function(event) {
if (event["handled"]) { return; }
$A.message(event.getParam("message"));
event["handled"] = true;
}
});
};
/**
* Signals that initialization has completed.
* @private
*/
AuraInstance.prototype.finishInit = function(doNotInitializeServices) {
if (!this["finishedInit"]) {
$A.util.removeClass(document.body, "loading");
delete $A.globalValueProviders;
this["finishedInit"] = true;
$A.eventService.getNewEvent("markup://aura:initialized").fire();
$A.metricsService.applicationReady();
}
// Unless we are in IntegrationServices, dispatch location hash change.
if (!doNotInitializeServices) {
$A.historyService.init();
}
};
/**
* @description Use <code>$A.error()</code> in response to a serious error that has no recovery path.
*
* If this occurs during a test, the test will be stopped unless you add calls to '$A.test.expectAuraError' for
* each error that occurs. <code>auraErrorsExpectedDuringInit</code> allows server side errors to not stop the
* test as well.
*
*
* @public
* @param {String} msg The error message to be displayed to the user.
* @param {Error} [e] The error object to be displayed to the user.
* @platform
* @deprecated throw new Error(msg) instead
*/
AuraInstance.prototype.error = function(msg, e){
this.logger.error(msg, e);
};
/**
* Optionally sets and returns whether to display error dialog
*
* @private
* @param {Boolean} [toggle] toggles display of error dialog
* @returns {Boolean} whether to display error dialog
*/
AuraInstance.prototype.showErrors = function(toggle){
if (toggle !== undefined) {
this.displayErrors = !!toggle;
}
return this.displayErrors;
};
/**
* @private
*/
AuraInstance.prototype.handleError = function(message, e) {
//#if {"excludeModes" : ["PRODUCTION", "PRODUCTIONDEBUG"]}
$A.logger.devDebugConsoleLog("ERROR", message, e);
//#end
var dispMsg = message;
var evtArgs = {"message":dispMsg,"error":null,"auraError":null};
if (e) {
if (e["handled"]) {
return;
} else {
e["handled"] = true;
}
if (e instanceof $A.auraFriendlyError) {
e.severity = e.severity || this.severity.QUIET;
evtArgs = {"message":e["message"],"error":e["name"],"auraError":e};
} else if (e instanceof $A.auraError) {
var format = "Something has gone wrong. {0}.\nPlease try again.\n";
var displayMessage = e.message || e.name;
e.severity = e.severity || this.severity["ALERT"];
displayMessage += "\n" + (e.component ? "Failing descriptor: {" + e.component + "}" : "");
//#if {"excludeModes" : ["PRODUCTION", "PRODUCTIONDEBUG"]}
displayMessage += "\n" + e.stackTrace;
//#end
dispMsg = $A.util.format(format, displayMessage);
// use null error string to specify non auraFriendlyError type.
evtArgs = {"message":dispMsg,"error":null,"auraError":e};
}
}
if ($A.initialized) {
// fire the event later so the current handleError could return even if an error occurs in the event handler.
window.setTimeout(function() {
$A.eventService.getNewEvent('markup://aura:systemError').fire(evtArgs);
}, 0);
} else {
if ($A.showErrors()) {
$A.message(dispMsg);
}
}
};
/**
* Report error to the server after handling it.
* Note that the method should only be used if try-catch mechanism
* of error handling is not desired or not functional (ex: in nested promises)
* @public
* @param {String} message The message to display.
* @param {Error} error An error object to be included in handling and reporting.
* @platform
*/
AuraInstance.prototype.reportError = function(message, error) {
// for browsers that doesn't have 5th argument (error object) passed in the onerror handler,
// we use our bookkeeping object this.lastKnownError
// when there is still no error object, we create a dummy to have client error id.
error = error ||
((this.lastKnownError && message && message.indexOf(this.lastKnownError.message) > -1) ? this.lastKnownError : null) ||
new $A.auraError("[NoErrorObjectAvailable] " + message);
$A.handleError(message, error);
if ($A.initialized) {
$A.getCallback(function() {
if (error && message) {
// if there's extra info in the message that's not in error.message, include it for report.
if (message !== error.message && message.indexOf(error.message) > -1) {
error.message = message;
}
}
$A.logger.reportError(error);
})();
$A.services.client.postProcess();
}
this.lastKnownError = null;
};
/**
* <code>$A.warning()</code> should be used in the case where poor programming practices have been used.
*
* These warnings will not, in general, be displayed to the user, but they will appear in the console (if
* availiable), and in the aura debug window.
*
* @public
* @param {String} w The message to display.
* @param {Error} e an error, if any.
* @platform
*/
AuraInstance.prototype.warning = function(w, e) {
this.logger.warning(w, e);
};
/**
* Displays an error message to the user. Currently used for displaying errors that do not cause the application to
* stop completely.
*
* @public
* @param {String} msg The message to display.
*/
AuraInstance.prototype.message = function(msg) {
if (!this.displayErrors) {
return;
}
var message = $A.util.getElement("auraErrorMessage");
message.innerHTML = "";
message.appendChild(document.createTextNode(msg));
$A.util.removeClass(document.body, "loading");
$A.util.addClass(document.body, "auraError");
};
/**
* Returns a callback which is safe to invoke from outside Aura, e.g. as an event handler or in a setTimeout.
* @public
* @function
* @param {Function} callback The method to call after reestablishing Aura context.
* @platform
*/
AuraInstance.prototype.getCallback = function(callback) {
$A.assert($A.util.isFunction(callback),"$A.getCallback(): 'callback' must be a valid Function");
var context=$A.getContext().getCurrentAccess();
return function(){
$A.getContext().setCurrentAccess(context);
$A.clientService.pushStack("$A.getCallback()");
try {
return callback.apply(this,Array.prototype.slice.call(arguments));
} catch (e) {
// no need to wrap AFE with auraError as
// customers who throw AFE would want to handle it with their own custom experience.
if (e instanceof $A.auraError) {
if (context && context.getDef) {
e.component = e.component || context.getDef().getDescriptor().toString();
}
$A.lastKnownError = e;
throw e;
} else {
var errorWrapper = new $A.auraError("Error in $A.getCallback()", e);
if (context && context.getDef) {
errorWrapper.component = context.getDef().getDescriptor().toString();
}
$A.lastKnownError = errorWrapper;
throw errorWrapper;
}
} finally {
$A.clientService.popStack("$A.getCallback()");
$A.getContext().releaseCurrentAccess();
}
};
};
/**
* Returns the application token referenced by name.
* @function
* @param {String} token The name of the application configuration token to retrieve, for example, <code>$A.getToken("section.configuration")</code>.
* @public
* @platform
*/
AuraInstance.prototype.getToken = function(token){
var context=$A.getContext();
var tokens=context&&context.getTokens();
if(tokens){
if(tokens.hasOwnProperty(token)){
return tokens[token];
}
throw new $A.auraError("Unknown token: '"+token+"'. Are you missing a tokens file or declaration?");
}
};
/**
* Returns the value referenced using property syntax. Gets the value from the specified global value provider.
* @public
* @function
* @param {String} key The data key to look up on element, for example, <code>$A.get("$Label.section.key")</code>.
* @param {Function} callback The method to call with the result if a server trip is expected.
* @platform
*/
AuraInstance.prototype.get = function(key, callback) {
// JBUCH: TODO: FIXME