@@ -237,6 +237,50 @@ function findPrototypeDescriptor(className, property) {
237237 return undefined;
238238 }
239239
240+ function nativeExtensionMethodsWithIndexedCollectionAliases(methods) {
241+ if (methods == null || typeof methods !== 'object') {
242+ return methods;
243+ }
244+
245+ var needsObjectAtIndexedSubscript =
246+ Object.prototype.hasOwnProperty.call(methods, 'objectAtIndex') &&
247+ !Object.prototype.hasOwnProperty.call(methods, 'objectAtIndexedSubscript');
248+ var needsSetObjectAtIndexedSubscript =
249+ Object.prototype.hasOwnProperty.call(methods, 'replaceObjectAtIndexWithObject') &&
250+ !Object.prototype.hasOwnProperty.call(methods, 'setObjectAtIndexedSubscript');
251+
252+ if (!needsObjectAtIndexedSubscript && !needsSetObjectAtIndexedSubscript) {
253+ return methods;
254+ }
255+
256+ var prepared = Object.create(Object.getPrototypeOf(methods));
257+ Object.defineProperties(prepared, Object.getOwnPropertyDescriptors(methods));
258+
259+ if (needsObjectAtIndexedSubscript) {
260+ Object.defineProperty(prepared, 'objectAtIndexedSubscript', {
261+ configurable: true,
262+ enumerable: false,
263+ writable: true,
264+ value: function(index) {
265+ return this.objectAtIndex(index);
266+ }
267+ });
268+ }
269+
270+ if (needsSetObjectAtIndexedSubscript) {
271+ Object.defineProperty(prepared, 'setObjectAtIndexedSubscript', {
272+ configurable: true,
273+ enumerable: false,
274+ writable: true,
275+ value: function(anObject, index) {
276+ return this.replaceObjectAtIndexWithObject(index, anObject);
277+ }
278+ });
279+ }
280+
281+ return prepared;
282+ }
283+
240284 Object.defineProperty(globalThis, '__nativeScriptCreateNativeApiIterator', {
241285 configurable: false,
242286 enumerable: false,
@@ -708,6 +752,7 @@ function rememberInstanceClass(instance) {
708752 if (methods == null || typeof methods !== 'object') {
709753 throw new Error('extend() first parameter must be an object');
710754 }
755+ var extensionMethods = nativeExtensionMethodsWithIndexedCollectionAliases(methods);
711756 var extendOptions = options || {};
712757 if (typeof Symbol === 'function' &&
713758 Object.prototype.hasOwnProperty.call(methods, Symbol.iterator)) {
@@ -719,18 +764,18 @@ function rememberInstanceClass(instance) {
719764 extendOptions.__hasIterator = true;
720765 }
721766 }
722- var extendedNativeClass = api.__extendClass(nativeClass, methods , extendOptions);
767+ var extendedNativeClass = api.__extendClass(nativeClass, extensionMethods , extendOptions);
723768 var extended = wrapNativeClass(extendedNativeClass);
724769 try {
725770 Object.setPrototypeOf(extended, wrapper || constructable);
726771 } catch (_) {
727772 }
728773 var extendedPrototype = Object.create(constructable.prototype || null);
729774 try {
730- Object.defineProperties(extendedPrototype, Object.getOwnPropertyDescriptors(methods ));
775+ Object.defineProperties(extendedPrototype, Object.getOwnPropertyDescriptors(extensionMethods ));
731776 } catch (_) {
732- Object.keys(methods ).forEach(function(key) {
733- extendedPrototype[key] = methods [key];
777+ Object.keys(extensionMethods ).forEach(function(key) {
778+ extendedPrototype[key] = extensionMethods [key];
734779 });
735780 }
736781 try {
@@ -1361,7 +1406,9 @@ function materializeTypeScriptNativeClass(constructor) {
13611406 }
13621407
13631408 var nativeBase = nativeClassLikeHandle(baseWrapper);
1364- var nativeClass = api.__extendClass(nativeBase, constructor.prototype || {}, options);
1409+ var extensionMethods =
1410+ nativeExtensionMethodsWithIndexedCollectionAliases(constructor.prototype || {});
1411+ var nativeClass = api.__extendClass(nativeBase, extensionMethods, options);
13651412 var wrapper = wrapNativeClass(nativeClass);
13661413 state.wrapper = wrapper;
13671414
@@ -1370,7 +1417,7 @@ function materializeTypeScriptNativeClass(constructor) {
13701417 } catch (_) {
13711418 }
13721419 try {
1373- api.__rememberClassWrapper(nativeClass, constructor, constructor.prototype || {} );
1420+ api.__rememberClassWrapper(nativeClass, constructor, extensionMethods );
13741421 } catch (_) {
13751422 }
13761423 return wrapper;
0 commit comments