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/01/21 19:01:39 UTC

[7/10] js commit: [all] Use modulemapper.getOriginalSymbol() in FileReader

[all] Use modulemapper.getOriginalSymbol() in FileReader

Also changes the function to return the actual symbol if it was never
overwritten.


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/c2fe9750
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/c2fe9750
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/c2fe9750

Branch: refs/heads/master
Commit: c2fe97506b1b064f1f8be3580a734e03114ff8a3
Parents: 3c6b56e
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jan 17 13:23:28 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jan 18 12:22:11 2013 -0500

----------------------------------------------------------------------
 lib/common/modulemapper.js      |   10 +++++++++-
 lib/common/plugin/FileReader.js |    3 ++-
 test/test.modulemapper.js       |    9 +++++++--
 3 files changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c2fe9750/lib/common/modulemapper.js
----------------------------------------------------------------------
diff --git a/lib/common/modulemapper.js b/lib/common/modulemapper.js
index 18f2e5c..da5126f 100644
--- a/lib/common/modulemapper.js
+++ b/lib/common/modulemapper.js
@@ -82,7 +82,15 @@ exports.mapModules = function(context) {
 
 exports.getOriginalSymbol = function(context, symbolPath) {
     var origSymbols = context.CDV_origSymbols;
-    return origSymbols && origSymbols[symbolPath];
+    if (origSymbols && (symbolPath in origSymbols)) {
+        return origSymbols[symbolPath];
+    }
+    var parts = symbolPath.split('.');
+    var obj = context;
+    for (var i = 0; i < parts.length; ++i) {
+        obj = obj && obj[parts[i]];
+    }
+    return obj;
 };
 
 exports.loadMatchingModules = function(matchingRegExp) {

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c2fe9750/lib/common/plugin/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/FileReader.js b/lib/common/plugin/FileReader.js
index fc021b1..d48e714 100644
--- a/lib/common/plugin/FileReader.js
+++ b/lib/common/plugin/FileReader.js
@@ -20,11 +20,12 @@
 */
 
 var exec = require('cordova/exec'),
+    modulemapper = require('cordova/modulemapper'),
     utils = require('cordova/utils'),
     File = require('cordova/plugin/File'),
     FileError = require('cordova/plugin/FileError'),
     ProgressEvent = require('cordova/plugin/ProgressEvent'),
-    origFileReader = this.FileReader;
+    origFileReader = modulemapper.getOriginalSymbol(this, 'FileReader');
 
 /**
  * This class reads the mobile device file system.

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c2fe9750/test/test.modulemapper.js
----------------------------------------------------------------------
diff --git a/test/test.modulemapper.js b/test/test.modulemapper.js
index 8ae27d3..6202c9a 100644
--- a/test/test.modulemapper.js
+++ b/test/test.modulemapper.js
@@ -135,9 +135,9 @@ describe('modulemapper', function() {
         expect(context.obj.obj).toBe(testmodule.obj);
     });
     it('should return undefined for getOriginalSymbol("unknown")', function() {
-        expect(modulemapper.getOriginalSymbol(context, 'obj')).toBeUndefined();
+        expect(modulemapper.getOriginalSymbol(context, 'blah')).toBeUndefined();
         modulemapper.mapModules(context);
-        expect(modulemapper.getOriginalSymbol(context, 'obj')).toBeUndefined();
+        expect(modulemapper.getOriginalSymbol(context, 'obj.foo.bar')).toBeUndefined('obj.foo.bar');
     });
     it('should remember original symbols when clobbering', function() {
         var orig = context.obj;
@@ -145,6 +145,11 @@ describe('modulemapper', function() {
         modulemapper.mapModules(context);
         expect(modulemapper.getOriginalSymbol(context, 'obj')).toBe(orig);
     });
+    it('should return original symbols when symbol was not clobbered', function() {
+        modulemapper.mapModules(context);
+        expect(modulemapper.getOriginalSymbol(context, 'obj')).toBe(context.obj);
+        expect(modulemapper.getOriginalSymbol(context, 'obj.str')).toBe(context.obj.str);
+    });
     it('should load modules with loadMatchingModules', function() {
         var spyModules = {};
         this.after(function() {