From 76d4eb3b3c352079a25122274011f8b04eab3a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sat, 12 Oct 2019 21:15:24 +0200 Subject: [PATCH 01/11] Remove utils.arrayIndexOf --- src/common/utils.js | 15 +-------------- test/test.utils.js | 15 --------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 82274ff76..d9978ebdd 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -47,24 +47,11 @@ utils.defineGetterSetter = function (obj, key, getFunc, opt_setFunc) { */ utils.defineGetter = utils.defineGetterSetter; -utils.arrayIndexOf = function (a, item) { - if (a.indexOf) { - return a.indexOf(item); - } - var len = a.length; - for (var i = 0; i < len; ++i) { - if (a[i] === item) { - return i; - } - } - return -1; -}; - /** * Returns whether the item was found in the array. */ utils.arrayRemove = function (a, item) { - var index = utils.arrayIndexOf(a, item); + var index = a.indexOf(item); if (index !== -1) { a.splice(index, 1); } diff --git a/test/test.utils.js b/test/test.utils.js index 30c8f25c6..6ba1527ee 100644 --- a/test/test.utils.js +++ b/test/test.utils.js @@ -22,21 +22,6 @@ describe('utils', function () { var utils = cordova.require('cordova/utils'); - describe('utils.arrayIndexOf', function () { - it('Test#001 : should return -1 when not found', function () { - expect(utils.arrayIndexOf([1, 2, 3], 4)).toBe(-1); - }); - it('Test#002 : should return 0 for first item', function () { - expect(utils.arrayIndexOf([1, 2, 3], 1)).toBe(0); - }); - it('Test#003 : should return 2 for last item', function () { - expect(utils.arrayIndexOf([1, 2, 3], 3)).toBe(2); - }); - it('Test#004 : should return index of first occurance', function () { - expect(utils.arrayIndexOf([1, 2, 1], 1)).toBe(0); - }); - }); - describe('utils.arrayRemove', function () { it('Test#005 : should return true when removed.', function () { var a = [1, 2, 3]; From fbf05addf5d4d300608feae477d5f781ff4d5b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 20:29:10 +0200 Subject: [PATCH 02/11] Remove utils.arrayRemove --- src/common/utils.js | 11 ----------- test/test.utils.js | 18 ------------------ 2 files changed, 29 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index d9978ebdd..5c4b39811 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -47,17 +47,6 @@ utils.defineGetterSetter = function (obj, key, getFunc, opt_setFunc) { */ utils.defineGetter = utils.defineGetterSetter; -/** - * Returns whether the item was found in the array. - */ -utils.arrayRemove = function (a, item) { - var index = a.indexOf(item); - if (index !== -1) { - a.splice(index, 1); - } - return index !== -1; -}; - utils.typeName = function (val) { return Object.prototype.toString.call(val).slice(8, -1); }; diff --git a/test/test.utils.js b/test/test.utils.js index 6ba1527ee..6948e5fc5 100644 --- a/test/test.utils.js +++ b/test/test.utils.js @@ -22,24 +22,6 @@ describe('utils', function () { var utils = cordova.require('cordova/utils'); - describe('utils.arrayRemove', function () { - it('Test#005 : should return true when removed.', function () { - var a = [1, 2, 3]; - expect(utils.arrayRemove(a, 2)).toBe(true); - expect(a).toEqual([1, 3]); - }); - it('Test#006 : should return false when item was not there.', function () { - var a = [1, 2, 3]; - expect(utils.arrayRemove(a, 4)).toBe(false); - expect(a).toEqual([1, 2, 3]); - }); - it('Test#007 : should remove only first occurance', function () { - var a = [1, 2, 1]; - expect(utils.arrayRemove(a, 1)).toBe(true); - expect(a).toEqual([2, 1]); - }); - }); - describe('isArray', function () { it('Test#008 : should return true for [].', function () { var isArray = utils.isArray([]); From 458fc36ed77013ebdfed52247c74bf9de24ed03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 21:32:49 +0200 Subject: [PATCH 03/11] Remove utils.close --- src/common/channel.js | 3 +-- src/common/utils.js | 10 ---------- test/test.utils.js | 27 --------------------------- 3 files changed, 1 insertion(+), 39 deletions(-) diff --git a/src/common/channel.js b/src/common/channel.js index 03c76c976..c0deab86d 100644 --- a/src/common/channel.js +++ b/src/common/channel.js @@ -19,7 +19,6 @@ * */ -var utils = require('cordova/utils'); var nextGuid = 1; /** @@ -171,7 +170,7 @@ Channel.prototype.subscribe = function (eventListenerOrFunction, eventListener) guid = eventListenerOrFunction.observer_guid; if (typeof eventListener === 'object') { - handleEvent = utils.close(eventListener, handleEvent); + handleEvent = handleEvent.bind(eventListener); } if (!guid) { diff --git a/src/common/utils.js b/src/common/utils.js index 5c4b39811..390b5c7d0 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -95,16 +95,6 @@ utils.clone = function (obj) { return retVal; }; -/** - * Returns a wrapped version of the function - */ -utils.close = function (context, func, params) { - return function () { - var args = params || arguments; - return func.apply(context, args); - }; -}; - // ------------------------------------------------------------------------------ function UUIDcreatePart (length) { var uuidpart = ''; diff --git a/test/test.utils.js b/test/test.utils.js index 6948e5fc5..f0fb4215b 100644 --- a/test/test.utils.js +++ b/test/test.utils.js @@ -107,33 +107,6 @@ describe('utils', function () { }); }); - describe('when closing around a function', function () { - it('Test#021 : calls the original function when calling the closed function', function () { - var f = jasmine.createSpy(); - utils.close(null, f)(); - expect(f).toHaveBeenCalled(); - }); - - it('Test#022 : uses the correct context for the closed function', function () { - var context = {}; - utils.close(context, function () { - expect(this).toBe(context); - })(); - }); - - it('Test#023 : passes the arguments to the closed function', function () { - utils.close(null, function (arg) { - expect(arg).toBe(1); - })(1); - }); - - it('Test#024 : overrides the arguments when provided', function () { - utils.close(null, function (arg) { - expect(arg).toBe(42); - }, [42])(16); - }); - }); - it('Test#025 : can create a uuid', function () { var uuid = utils.createUUID(); expect(uuid).toMatch(/^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$/); From 6e3a992aa5b81ea2d96253aff5f71878a611f97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 21:52:49 +0200 Subject: [PATCH 04/11] Remove utils.alert --- src/common/builder.js | 2 +- src/common/utils.js | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/common/builder.js b/src/common/builder.js index 7b6dc408c..c43ad64b7 100644 --- a/src/common/builder.js +++ b/src/common/builder.js @@ -89,7 +89,7 @@ function include (parent, objects, clobber, merge) { include(result, obj.children, clobber, merge); } } catch (e) { - utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"'); + console.error('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"'); } }); } diff --git a/src/common/utils.js b/src/common/utils.js index 390b5c7d0..4f654aa81 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -134,14 +134,3 @@ utils.extend = (function () { Child.prototype.constructor = Child; }; }()); - -/** - * Alerts a message in any available way: alert or console.log. - */ -utils.alert = function (msg) { - if (window.alert) { - window.alert(msg); - } else if (console && console.log) { - console.log(msg); - } -}; From 1ac6c68ae74c364a58ea82fa2c8bcf5af2c62d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 22:21:22 +0200 Subject: [PATCH 05/11] Remove utils.isDate --- src/common/utils.js | 9 +-------- test/test.utils.js | 11 ----------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 4f654aa81..566473f63 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -57,18 +57,11 @@ utils.typeName = function (val) { utils.isArray = Array.isArray || function (a) { return utils.typeName(a) === 'Array'; }; -/** - * Returns an indication of whether the argument is a Date or not - */ -utils.isDate = function (d) { - return (d instanceof Date); -}; - /** * Does a deep clone of the object. */ utils.clone = function (obj) { - if (!obj || typeof obj === 'function' || utils.isDate(obj) || typeof obj !== 'object') { + if (!obj || typeof obj === 'function' || obj instanceof Date || typeof obj !== 'object') { return obj; } diff --git a/test/test.utils.js b/test/test.utils.js index f0fb4215b..aa742c869 100644 --- a/test/test.utils.js +++ b/test/test.utils.js @@ -38,17 +38,6 @@ describe('utils', function () { }); }); - describe('isDate', function () { - it('Test#011 : should return true for new Date().', function () { - var isDate = utils.isDate(new Date()); - expect(isDate).toBe(true); - }); - it('Test#012 : should return false for {}.', function () { - var isDate = utils.isDate({}); - expect(isDate).toBe(false); - }); - }); - describe('when cloning', function () { it('Test#013 : can clone an array', function () { var orig = [1, 2, 3, { four: 4 }, '5']; From fe923f00fcf75a540bf17b953029baf25fe0e962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 22:42:50 +0200 Subject: [PATCH 06/11] Remove utils.isArray --- src/common/utils.js | 8 +------- test/test.utils.js | 16 ---------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 566473f63..ace75aaaf 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -51,12 +51,6 @@ utils.typeName = function (val) { return Object.prototype.toString.call(val).slice(8, -1); }; -/** - * Returns an indication of whether the argument is an array or not - */ -utils.isArray = Array.isArray || - function (a) { return utils.typeName(a) === 'Array'; }; - /** * Does a deep clone of the object. */ @@ -67,7 +61,7 @@ utils.clone = function (obj) { var retVal, i; - if (utils.isArray(obj)) { + if (Array.isArray(obj)) { retVal = []; for (i = 0; i < obj.length; ++i) { retVal.push(utils.clone(obj[i])); diff --git a/test/test.utils.js b/test/test.utils.js index aa742c869..3f8fb023c 100644 --- a/test/test.utils.js +++ b/test/test.utils.js @@ -22,22 +22,6 @@ describe('utils', function () { var utils = cordova.require('cordova/utils'); - describe('isArray', function () { - it('Test#008 : should return true for [].', function () { - var isArray = utils.isArray([]); - expect(isArray).toBe(true); - }); - it('Test#009 : should return true for new Array().', function () { - // eslint-disable-next-line no-array-constructor - var isArray = utils.isArray(new Array()); - expect(isArray).toBe(true); - }); - it('Test#010 : should return false for {}.', function () { - var isArray = utils.isArray({}); - expect(isArray).toBe(false); - }); - }); - describe('when cloning', function () { it('Test#013 : can clone an array', function () { var orig = [1, 2, 3, { four: 4 }, '5']; From d99d1320dae686b5578a03b8f2dea3cf5dd56925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 22:58:44 +0200 Subject: [PATCH 07/11] Remove argscheck.enableChecks --- src/common/argscheck.js | 4 ---- test/test.argscheck.js | 5 ----- 2 files changed, 9 deletions(-) diff --git a/src/common/argscheck.js b/src/common/argscheck.js index c94c5ec89..98514b4b1 100644 --- a/src/common/argscheck.js +++ b/src/common/argscheck.js @@ -66,9 +66,6 @@ function extractParamName (callee, argIndex) { * @throws {TypeError} if args do not satisfy spec */ function checkArgs (spec, functionName, args, opt_callee) { - if (!moduleExports.enableChecks) { - return; - } var errMsg = null; var typeName; for (var i = 0; i < spec.length; ++i) { @@ -105,4 +102,3 @@ function getValue (value, defaultValue) { moduleExports.checkArgs = checkArgs; moduleExports.getValue = getValue; -moduleExports.enableChecks = true; diff --git a/test/test.argscheck.js b/test/test.argscheck.js index 60fd02f3a..15d812f3d 100644 --- a/test/test.argscheck.js +++ b/test/test.argscheck.js @@ -73,11 +73,6 @@ describe('argscheck', function () { var testFunc = createTestFunc(true); expect(function () { testFunc(null, null, null, null, null, new Date()); }).toThrowError('Wrong type for parameter "func" of testFunc: Expected Function, but got Date.'); }); - it('Test#011 : should not throw when checking is disabled', function () { - var testFunc = createTestFunc(false); - argscheck.enableChecks = false; - testFunc(); - }); it('Test#012 : should be able to extract from all kinds of parameter formats', () => { const check = args => argscheck.checkArgs('ss', 'testFn', args); From 7f2148be412d508d0376d02330e42b167a7ebb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 23:11:56 +0200 Subject: [PATCH 08/11] Remove unused exports from cordova/builder --- src/common/builder.js | 54 ---------------------------------- test/test.builder.js | 67 ------------------------------------------- 2 files changed, 121 deletions(-) delete mode 100644 test/test.builder.js diff --git a/src/common/builder.js b/src/common/builder.js index c43ad64b7..5ba89d530 100644 --- a/src/common/builder.js +++ b/src/common/builder.js @@ -21,14 +21,6 @@ var utils = require('cordova/utils'); -function each (objects, func, context) { - for (var prop in objects) { - if (objects.hasOwnProperty(prop)) { - func.apply(context, [objects[prop], prop]); - } - } -} - function clobber (obj, key, value) { var needsProperty = false; try { @@ -57,43 +49,6 @@ function assignOrWrapInDeprecateGetter (obj, key, value, message) { } } -function include (parent, objects, clobber, merge) { - each(objects, function (obj, key) { - try { - var result = obj.path ? require(obj.path) : {}; - - if (clobber) { - // Clobber if it doesn't exist. - if (typeof parent[key] === 'undefined') { - assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); - } else if (typeof obj.path !== 'undefined') { - // If merging, merge properties onto parent, otherwise, clobber. - if (merge) { - recursiveMerge(parent[key], result); - } else { - assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); - } - } - result = parent[key]; - } else { - // Overwrite if not currently defined. - if (typeof parent[key] === 'undefined') { - assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); - } else { - // Set result to what already exists, so we can build children into it if they exist. - result = parent[key]; - } - } - - if (obj.children) { - include(result, obj.children, clobber, merge); - } - } catch (e) { - console.error('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"'); - } - }); -} - /** * Merge properties from one object onto another recursively. Properties from * the src object will overwrite existing target property. @@ -118,14 +73,5 @@ function recursiveMerge (target, src) { } } -exports.buildIntoButDoNotClobber = function (objects, target) { - include(target, objects, false, false); -}; -exports.buildIntoAndClobber = function (objects, target) { - include(target, objects, true, false); -}; -exports.buildIntoAndMerge = function (objects, target) { - include(target, objects, true, true); -}; exports.recursiveMerge = recursiveMerge; exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter; diff --git a/test/test.builder.js b/test/test.builder.js deleted file mode 100644 index 8901d2c37..000000000 --- a/test/test.builder.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * -*/ - -describe('builder', function () { - var builder = cordova.require('cordova/builder'); - - it('Test#001 : includes the module into the target', function () { - var target = {}; - var objects = { - foo: { - path: 'cordova/builder' - } - }; - - builder.buildIntoAndClobber(objects, target); - expect(target.foo).toBeDefined(); - expect(target.foo).toBe(cordova.require('cordova/builder')); - }); - - it('Test#002 : returns an empty object literal if no path', function () { - var target = {}; - var objects = { cat: {} }; - - builder.buildIntoButDoNotClobber(objects, target); - - expect(target.cat).toBeDefined(); - }); - - it('Test#003 : builds out the children', function () { - var target = {}; - var objects = { - homer: { - children: { - bart: {}, - lisa: {}, - maggie: { - path: 'cordova/builder' - } - } - } - }; - - builder.buildIntoButDoNotClobber(objects, target); - - expect(target.homer.bart).toBeDefined(); - expect(target.homer.maggie).toBe(cordova.require('cordova/builder')); - expect(target.homer.lisa).toBeDefined(); - }); -}); From b134a9bf6472c03988dab6faa88064be584cb94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 23:30:29 +0200 Subject: [PATCH 09/11] Remove modulemapper.defaults --- src/common/modulemapper.js | 6 +----- test/test.modulemapper.js | 23 ----------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/src/common/modulemapper.js b/src/common/modulemapper.js index d815a99ed..a94fb215a 100644 --- a/src/common/modulemapper.js +++ b/src/common/modulemapper.js @@ -47,10 +47,6 @@ exports.merges = function (moduleName, symbolPath, opt_deprecationMessage) { addEntry('m', moduleName, symbolPath, opt_deprecationMessage); }; -exports.defaults = function (moduleName, symbolPath, opt_deprecationMessage) { - addEntry('d', moduleName, symbolPath, opt_deprecationMessage); -}; - exports.runs = function (moduleName) { addEntry('r', moduleName, null); }; @@ -86,7 +82,7 @@ exports.mapModules = function (context) { if (strategy === 'm' && target) { builder.recursiveMerge(target, module); - } else if ((strategy === 'd' && !target) || (strategy !== 'd')) { + } else { if (!(symbolPath in origSymbols)) { origSymbols[symbolPath] = target; } diff --git a/test/test.modulemapper.js b/test/test.modulemapper.js index 61c9b94f1..79f5f87e4 100644 --- a/test/test.modulemapper.js +++ b/test/test.modulemapper.js @@ -56,38 +56,30 @@ describe('modulemapper', function () { }); it('Test#002 : should properly set a new top-level property', function () { modulemapper.clobbers('cordova/test/testmodule', 'newProp1'); - modulemapper.defaults('cordova/test/testmodule', 'newProp2'); modulemapper.merges('cordova/test/testmodule', 'newProp3'); modulemapper.mapModules(context); expect(context.newProp1).toBe(testmodule); - expect(context.newProp2).toBe(testmodule); expect(context.newProp3).toBe(testmodule); }); it('Test#003 : should properly set a new non-top-level property', function () { modulemapper.clobbers('cordova/test/testmodule', 'foo1.newProp'); - modulemapper.defaults('cordova/test/testmodule', 'foo2.newProp'); modulemapper.merges('cordova/test/testmodule', 'foo3.newProp'); modulemapper.mapModules(context); expect(context.foo1.newProp).toBe(testmodule); - expect(context.foo2.newProp).toBe(testmodule); expect(context.foo3.newProp).toBe(testmodule); }); it('Test#004 : should properly set a new non-top-level property #2', function () { modulemapper.clobbers('cordova/test/testmodule', 'foo1.bar.newProp'); - modulemapper.defaults('cordova/test/testmodule', 'foo2.bar.newProp'); modulemapper.merges('cordova/test/testmodule', 'foo3.bar.newProp'); modulemapper.mapModules(context); expect(context.foo1.bar.newProp).toBe(testmodule); - expect(context.foo2.bar.newProp).toBe(testmodule); expect(context.foo3.bar.newProp).toBe(testmodule); }); it('Test#005 : should properly set a non-new non-top-level property', function () { modulemapper.clobbers('cordova/test/testmodule', 'obj.newProp1'); - modulemapper.defaults('cordova/test/testmodule', 'obj.newProp2'); modulemapper.merges('cordova/test/testmodule', 'obj.newProp3'); modulemapper.mapModules(context); expect(context.obj.newProp1).toBe(testmodule); - expect(context.obj.newProp2).toBe(testmodule); expect(context.obj.newProp3).toBe(testmodule); }); it('Test#006 : should clobber existing properties', function () { @@ -101,17 +93,6 @@ describe('modulemapper', function () { expect(context.getme).toBe(testmodule); expect(context.TestClass).toBe(testmodule); }); - it('Test#007 : should not clobber existing properties when using defaults', function () { - modulemapper.defaults('cordova/test/testmodule', 'num'); - modulemapper.defaults('cordova/test/testmodule', 'obj.str'); - modulemapper.defaults('cordova/test/testmodule', 'obj.getme'); - modulemapper.defaults('cordova/test/testmodule', 'TestClass'); - modulemapper.mapModules(context); - expect(context.num).not.toBe(testmodule); - expect(context.obj.str).not.toBe(testmodule); - expect(context.getme).not.toBe(testmodule); - expect(context.TestClass).not.toBe(testmodule); - }); it('Test#008 : should throw when namespace is a non-object', function () { expect(function () { modulemapper.merges('cordova/test/testmodule', 'num'); @@ -179,13 +160,9 @@ describe('modulemapper', function () { it('Test#017 : should log about deprecated property access', function () { spyOn(console, 'log'); modulemapper.clobbers('cordova/test/testmodule', 'obj', 'Use foo instead'); - modulemapper.defaults('cordova/test/testmodule', 'newProp', 'Use foo instead'); modulemapper.mapModules(context); context.obj.func(); context.obj.func(); expect(console.log).toHaveBeenCalledTimes(1); - context.newProp.func(); - context.newProp.func(); - expect(console.log).toHaveBeenCalledTimes(2); }); }); From 239eb81778518228eccb1f14b5e2d6f7a5f9901d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 13 Oct 2019 23:56:41 +0200 Subject: [PATCH 10/11] Inline cordova/builder into cordova/modulemapper --- src/common/builder.js | 77 -------------------------------------- src/common/modulemapper.js | 58 ++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 80 deletions(-) delete mode 100644 src/common/builder.js diff --git a/src/common/builder.js b/src/common/builder.js deleted file mode 100644 index 5ba89d530..000000000 --- a/src/common/builder.js +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * -*/ - -var utils = require('cordova/utils'); - -function clobber (obj, key, value) { - var needsProperty = false; - try { - obj[key] = value; - } catch (e) { - needsProperty = true; - } - // Getters can only be overridden by getters. - if (needsProperty || obj[key] !== value) { - utils.defineGetter(obj, key, function () { - return value; - }); - } -} - -function assignOrWrapInDeprecateGetter (obj, key, value, message) { - if (message) { - utils.defineGetter(obj, key, function () { - console.log(message); - delete obj[key]; - clobber(obj, key, value); - return value; - }); - } else { - clobber(obj, key, value); - } -} - -/** - * Merge properties from one object onto another recursively. Properties from - * the src object will overwrite existing target property. - * - * @param target Object to merge properties into. - * @param src Object to merge properties from. - */ -function recursiveMerge (target, src) { - for (var prop in src) { - if (src.hasOwnProperty(prop)) { - if (target.prototype && target.prototype.constructor === target) { - // If the target object is a constructor override off prototype. - clobber(target.prototype, prop, src[prop]); - } else { - if (typeof src[prop] === 'object' && typeof target[prop] === 'object') { - recursiveMerge(target[prop], src[prop]); - } else { - clobber(target, prop, src[prop]); - } - } - } - } -} - -exports.recursiveMerge = recursiveMerge; -exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter; diff --git a/src/common/modulemapper.js b/src/common/modulemapper.js index a94fb215a..40318eb37 100644 --- a/src/common/modulemapper.js +++ b/src/common/modulemapper.js @@ -18,7 +18,7 @@ * */ -var builder = require('cordova/builder'); +var utils = require('cordova/utils'); var moduleMap = define.moduleMap; var symbolList; var deprecationMap; @@ -60,6 +60,58 @@ function prepareNamespace (symbolPath, context) { }, context); } +function clobber (obj, key, value) { + var needsProperty = false; + try { + obj[key] = value; + } catch (e) { + needsProperty = true; + } + // Getters can only be overridden by getters. + if (needsProperty || obj[key] !== value) { + utils.defineGetter(obj, key, function () { + return value; + }); + } +} + +function assignOrWrapInDeprecateGetter (obj, key, value, message) { + if (message) { + utils.defineGetter(obj, key, function () { + console.log(message); + delete obj[key]; + clobber(obj, key, value); + return value; + }); + } else { + clobber(obj, key, value); + } +} + +/** + * Merge properties from one object onto another recursively. Properties from + * the src object will overwrite existing target property. + * + * @param target Object to merge properties into. + * @param src Object to merge properties from. + */ +function recursiveMerge (target, src) { + for (var prop in src) { + if (src.hasOwnProperty(prop)) { + if (target.prototype && target.prototype.constructor === target) { + // If the target object is a constructor override off prototype. + clobber(target.prototype, prop, src[prop]); + } else { + if (typeof src[prop] === 'object' && typeof target[prop] === 'object') { + recursiveMerge(target[prop], src[prop]); + } else { + clobber(target, prop, src[prop]); + } + } + } + } +} + exports.mapModules = function (context) { var origSymbols = {}; context.CDV_origSymbols = origSymbols; @@ -81,12 +133,12 @@ exports.mapModules = function (context) { var target = parentObj[lastName]; if (strategy === 'm' && target) { - builder.recursiveMerge(target, module); + recursiveMerge(target, module); } else { if (!(symbolPath in origSymbols)) { origSymbols[symbolPath] = target; } - builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg); + assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg); } } }; From a5c275f9b00ee5bb36539970eb24ac72acbb97fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Mon, 14 Oct 2019 00:19:25 +0200 Subject: [PATCH 11/11] Remove unused cordova.addConstructor --- src/cordova.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/cordova.js b/src/cordova.js index c88e2f982..6012e6e5d 100644 --- a/src/cordova.js +++ b/src/cordova.js @@ -237,16 +237,6 @@ var cordova = { cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg, 'error': err }); throw err; } - }, - - addConstructor: function (func) { - channel.onCordovaReady.subscribe(function () { - try { - func(); - } catch (e) { - console.log('Failed to run constructor: ' + e); - } - }); } };