Skip to content

Commit

Permalink
Enhancement to add ECMAScript 6 support (#1574) (#1682)
Browse files Browse the repository at this point in the history
* Enhancement to add ECMAScript 6 support (#1574)
  • Loading branch information
speckyspooky committed May 13, 2024
1 parent 840f82a commit 1e09901
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bundle-Version: 4.16.0.qualifier
Bundle-Activator: org.eclipse.birt.report.designer.ui.ReportPlugin
Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Import-Package: org.eclipse.birt.report.engine.javascript
Export-Package: org.eclipse.birt.report.designer.data.ui.aggregation,
org.eclipse.birt.report.designer.data.ui.dataset,
org.eclipse.birt.report.designer.data.ui.property,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Iterator;

import org.eclipse.birt.report.designer.ui.IReportGraphicConstants;
import org.eclipse.birt.report.engine.javascript.JavascriptVersion;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.TextSelection;
Expand Down Expand Up @@ -128,7 +129,7 @@ private void clearAnnotations() {
IAnnotationModel annotationModel = scriptViewer.getAnnotationModel();

if (annotationModel != null) {
for (Iterator iterator = annotationModel.getAnnotationIterator(); iterator.hasNext();) {
for (Iterator<?> iterator = annotationModel.getAnnotationIterator(); iterator.hasNext();) {
Annotation annotation = (Annotation) iterator.next();

if (annotation != null && IReportGraphicConstants.ANNOTATION_ERROR.equals(annotation.getType())) {
Expand All @@ -150,6 +151,7 @@ protected void validateScript(String script) throws ParseException {
}

CompilerEnvirons compilerEnv = new CompilerEnvirons();
compilerEnv.setLanguageVersion((new JavascriptVersion()).getECMAScriptVersion());
Parser jsParser = new Parser(compilerEnv, compilerEnv.getErrorReporter());

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class JavascriptEngine implements IScriptEngine, IDataScriptEngine {

protected ScriptableObject root;

protected JavascriptVersion version;

private Map<String, Object> propertyMap = new HashMap<>();

private JavascriptEngineFactory factory;
Expand All @@ -76,16 +78,25 @@ public class JavascriptEngine implements IScriptEngine, IDataScriptEngine {
Context context = Context.enter();
cachedScript = context.compileString("function writeStatus(msg) { _statusHandle.showStatus(msg); }",
"<inline>", 1, null);
context.exit();
Context.exit();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Constructor
*
* @param factory factory object for the JavaScript engine
* @param root scriptable object
* @throws BirtException
*/
public JavascriptEngine(JavascriptEngineFactory factory, ScriptableObject root) throws BirtException {
this.factory = factory;
try {
this.context = Context.enter();
this.version = new JavascriptVersion();
this.context.setLanguageVersion(this.version.getECMAScriptVersion());
this.global = new ImporterTopLevel();
this.root = root;
if (root != null) {
Expand Down Expand Up @@ -129,7 +140,7 @@ private void initWrapFactory() {
* wrapper an java object to javascript object.
*/
@Override
public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
public Object wrap(Context cx, Scriptable scope, Object obj, Class<?> staticType) {
Object object = coreWrapper.wrap(cx, scope, obj, staticType);
if (object != obj) {
return object;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package org.eclipse.birt.report.engine.javascript;

/**
* Copyright (c) 2024 Thomas Gutmann.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Handling of the JavaScript version evaluation
*
* Contributors: Thomas Gutmann - initial implementation
*
* @since 4.16
*
*/
public class JavascriptVersion {

/**
* Constructor
*/
public JavascriptVersion() {
evaluateEcmaScriptVersion();
}

/** Valid JavaScript versions */
/** JavaScript 1.0 */
private static final int ECMA_SCRIPT_VERSION_1_0 = 100;
/** JavaScript 1.1 */
private static final int ECMA_SCRIPT_VERSION_1_1 = 110;
/** JavaScript 1.2 */
private static final int ECMA_SCRIPT_VERSION_1_2 = 120;
/** JavaScript 1.3 */
private static final int ECMA_SCRIPT_VERSION_1_3 = 130;
/** JavaScript 1.4 */
private static final int ECMA_SCRIPT_VERSION_1_4 = 140;
/** JavaScript 1.5 */
private static final int ECMA_SCRIPT_VERSION_1_5 = 150;
/** JavaScript 1.6 */
private static final int ECMA_SCRIPT_VERSION_1_6 = 160;
/** JavaScript 1.7 */
private static final int ECMA_SCRIPT_VERSION_1_7 = 170;
/** JavaScript 1.8 */
private static final int ECMA_SCRIPT_VERSION_1_8 = 180;
/** JavaScript 1.8 */
private static final int ECMA_SCRIPT_VERSION_ES6 = 200;

/** System property of the JavaScript version */
private static final String ECMA_SCRIPT_VERSION_PROPERTY_KEY = "birt.ecmascript.version"; //$NON-NLS-1$

/** Valid keys of the system property */
private static final String ECMA_SCRIPT_VERSION_1_0_KEY = "1.0"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_1_KEY = "1.1"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_2_KEY = "1.2"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_3_KEY = "1.3"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_4_KEY = "1.4"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_5_KEY = "1.5"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_6_KEY = "1.6"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_7_KEY = "1.7"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_1_8_KEY = "1.8"; //$NON-NLS-1$
private static final String ECMA_SCRIPT_VERSION_ES6_KEY = "ES6"; //$NON-NLS-1$

private int valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_ES6;

private String configuredECMAScriptVersion;

/**
* Get the EMCAScript version number
*
* @return the ECMAScript version number
*/
public int getECMAScriptVersion() {
return this.valueEcmaScriptVersion;
}

/**
* Get the configured EMCAScript version of JVM
*
* @return the ECMAScript version configured at JVM
*/
public String getConfiguredECMAScriptVersion() {
return this.configuredECMAScriptVersion;
}

/**
* Evaluate the system property to set the version number of the Rhino engine
*/
private void evaluateEcmaScriptVersion() {

/* System property: -Dbirt.ecmascript.version */
configuredECMAScriptVersion = System.getProperty(ECMA_SCRIPT_VERSION_PROPERTY_KEY);
if (configuredECMAScriptVersion != null) {
switch (configuredECMAScriptVersion) {
case ECMA_SCRIPT_VERSION_1_0_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_0;
break;
case ECMA_SCRIPT_VERSION_1_1_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_1;
break;
case ECMA_SCRIPT_VERSION_1_2_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_2;
break;
case ECMA_SCRIPT_VERSION_1_3_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_3;
break;
case ECMA_SCRIPT_VERSION_1_4_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_4;
break;
case ECMA_SCRIPT_VERSION_1_5_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_5;
break;
case ECMA_SCRIPT_VERSION_1_6_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_6;
break;
case ECMA_SCRIPT_VERSION_1_7_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_7;
break;
case ECMA_SCRIPT_VERSION_1_8_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_1_8;
break;
case ECMA_SCRIPT_VERSION_ES6_KEY:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_ES6;
break;
default:
this.valueEcmaScriptVersion = ECMA_SCRIPT_VERSION_ES6;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Eclipse BIRT
Introduction to use the configuration of the JavaScript language version.

## Reason
The JavaScript engine of BIRT is based on the Rhino engine. The default language version of the Rhino engine is JavaScript version 1.6. Rhino supports different language versions of JavaScript including the latest version ECMAScript 6.

On **BIRT** side the Rhino engine will be run with the latest version **ECMAScript 6**.
To be compatible with earlier JavaScript versions a global system property is given which can be set at JVM level to change the JavaScript language version.

All supported JavaScript language versions of the Rhino engine can be configured.

### JVM configuration of the JavaScript language version

The configuration will be done as a global starting parameter of the JVM.

**birt.ecmascript.version**

Content configuration of the JavaScript language version
Parameter -Dbirt.ecmascript.version
Location JVM
Data type string
Values value of the supported language version
Supported 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, ES6
Default ES6 (= EMCAScript 6)
Version 4.16

** Function reference of Rhino**

- An overview of Rhino engine supported functions are listed here: [Rhino ES2015 Support](https://mozilla.github.io/rhino/compat/engines.html)


- The Rhino engine will be integrated at BIRT through the Orbit-project: [Orbit Aggregation Summary](https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/table.html)
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ interface IDesignSchemaConstants {
/**
* The version of report design.
*/

String REPORT_VERSION = "3.2.24"; //$NON-NLS-1$
String REPORT_VERSION = "3.2.25"; //$NON-NLS-1$

/**
* The number representation for the current version string.
*/

int REPORT_VERSION_NUMBER = VersionUtil.VERSION_3_2_24;
int REPORT_VERSION_NUMBER = VersionUtil.VERSION_3_2_25;

String ACCESS_CONTROL_TAG = "access-control"; //$NON-NLS-1$
String AUTO_TEXT_TAG = "auto-text"; //$NON-NLS-1$
Expand Down Expand Up @@ -240,7 +238,6 @@ interface IDesignSchemaConstants {
/**
* @deprecated by the {@link #TEXT_DATA_TAG}
*/

@Deprecated
String MULTI_LINE_DATA_TAG = "multi-line-data"; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,93 @@ public class VersionUtil {

private static final int[] expoArray = { 1000000, 10000, 100, 1 };

/** property: report design file version 0 */
public final static int VERSION_0 = 0;

/** property: report design file version 1.0.0 */
public final static int VERSION_1_0_0 = 1000000;

/** property: report design file version 3.0.0 */
public final static int VERSION_3_0_0 = 3000000;

/** property: report design file version 3.1.0 */
public final static int VERSION_3_1_0 = 3010000;

/** property: report design file version 3.2.0 */
public final static int VERSION_3_2_0 = 3020000;

/** property: report design file version 3.2.1 */
public final static int VERSION_3_2_1 = 3020100;

/** property: report design file version 3.2.2 */
public final static int VERSION_3_2_2 = 3020200;

/** property: report design file version 3.2.3 */
public final static int VERSION_3_2_3 = 3020300;

/** property: report design file version 3.2.4 */
public final static int VERSION_3_2_4 = 3020400;

/** property: report design file version 3.2.6 */
public final static int VERSION_3_2_6 = 3020600;

/** property: report design file version 3.2.7 */
public final static int VERSION_3_2_7 = 3020700;

/** property: report design file version 3.2.8 */
public final static int VERSION_3_2_8 = 3020800;

/** property: report design file version 3.2.9 */
public final static int VERSION_3_2_9 = 3020900;

/** property: report design file version 3.2.10 */
public final static int VERSION_3_2_10 = 3021000;

/** property: report design file version 3.2.11 */
public final static int VERSION_3_2_11 = 3021100;

/** property: report design file version 3.2.12 */
public final static int VERSION_3_2_12 = 3021200;

/** property: report design file version 3.2.13 */
public final static int VERSION_3_2_13 = 3021300;

/** property: report design file version 3.2.14 */
public final static int VERSION_3_2_14 = 3021400;

/** property: report design file version 3.2.15 */
public final static int VERSION_3_2_15 = 3021500;

/** property: report design file version 3.2.16 */
public final static int VERSION_3_2_16 = 3021600;

/** property: report design file version 3.2.17 */
public final static int VERSION_3_2_17 = 3021700;

/** property: report design file version 3.2.18 */
public final static int VERSION_3_2_18 = 3021800;

/** property: report design file version 3.2.19 */
public final static int VERSION_3_2_19 = 3021900;

/** property: report design file version 3.2.20 */
public final static int VERSION_3_2_20 = 3022000;

/** property: report design file version 3.2.21 */
public static final int VERSION_3_2_21 = 3022100;

/** property: report design file version 3.2.22 */
public static final int VERSION_3_2_22 = 3022200;

/** property: report design file version 3.2.23 */
public static final int VERSION_3_2_23 = 3022300;

/** property: report design file version 3.2.24 */
public static final int VERSION_3_2_24 = 3022400;

/** property: report design file version 3.2.25 */
public static final int VERSION_3_2_25 = 3022500;

/**
*
* @param version
Expand Down

0 comments on commit 1e09901

Please sign in to comment.