From d6f8aa6f037b009132f555a68d13005e173a7573 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Thu, 2 Oct 2014 15:42:52 +0400 Subject: [PATCH] JS backend minor: made undefined expression static field --- .../k2js/translate/context/Namer.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java b/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java index 3eaa53c145d..60d3b5b183b 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java @@ -79,6 +79,19 @@ public final class Namer { private static final String PROTOTYPE_NAME = "prototype"; public static final String CAPTURED_VAR_FIELD = "v"; + @NotNull + public static final JsExpression UNDEFINED_EXPRESSION = new JsPrefixOperation(JsUnaryOperator.VOID, JsNumberLiteral.ZERO); + + public static boolean isUndefined(@NotNull JsExpression expr) { + if (expr instanceof JsPrefixOperation) { + JsUnaryOperator op = ((JsPrefixOperation) expr).getOperator(); + + return op == JsUnaryOperator.VOID; + } + + return false; + } + @NotNull public static String getReceiverParameterName() { return RECEIVER_PARAMETER_NAME; @@ -212,8 +225,6 @@ public final class Namer { @NotNull private final JsName callableRefForExtensionProperty; @NotNull - private final JsExpression undefinedExpression; - @NotNull private final JsExpression callGetProperty; @NotNull private final JsExpression callSetProperty; @@ -243,8 +254,6 @@ public final class Namer { callableRefForExtensionProperty = kotlinScope.declareName(CALLABLE_REF_FOR_EXTENSION_PROPERTY); isTypeName = kotlinScope.declareName("isType"); - - undefinedExpression = new JsPrefixOperation(JsUnaryOperator.VOID, rootScope.getProgram().getNumberLiteral(0)); } @NotNull @@ -365,7 +374,7 @@ public final class Namer { @NotNull public JsExpression getUndefinedExpression() { - return undefinedExpression; + return UNDEFINED_EXPRESSION; } @NotNull