You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/10/22 17:45:20 UTC
[10/25] js commit: [all] Fix pluginloader never finishing (broken by
recent commit) (cherry picked from commit
553681f0adf55c8928be8d72164f22e17323f496)
[all] Fix pluginloader never finishing (broken by recent commit)
(cherry picked from commit 553681f0adf55c8928be8d72164f22e17323f496)
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/5f9b6705
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/5f9b6705
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/5f9b6705
Branch: refs/heads/2.9.x
Commit: 5f9b67050ecbbb86d72bc5a2003d2f7a0cdd6644
Parents: d3ba335
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Jul 10 11:38:25 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Oct 22 11:35:54 2013 -0400
----------------------------------------------------------------------
lib/common/pluginloader.js | 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/5f9b6705/lib/common/pluginloader.js
----------------------------------------------------------------------
diff --git a/lib/common/pluginloader.js b/lib/common/pluginloader.js
index 7341e14..002f944 100644
--- a/lib/common/pluginloader.js
+++ b/lib/common/pluginloader.js
@@ -22,19 +22,8 @@
var channel = require('cordova/channel');
var modulemapper = require('cordova/modulemapper');
-var scriptCounter = 0;
-var moduleList = null;
-
-function scriptLoadedCallback() {
- scriptCounter--;
- if (scriptCounter === 0) {
- onScriptLoadingComplete();
- }
-}
-
// Helper function to inject a <script> tag.
function injectScript(url, onload, onerror) {
- scriptCounter++;
var script = document.createElement("script");
// onload fires even when script fails loads with an error.
script.onload = onload;
@@ -43,10 +32,9 @@ function injectScript(url, onload, onerror) {
document.head.appendChild(script);
}
-function onScriptLoadingComplete() {
+function onScriptLoadingComplete(moduleList) {
// Loop through all the plugins and then through their clobbers and merges.
- for (var i = 0; i < moduleList.length; i++) {
- var module = moduleList[i];
+ for (var i = 0, module; module = moduleList[i]; i++) {
if (module) {
try {
if (module.clobbers && module.clobbers.length) {
@@ -88,8 +76,15 @@ function finishPluginLoading() {
// See plugman's plugin_loader.js for the details of this object.
// This function is only called if the really is a plugins array that isn't empty.
// Otherwise the onerror response handler will just call finishPluginLoading().
-function handlePluginsObject(path) {
+function handlePluginsObject(path, moduleList) {
// Now inject the scripts.
+ var scriptCounter = moduleList.length;
+ function scriptLoadedCallback() {
+ if (!--scriptCounter) {
+ onScriptLoadingComplete(moduleList);
+ }
+ }
+
for (var i = 0; i < moduleList.length; i++) {
injectScript(path + moduleList[i].file, scriptLoadedCallback);
}
@@ -98,8 +93,8 @@ function handlePluginsObject(path) {
function injectPluginScript(pathPrefix) {
injectScript(pathPrefix + 'cordova_plugins.js', function(){
try {
- moduleList = require("cordova/plugin_list");
- handlePluginsObject(pathPrefix);
+ var moduleList = require("cordova/plugin_list");
+ handlePluginsObject(pathPrefix, moduleList);
} catch (e) {
// Error loading cordova_plugins.js, file not found or something
// this is an acceptable error, pre-3.0.0, so we just move on.