(obj: CoreObject, properties?: unknown)
| 70 | } |
| 71 | |
| 72 | function initialize(obj: CoreObject, properties?: unknown) { |
| 73 | let m = meta(obj); |
| 74 | |
| 75 | if (properties !== undefined) { |
| 76 | assert( |
| 77 | 'EmberObject.create only accepts objects.', |
| 78 | typeof properties === 'object' && properties !== null |
| 79 | ); |
| 80 | |
| 81 | assert( |
| 82 | 'EmberObject.create no longer supports mixing in other ' + |
| 83 | 'definitions, use .extend & .create separately instead.', |
| 84 | !(properties instanceof Mixin) |
| 85 | ); |
| 86 | |
| 87 | let concatenatedProperties = obj.concatenatedProperties; |
| 88 | let mergedProperties = obj.mergedProperties; |
| 89 | |
| 90 | let keyNames = Object.keys(properties); |
| 91 | |
| 92 | for (let keyName of keyNames) { |
| 93 | // SAFETY: this cast as a Record is safe because all object types can be |
| 94 | // indexed in JS, and we explicitly type it as returning `unknown`, so the |
| 95 | // result *must* be checked below. |
| 96 | let value: unknown = (properties as Record<string, unknown>)[keyName]; |
| 97 | |
| 98 | assert( |
| 99 | 'EmberObject.create no longer supports defining computed ' + |
| 100 | 'properties. Define computed properties using extend() or reopen() ' + |
| 101 | 'before calling create().', |
| 102 | !isClassicDecorator(value) |
| 103 | ); |
| 104 | assert( |
| 105 | 'EmberObject.create no longer supports defining methods that call _super.', |
| 106 | !(typeof value === 'function' && value.toString().indexOf('._super') !== -1) |
| 107 | ); |
| 108 | assert( |
| 109 | '`actions` must be provided at extend time, not at create time, ' + |
| 110 | 'when Ember.ActionHandler is used (i.e. views, controllers & routes).', |
| 111 | !(keyName === 'actions' && ActionHandler.detect(obj)) |
| 112 | ); |
| 113 | |
| 114 | let possibleDesc = descriptorForProperty(obj, keyName, m); |
| 115 | let isDescriptor = possibleDesc !== undefined; |
| 116 | |
| 117 | if (!isDescriptor) { |
| 118 | if ( |
| 119 | concatenatedProperties !== undefined && |
| 120 | concatenatedProperties.length > 0 && |
| 121 | concatenatedProperties.includes(keyName) |
| 122 | ) { |
| 123 | let baseValue = (obj as any)[keyName]; |
| 124 | if (baseValue) { |
| 125 | value = makeArray(baseValue).concat(value); |
| 126 | } else { |
| 127 | value = makeArray(value); |
| 128 | } |
| 129 | } |
no test coverage detected