You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by er...@apache.org on 2013/11/15 15:56:18 UTC

[4/9] git commit: [flex-asjs] [refs/heads/develop] - FLEX-33903 changed 'as()' method to throw an exception when a type coercion fails

FLEX-33903 changed 'as()' method to throw an exception when a type coercion fails

Signed-off-by: Erik de Bruin <er...@ixsoftware.nl>


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/7c857d7a
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/7c857d7a
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/7c857d7a

Branch: refs/heads/develop
Commit: 7c857d7a560b928e15e6ab74c9e08b2dfcfc2b6d
Parents: aa9eb9c
Author: Erik de Bruin <er...@ixsoftware.nl>
Authored: Fri Nov 15 11:33:23 2013 +0100
Committer: Erik de Bruin <er...@ixsoftware.nl>
Committed: Fri Nov 15 11:33:23 2013 +0100

----------------------------------------------------------------------
 .../src/org/apache/flex/utils/Language.js       | 31 +++++++++++++++-----
 1 file changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7c857d7a/frameworks/js/FlexJS/src/org/apache/flex/utils/Language.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/utils/Language.js b/frameworks/js/FlexJS/src/org/apache/flex/utils/Language.js
index a846467..6c55658 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/utils/Language.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/utils/Language.js
@@ -28,15 +28,32 @@ org.apache.flex.utils.Language = function() {
  *
  * @expose
  * @param {?} leftOperand The lefthand operand of the
- *     binary as operator in AS3.
+ *                        binary as operator in AS3.
  * @param {?} rightOperand The righthand operand of the
- *     binary operator in AS3.
- * @return {?} Returns the lefthand operand if it is
- *     of the type of the righthand operand, otherwise null.
+ *                         binary operator in AS3.
+ * @param {?=} opt_coercion The cast is a coercion,
+ *                          throw expception if it fails.
+ * @return {?} Returns the lefthand operand if it is of the
+ *             type of the righthand operand, otherwise null.
  */
-org.apache.flex.utils.Language.as = function(leftOperand, rightOperand) {
-  return (org.apache.flex.utils.Language.is(leftOperand, rightOperand)) ?
-      leftOperand : null;
+org.apache.flex.utils.Language.as = function(leftOperand, rightOperand, opt_coercion) {
+  var error, itIs, message;
+
+  opt_coercion = (opt_coercion !== undefined) ? opt_coercion : false;
+
+  itIs = org.apache.flex.utils.Language.is(leftOperand, rightOperand);
+
+  if (!itIs && opt_coercion) {
+    message = 'Type Coercion failed';
+    if (TypeError) {
+      error = new TypeError(message);
+    } else {
+      error = new Error(message);
+    }
+    throw error;
+  }
+
+  return (itIs) ? leftOperand : null;
 };