Permalink
Browse files

0.6.4: curl now restores any previous curl() or define() if the dev r…

…eassigns either using apiContext/apiName or defineContext/defineName
  • Loading branch information...
1 parent 450fd7a commit 690284b42e9d58c6f22b1e78ac1375d4e4d0b8f6 John Hann committed Jun 6, 2012
Showing with 27 additions and 7 deletions.
  1. +3 −0 README.md
  2. +6 −3 src/curl.js
  3. +10 −3 test/apiConflict.html
  4. +8 −1 test/defineConflict.html
View
@@ -20,6 +20,9 @@ Helpful link for updating submodules:
What's New?
=======
+* 0.6.4
+ * curl now restores any previous curl() or define() if the dev reassigns
+ either using apiContext/apiName or defineContext/defineName
* 0.6.3
* fix !exports option of js! plugin when file is compressed
* now resolves arbitrarily deep double-dot module ids (dojo and node compatibility)
View
@@ -9,12 +9,12 @@
* Licensed under the MIT License at:
* http://www.opensource.org/licenses/mit-license.php
*
- * @version 0.6.3
+ * @version 0.6.4
*/
(function (global) {
"use strict";
var
- version = '0.6.3',
+ version = '0.6.4',
userCfg = global['curl'],
prevCurl,
prevDefine,
@@ -371,7 +371,8 @@
throw new Error((apiName || 'curl') + ' already exists');
}
(apiObj || global)[apiName || 'curl'] = _curl;
-
+ // restore previous curl
+ if (prevCurl && hasCfg) global['curl'] = prevCurl;
// allow dev to rename/relocate define() to another object
defName = cfg['defineName'];
@@ -384,6 +385,8 @@
var args = core.fixArgs(arguments);
_define(args);
};
+ // restore previous define
+ if (prevDefine && hasCfg) global['define'] = prevDefine;
// indicate our capabilities:
define['amd'] = { 'plugins': true, 'jQuery': true, 'curl': version };
View
@@ -4,7 +4,7 @@
<title>noConflict api test</title>
<script>
-var curl = function () {};
+var curl = function () {}, orig = curl;
</script>
<script src="../src/curl.js" type="text/javascript"></script>
</head>
@@ -20,12 +20,19 @@
}
}
);
- write('FAILED: curl overwrote global curl');
+ write('FAILED: curl should not overwrite global curl');
}
catch (ex) {
- write('SUCCESS: curl threw when it conflicted with no recourse: ' + ex.message);
+ write('SUCCESS: curl should threw when it conflicted with no recourse: ' + ex.message);
}
+curl({
+ apiContext: this, apiName: 'curl2'
+});
+
+write((orig == curl ? 'SUCCESS' : 'FAILED') + ': curl should restore previous curl()');
+write((curl2 ? 'SUCCESS' : 'FAILED') + ': curl should create non-conflicting curl2()');
+
function write (msg) {
document.body.appendChild(document.createElement('div')).innerHTML = msg;
}
@@ -4,7 +4,7 @@
<title>noConflict define test</title>
<script>
-var define = function () {};
+var define = function () {}, orig = define;
</script>
<script src="../src/curl.js" type="text/javascript"></script>
</head>
@@ -26,6 +26,13 @@
write('SUCCESS: curl threw when it conflicted with no recourse: ' + ex.message);
}
+curl({
+ defineContext: this, defineName: 'define2'
+});
+
+write((orig == define ? 'SUCCESS' : 'FAILED') + ': curl should restore previous define()');
+write((define2 ? 'SUCCESS' : 'FAILED') + ': curl should create non-conflicting define2()');
+
function write (msg) {
document.body.appendChild(document.createElement('div')).innerHTML = msg;
}

0 comments on commit 690284b

Please sign in to comment.