-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-1.0.pre.js
executable file
·20709 lines (16193 loc) · 604 KB
/
ember-1.0.pre.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
// Version: v1.0.pre
// Last commit: 7955b85 (2012-08-03 14:50:17 -0700)
(function() {
/*global __fail__*/
if ('undefined' === typeof Ember) {
Ember = {};
if ('undefined' !== typeof window) {
window.Em = window.Ember = Em = Ember;
}
}
Ember.ENV = 'undefined' === typeof ENV ? {} : ENV;
if (!('MANDATORY_SETTER' in Ember.ENV)) {
Ember.ENV.MANDATORY_SETTER = true; // default to true for debug dist
}
/**
Define an assertion that will throw an exception if the condition is not
met. Ember build tools will remove any calls to Ember.assert() when
doing a production build. Example:
// Test for truthiness
Ember.assert('Must pass a valid object', obj);
// Fail unconditionally
Ember.assert('This code path should never be run')
@static
@function
@param {String} desc
A description of the assertion. This will become the text of the Error
thrown if the assertion fails.
@param {Boolean} test
Must be truthy for the assertion to pass. If falsy, an exception will be
thrown.
*/
Ember.assert = function(desc, test) {
if (!test) throw new Error("assertion failed: "+desc);
};
/**
Display a warning with the provided message. Ember build tools will
remove any calls to Ember.warn() when doing a production build.
@static
@function
@param {String} message
A warning to display.
@param {Boolean} test
An optional boolean. If falsy, the warning will be displayed.
*/
Ember.warn = function(message, test) {
if (!test) {
Ember.Logger.warn("WARNING: "+message);
if ('trace' in Ember.Logger) Ember.Logger.trace();
}
};
/**
Display a deprecation warning with the provided message and a stack trace
(Chrome and Firefox only). Ember build tools will remove any calls to
Ember.deprecate() when doing a production build.
@static
@function
@param {String} message
A description of the deprecation.
@param {Boolean} test
An optional boolean. If falsy, the deprecation will be displayed.
*/
Ember.deprecate = function(message, test) {
if (Ember && Ember.TESTING_DEPRECATION) { return; }
if (arguments.length === 1) { test = false; }
if (test) { return; }
if (Ember && Ember.ENV.RAISE_ON_DEPRECATION) { throw new Error(message); }
var error;
// When using new Error, we can't do the arguments check for Chrome. Alternatives are welcome
try { __fail__.fail(); } catch (e) { error = e; }
if (Ember.LOG_STACKTRACE_ON_DEPRECATION && error.stack) {
var stack, stackStr = '';
if (error['arguments']) {
// Chrome
stack = error.stack.replace(/^\s+at\s+/gm, '').
replace(/^([^\(]+?)([\n$])/gm, '{anonymous}($1)$2').
replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}($1)').split('\n');
stack.shift();
} else {
// Firefox
stack = error.stack.replace(/(?:\n@:0)?\s+$/m, '').
replace(/^\(/gm, '{anonymous}(').split('\n');
}
stackStr = "\n " + stack.slice(2).join("\n ");
message = message + stackStr;
}
Ember.Logger.warn("DEPRECATION: "+message);
};
/**
Display a deprecation warning with the provided message and a stack trace
(Chrome and Firefox only) when the wrapped method is called.
Ember build tools will not remove calls to Ember.deprecateFunc(), though
no warnings will be shown in production.
@static
@function
@param {String} message
A description of the deprecation.
@param {Function} func
The function to be deprecated.
*/
Ember.deprecateFunc = function(message, func) {
return function() {
Ember.deprecate(message);
return func.apply(this, arguments);
};
};
window.ember_assert = Ember.deprecateFunc("ember_assert is deprecated. Please use Ember.assert instead.", Ember.assert);
window.ember_warn = Ember.deprecateFunc("ember_warn is deprecated. Please use Ember.warn instead.", Ember.warn);
window.ember_deprecate = Ember.deprecateFunc("ember_deprecate is deprecated. Please use Ember.deprecate instead.", Ember.deprecate);
window.ember_deprecateFunc = Ember.deprecateFunc("ember_deprecateFunc is deprecated. Please use Ember.deprecateFunc instead.", Ember.deprecateFunc);
})();
// Version: v1.0.pre
// Last commit: 7955b85 (2012-08-03 14:50:17 -0700)
(function() {
// ==========================================================================
// Project: Ember Metal
// Copyright: ©2011 Strobe Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/*globals Em:true ENV */
if ('undefined' === typeof Ember) {
// Create core object. Make it act like an instance of Ember.Namespace so that
// objects assigned to it are given a sane string representation.
Ember = {};
}
/**
@namespace
@name Ember
@version 1.0.pre
All Ember methods and functions are defined inside of this namespace.
You generally should not add new properties to this namespace as it may be
overwritten by future versions of Ember.
You can also use the shorthand "Em" instead of "Ember".
Ember-Runtime is a framework that provides core functions for
Ember including cross-platform functions, support for property
observing and objects. Its focus is on small size and performance. You can
use this in place of or along-side other cross-platform libraries such as
jQuery.
The core Runtime framework is based on the jQuery API with a number of
performance optimizations.
*/
// aliases needed to keep minifiers from removing the global context
if ('undefined' !== typeof window) {
window.Em = window.Ember = Em = Ember;
}
// Make sure these are set whether Ember was already defined or not
Ember.isNamespace = true;
Ember.toString = function() { return "Ember"; };
/**
@static
@type String
@default '1.0.pre'
@constant
*/
Ember.VERSION = '1.0.pre';
/**
@static
@type Hash
@constant
Standard environmental variables. You can define these in a global `ENV`
variable before loading Ember to control various configuration
settings.
*/
Ember.ENV = Ember.ENV || ('undefined' === typeof ENV ? {} : ENV);
Ember.config = Ember.config || {};
// ..........................................................
// BOOTSTRAP
//
/**
@static
@type Boolean
@default true
@constant
Determines whether Ember should enhances some built-in object
prototypes to provide a more friendly API. If enabled, a few methods
will be added to Function, String, and Array. Object.prototype will not be
enhanced, which is the one that causes most troubles for people.
In general we recommend leaving this option set to true since it rarely
conflicts with other code. If you need to turn it off however, you can
define an ENV.EXTEND_PROTOTYPES config to disable it.
*/
Ember.EXTEND_PROTOTYPES = (Ember.ENV.EXTEND_PROTOTYPES !== false);
/**
@static
@type Boolean
@default true
@constant
Determines whether Ember logs a full stack trace during deprecation warnings
*/
Ember.LOG_STACKTRACE_ON_DEPRECATION = (Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION !== false);
/**
@static
@type Boolean
@default Ember.EXTEND_PROTOTYPES
@constant
Determines whether Ember should add ECMAScript 5 shims to older browsers.
*/
Ember.SHIM_ES5 = (Ember.ENV.SHIM_ES5 === false) ? false : Ember.EXTEND_PROTOTYPES;
/**
@static
@type Boolean
@default true
@constant
Determines whether computed properties are cacheable by default.
This option will be removed for the 1.1 release.
When caching is enabled by default, you can use `volatile()` to disable
caching on individual computed properties.
*/
Ember.CP_DEFAULT_CACHEABLE = (Ember.ENV.CP_DEFAULT_CACHEABLE !== false);
/**
@static
@type Boolean
@default true
@constant
Determines whether views render their templates using themselves
as the context, or whether it is inherited from the parent. This option
will be removed in the 1.1 release.
If you need to update your application to use the new context rules, simply
prefix property access with `view.`:
// Before:
{{#each App.photosController}}
Photo Title: {{title}}
{{#view App.InfoView contentBinding="this"}}
{{content.date}}
{{content.cameraType}}
{{otherViewProperty}}
{{/view}}
{{/each}}
// After:
{{#each App.photosController}}
Photo Title: {{title}}
{{#view App.InfoView}}
{{date}}
{{cameraType}}
{{view.otherViewProperty}}
{{/view}}
{{/each}}
*/
Ember.VIEW_PRESERVES_CONTEXT = (Ember.ENV.VIEW_PRESERVES_CONTEXT !== false);
/**
Empty function. Useful for some operations.
@returns {Object}
@private
*/
Ember.K = function() { return this; };
/**
@namespace
@name window
@description The global window object
*/
// Stub out the methods defined by the ember-debug package in case it's not loaded
if ('undefined' === typeof Ember.assert) { Ember.assert = Ember.K; }
if ('undefined' === typeof Ember.warn) { Ember.warn = Ember.K; }
if ('undefined' === typeof Ember.deprecate) { Ember.deprecate = Ember.K; }
if ('undefined' === typeof Ember.deprecateFunc) {
Ember.deprecateFunc = function(_, func) { return func; };
}
// These are deprecated but still supported
if ('undefined' === typeof ember_assert) { window.ember_assert = Ember.K; }
if ('undefined' === typeof ember_warn) { window.ember_warn = Ember.K; }
if ('undefined' === typeof ember_deprecate) { window.ember_deprecate = Ember.K; }
if ('undefined' === typeof ember_deprecateFunc) {
/** @private */
window.ember_deprecateFunc = function(_, func) { return func; };
}
// ..........................................................
// LOGGER
//
/**
@class
Inside Ember-Metal, simply uses the window.console object.
Override this to provide more robust logging functionality.
*/
Ember.Logger = window.console || { log: Ember.K, warn: Ember.K, error: Ember.K, info: Ember.K, debug: Ember.K };
})();
(function() {
/*jshint newcap:false*/
// NOTE: There is a bug in jshint that doesn't recognize `Object()` without `new`
// as being ok unless both `newcap:false` and not `use strict`.
// https://github.com/jshint/jshint/issues/392
// Testing this is not ideal, but we want to use native functions
// if available, but not to use versions created by libraries like Prototype
/** @private */
var isNativeFunc = function(func) {
// This should probably work in all browsers likely to have ES5 array methods
return func && Function.prototype.toString.call(func).indexOf('[native code]') > -1;
};
// From: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/map
/** @private */
var arrayMap = isNativeFunc(Array.prototype.map) ? Array.prototype.map : function(fun /*, thisp */) {
//"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
res[i] = fun.call(thisp, t[i], i, t);
}
}
return res;
};
// From: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach
/** @private */
var arrayForEach = isNativeFunc(Array.prototype.forEach) ? Array.prototype.forEach : function(fun /*, thisp */) {
//"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
fun.call(thisp, t[i], i, t);
}
}
};
/** @private */
var arrayIndexOf = isNativeFunc(Array.prototype.indexOf) ? Array.prototype.indexOf : function (obj, fromIndex) {
if (fromIndex === null || fromIndex === undefined) { fromIndex = 0; }
else if (fromIndex < 0) { fromIndex = Math.max(0, this.length + fromIndex); }
for (var i = fromIndex, j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
};
Ember.ArrayPolyfills = {
map: arrayMap,
forEach: arrayForEach,
indexOf: arrayIndexOf
};
var utils = Ember.EnumerableUtils = {
map: function(obj, callback, thisArg) {
return obj.map ? obj.map.call(obj, callback, thisArg) : arrayMap.call(obj, callback, thisArg);
},
forEach: function(obj, callback, thisArg) {
return obj.forEach ? obj.forEach.call(obj, callback, thisArg) : arrayForEach.call(obj, callback, thisArg);
},
indexOf: function(obj, element, index) {
return obj.indexOf ? obj.indexOf.call(obj, element, index) : arrayIndexOf.call(obj, element, index);
},
indexesOf: function(obj, elements) {
return elements === undefined ? [] : utils.map(elements, function(item) {
return utils.indexOf(obj, item);
});
},
removeObject: function(array, item) {
var index = utils.indexOf(array, item);
if (index !== -1) { array.splice(index, 1); }
}
};
if (Ember.SHIM_ES5) {
if (!Array.prototype.map) {
/** @private */
Array.prototype.map = arrayMap;
}
if (!Array.prototype.forEach) {
/** @private */
Array.prototype.forEach = arrayForEach;
}
if (!Array.prototype.indexOf) {
/** @private */
Array.prototype.indexOf = arrayIndexOf;
}
}
})();
(function() {
// ==========================================================================
// Project: Ember Metal
// Copyright: ©2011 Strobe Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/*globals Node */
/**
@class
Platform specific methods and feature detectors needed by the framework.
@name Ember.platform
*/
var platform = Ember.platform = {};
/**
Identical to Object.create(). Implements if not available natively.
@memberOf Ember.platform
@name create
*/
Ember.create = Object.create;
if (!Ember.create) {
/** @private */
var K = function() {};
Ember.create = function(obj, props) {
K.prototype = obj;
obj = new K();
if (props) {
K.prototype = obj;
for (var prop in props) {
K.prototype[prop] = props[prop].value;
}
obj = new K();
}
K.prototype = null;
return obj;
};
Ember.create.isSimulated = true;
}
/** @private */
var defineProperty = Object.defineProperty;
var canRedefineProperties, canDefinePropertyOnDOM;
// Catch IE8 where Object.defineProperty exists but only works on DOM elements
if (defineProperty) {
try {
defineProperty({}, 'a',{get:function(){}});
} catch (e) {
/** @private */
defineProperty = null;
}
}
if (defineProperty) {
// Detects a bug in Android <3.2 where you cannot redefine a property using
// Object.defineProperty once accessors have already been set.
/** @private */
canRedefineProperties = (function() {
var obj = {};
defineProperty(obj, 'a', {
configurable: true,
enumerable: true,
get: function() { },
set: function() { }
});
defineProperty(obj, 'a', {
configurable: true,
enumerable: true,
writable: true,
value: true
});
return obj.a === true;
})();
// This is for Safari 5.0, which supports Object.defineProperty, but not
// on DOM nodes.
/** @private */
canDefinePropertyOnDOM = (function(){
try {
defineProperty(document.createElement('div'), 'definePropertyOnDOM', {});
return true;
} catch(e) { }
return false;
})();
if (!canRedefineProperties) {
/** @private */
defineProperty = null;
} else if (!canDefinePropertyOnDOM) {
/** @private */
defineProperty = function(obj, keyName, desc){
var isNode;
if (typeof Node === "object") {
isNode = obj instanceof Node;
} else {
isNode = typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string";
}
if (isNode) {
// TODO: Should we have a warning here?
return (obj[keyName] = desc.value);
} else {
return Object.defineProperty(obj, keyName, desc);
}
};
}
}
/**
Identical to Object.defineProperty(). Implements as much functionality
as possible if not available natively.
@memberOf Ember.platform
@name defineProperty
@param {Object} obj The object to modify
@param {String} keyName property name to modify
@param {Object} desc descriptor hash
@returns {void}
*/
platform.defineProperty = defineProperty;
/**
Set to true if the platform supports native getters and setters.
@memberOf Ember.platform
@name hasPropertyAccessors
*/
platform.hasPropertyAccessors = true;
if (!platform.defineProperty) {
platform.hasPropertyAccessors = false;
platform.defineProperty = function(obj, keyName, desc) {
if (!desc.get) { obj[keyName] = desc.value; }
};
platform.defineProperty.isSimulated = true;
}
if (Ember.ENV.MANDATORY_SETTER && !platform.hasPropertyAccessors) {
Ember.ENV.MANDATORY_SETTER = false;
}
})();
(function() {
// ==========================================================================
// Project: Ember Metal
// Copyright: ©2011 Strobe Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
var o_defineProperty = Ember.platform.defineProperty,
o_create = Ember.create,
// Used for guid generation...
GUID_KEY = '__ember'+ (+ new Date()),
uuid = 0,
numberCache = [],
stringCache = {};
var MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER;
/**
@private
@static
@type String
@constant
A unique key used to assign guids and other private metadata to objects.
If you inspect an object in your browser debugger you will often see these.
They can be safely ignored.
On browsers that support it, these properties are added with enumeration
disabled so they won't show up when you iterate over your properties.
*/
Ember.GUID_KEY = GUID_KEY;
var GUID_DESC = {
writable: false,
configurable: false,
enumerable: false,
value: null
};
/**
@private
Generates a new guid, optionally saving the guid to the object that you
pass in. You will rarely need to use this method. Instead you should
call Ember.guidFor(obj), which return an existing guid if available.
@param {Object} obj
Optional object the guid will be used for. If passed in, the guid will
be saved on the object and reused whenever you pass the same object
again.
If no object is passed, just generate a new guid.
@param {String} prefix
Optional prefix to place in front of the guid. Useful when you want to
separate the guid into separate namespaces.
@returns {String} the guid
*/
Ember.generateGuid = function generateGuid(obj, prefix) {
if (!prefix) prefix = 'ember';
var ret = (prefix + (uuid++));
if (obj) {
GUID_DESC.value = ret;
o_defineProperty(obj, GUID_KEY, GUID_DESC);
}
return ret ;
};
/**
@private
Returns a unique id for the object. If the object does not yet have
a guid, one will be assigned to it. You can call this on any object,
Ember.Object-based or not, but be aware that it will add a _guid property.
You can also use this method on DOM Element objects.
@method
@param obj {Object} any object, string, number, Element, or primitive
@returns {String} the unique guid for this instance.
*/
Ember.guidFor = function guidFor(obj) {
// special cases where we don't want to add a key to object
if (obj === undefined) return "(undefined)";
if (obj === null) return "(null)";
var cache, ret;
var type = typeof obj;
// Don't allow prototype changes to String etc. to change the guidFor
switch(type) {
case 'number':
ret = numberCache[obj];
if (!ret) ret = numberCache[obj] = 'nu'+obj;
return ret;
case 'string':
ret = stringCache[obj];
if (!ret) ret = stringCache[obj] = 'st'+(uuid++);
return ret;
case 'boolean':
return obj ? '(true)' : '(false)';
default:
if (obj[GUID_KEY]) return obj[GUID_KEY];
if (obj === Object) return '(Object)';
if (obj === Array) return '(Array)';
ret = 'ember'+(uuid++);
GUID_DESC.value = ret;
o_defineProperty(obj, GUID_KEY, GUID_DESC);
return ret;
}
};
// ..........................................................
// META
//
var META_DESC = {
writable: true,
configurable: false,
enumerable: false,
value: null
};
var META_KEY = Ember.GUID_KEY+'_meta';
/**
The key used to store meta information on object for property observing.
@static
@type String
*/
Ember.META_KEY = META_KEY;
// Placeholder for non-writable metas.
var EMPTY_META = {
descs: {},
watching: {}
};
if (MANDATORY_SETTER) { EMPTY_META.values = {}; }
Ember.EMPTY_META = EMPTY_META;
if (Object.freeze) Object.freeze(EMPTY_META);
var isDefinePropertySimulated = Ember.platform.defineProperty.isSimulated;
function Meta(obj) {
this.descs = {};
this.watching = {};
this.cache = {};
this.source = obj;
}
if (isDefinePropertySimulated) {
// on platforms that don't support enumerable false
// make meta fail jQuery.isPlainObject() to hide from
// jQuery.extend() by having a property that fails
// hasOwnProperty check.
Meta.prototype.__preventPlainObject__ = true;
}
/**
@private
@function
Retrieves the meta hash for an object. If 'writable' is true ensures the
hash is writable for this object as well.
The meta object contains information about computed property descriptors as
well as any watched properties and other information. You generally will
not access this information directly but instead work with higher level
methods that manipulate this hash indirectly.
@param {Object} obj
The object to retrieve meta for
@param {Boolean} writable
Pass false if you do not intend to modify the meta hash, allowing the
method to avoid making an unnecessary copy.
@returns {Hash}
*/
Ember.meta = function meta(obj, writable) {
var ret = obj[META_KEY];
if (writable===false) return ret || EMPTY_META;
if (!ret) {
if (!isDefinePropertySimulated) o_defineProperty(obj, META_KEY, META_DESC);
ret = new Meta(obj);
if (MANDATORY_SETTER) { ret.values = {}; }
obj[META_KEY] = ret;
// make sure we don't accidentally try to create constructor like desc
ret.descs.constructor = null;
} else if (ret.source !== obj) {
if (!isDefinePropertySimulated) o_defineProperty(obj, META_KEY, META_DESC);
ret = o_create(ret);
ret.descs = o_create(ret.descs);
ret.watching = o_create(ret.watching);
ret.cache = {};
ret.source = obj;
if (MANDATORY_SETTER) { ret.values = o_create(ret.values); }
obj[META_KEY] = ret;
}
return ret;
};
Ember.getMeta = function getMeta(obj, property) {
var meta = Ember.meta(obj, false);
return meta[property];
};
Ember.setMeta = function setMeta(obj, property, value) {
var meta = Ember.meta(obj, true);
meta[property] = value;
return value;
};
/**
@private
In order to store defaults for a class, a prototype may need to create
a default meta object, which will be inherited by any objects instantiated
from the class's constructor.
However, the properties of that meta object are only shallow-cloned,
so if a property is a hash (like the event system's `listeners` hash),
it will by default be shared across all instances of that class.
This method allows extensions to deeply clone a series of nested hashes or
other complex objects. For instance, the event system might pass
['listeners', 'foo:change', 'ember157'] to `prepareMetaPath`, which will
walk down the keys provided.
For each key, if the key does not exist, it is created. If it already
exists and it was inherited from its constructor, the constructor's
key is cloned.
You can also pass false for `writable`, which will simply return
undefined if `prepareMetaPath` discovers any part of the path that
shared or undefined.
@param {Object} obj The object whose meta we are examining
@param {Array} path An array of keys to walk down
@param {Boolean} writable whether or not to create a new meta
(or meta property) if one does not already exist or if it's
shared with its constructor
*/
Ember.metaPath = function metaPath(obj, path, writable) {
var meta = Ember.meta(obj, writable), keyName, value;
for (var i=0, l=path.length; i<l; i++) {
keyName = path[i];
value = meta[keyName];
if (!value) {
if (!writable) { return undefined; }
value = meta[keyName] = { __ember_source__: obj };
} else if (value.__ember_source__ !== obj) {
if (!writable) { return undefined; }
value = meta[keyName] = o_create(value);
value.__ember_source__ = obj;
}
meta = value;
}
return value;
};
/**
@private
Wraps the passed function so that `this._super` will point to the superFunc
when the function is invoked. This is the primitive we use to implement
calls to super.
@param {Function} func
The function to call
@param {Function} superFunc
The super function.
@returns {Function} wrapped function.
*/
Ember.wrap = function(func, superFunc) {
function K() {}
var newFunc = function() {
var ret, sup = this._super;
this._super = superFunc || K;
ret = func.apply(this, arguments);
this._super = sup;
return ret;
};
newFunc.base = func;
return newFunc;
};
/**
Returns true if the passed object is an array or Array-like.
Ember Array Protocol:
- the object has an objectAt property
- the object is a native Array
- the object is an Object, and has a length property
Unlike Ember.typeOf this method returns true even if the passed object is
not formally array but appears to be array-like (i.e. implements Ember.Array)
Ember.isArray(); // false
Ember.isArray([]); // true
Ember.isArray( Ember.ArrayProxy.create({ content: [] }) ); // true
@param {Object} obj The object to test
@returns {Boolean}
*/
Ember.isArray = function(obj) {
if (!obj || obj.setInterval) { return false; }
if (Array.isArray && Array.isArray(obj)) { return true; }
if (Ember.Array && Ember.Array.detect(obj)) { return true; }
if ((obj.length !== undefined) && 'object'===typeof obj) { return true; }
return false;
};
/**
Forces the passed object to be part of an array. If the object is already
an array or array-like, returns the object. Otherwise adds the object to
an array. If obj is null or undefined, returns an empty array.
Ember.makeArray(); => []
Ember.makeArray(null); => []
Ember.makeArray(undefined); => []
Ember.makeArray('lindsay'); => ['lindsay']
Ember.makeArray([1,2,42]); => [1,2,42]
var controller = Ember.ArrayProxy.create({ content: [] });
Ember.makeArray(controller) === controller; => true
@param {Object} obj the object
@returns {Array}