You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/09/22 19:36:20 UTC
[royale-compiler] branch develop updated: JSRoyaleEmitter: when
inserting a synthetic second argument for parseInt() pass 0 instead of
undefined
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 179edad JSRoyaleEmitter: when inserting a synthetic second argument for parseInt() pass 0 instead of undefined
179edad is described below
commit 179edad95b4bd8c859c8940b9316f9980ad4579a
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Sep 22 12:34:37 2021 -0700
JSRoyaleEmitter: when inserting a synthetic second argument for parseInt() pass 0 instead of undefined
undefined can't be used as a NumericLiteralNode because it results in the compiler throwing a NumberFormatException. According to the ECMAScript spec, parseInt() treats 0, NaN, and Infinity the same as undefined, so 0 is fine. Fun fact: Technically, undefined is coerced to NaN when calling parseInt().
---
.../royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java | 2 +-
.../compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
index 49bdf23..6cfd566 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
@@ -1004,7 +1004,7 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
if (nameNode instanceof IdentifierNode)
{
//see FLEX-35283
- LiteralNode appendedArgument = new NumericLiteralNode("undefined");
+ LiteralNode appendedArgument = new NumericLiteralNode("0");
appendedArgument.setSynthetic(true);
newNode = EmitterUtils.insertArgumentsAfter(node, appendedArgument);
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
index 83af814..e293ad0 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
@@ -115,7 +115,7 @@ public class TestRoyaleGlobalFunctions extends TestGoogGlobalFunctions
{
IVariableNode node = getVariable("var a:Number = parseInt('1.8');");
asBlockWalker.visitVariable(node);
- assertOut("var /** @type {number} */ a = parseInt('1.8', undefined)");
+ assertOut("var /** @type {number} */ a = parseInt('1.8', 0)");
}
@Test