Skip to content

Commit

Permalink
various improvements preparing v2
Browse files Browse the repository at this point in the history
- support for decorators (fixed #43)
- added support for core JS features (function-scope this ($this),
function-scope arguments, ...
- added/modified macros ($insert, $loose/$strict, ...)
- modified es5 and es6 API to simplify the use of JavaScript strings and
arrays
  • Loading branch information
renaudpawlak committed May 3, 2017
1 parent 0904e0a commit 11c8062
Show file tree
Hide file tree
Showing 110 changed files with 8,340 additions and 10,910 deletions.
892 changes: 652 additions & 240 deletions core-lib/es5/src/main/java/def/js/Array.java

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions core-lib/es5/src/main/java/def/js/Date.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package def.js;
/** Enables basic storage and retrieval of dates and times. */
public class Date extends def.js.Object {
/** Returns a string representation of a date. The format of the string depends on the locale. */
native public java.lang.String toString();
/** Returns a date as a string value. */
native public java.lang.String toDateString();
native public String toDateString();
/** Returns a time as a string value. */
native public java.lang.String toTimeString();
native public String toTimeString();
/** Returns a value as a string value appropriate to the host environment's current locale. */
native public java.lang.String toLocaleString();
native public String toLocaleString();
/** Returns a date as a string value appropriate to the host environment's current locale. */
native public java.lang.String toLocaleDateString();
native public String toLocaleDateString();
/** Returns a time as a string value appropriate to the host environment's current locale. */
native public java.lang.String toLocaleTimeString();
native public String toLocaleTimeString();
/** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */
native public Number valueOf();
/** Gets the time value in milliseconds. */
Expand Down Expand Up @@ -145,22 +143,28 @@ public class Date extends def.js.Object {
*/
native public double setUTCFullYear(double year, double month, double date);
/** Returns a date converted to a string using Universal Coordinated Time (UTC). */
native public java.lang.String toUTCString();
native public String toUTCString();
/** Returns a date as a string value in ISO format. */
native public java.lang.String toISOString();
native public String toISOString();
/** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */
native public java.lang.String toJSON(java.lang.Object key);
native public String toJSON(java.lang.Object key);
public Date(){}
public Date(double value){}
public Date(java.lang.String value){}
public Date(String value){}
public Date(double year, double month, double date, double hours, double minutes, double seconds, double ms){}
native public static java.lang.String applyStatic();
native public static String $applyStatic();
public static final Date prototype=null;
/**
* Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.
* @param s A date string
*/
native public static double parse(java.lang.String s);
/**
* Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.
* @param s A date string
*/
native public static double parse(String s);
/**
* Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
Expand Down
2 changes: 1 addition & 1 deletion core-lib/es5/src/main/java/def/js/Float32Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class Float32Array extends def.js.Object implements Iterable<java.lang.Do
/**
* Converts a number to a string by using the current locale.
*/
native public java.lang.String toLocaleString();
native public String toLocaleString();
/**
* Returns a string representation of an array.
*/
Expand Down
2 changes: 1 addition & 1 deletion core-lib/es5/src/main/java/def/js/Float64Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class Float64Array extends def.js.Object implements Iterable<java.lang.Do
/**
* Converts a number to a string by using the current locale.
*/
native public java.lang.String toLocaleString();
native public String toLocaleString();
/**
* Returns a string representation of an array.
*/
Expand Down
241 changes: 180 additions & 61 deletions core-lib/es5/src/main/java/def/js/Globals.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,183 @@
package def.js;
/** This class holds all the global functions and variables of the jsweet.lang package. */

/**
* This class holds all the global functions and variables of the jsweet.lang
* package.
*/
public final class Globals extends def.js.Object {
private Globals(){}
public static final double NaN=0;
public static final double Infinity=0;
/**
* Evaluates JavaScript code and executes it.
* @param x A String value that contains valid JavaScript code.
*/
native public static java.lang.Object eval(java.lang.String x);
/**
* Converts A string to an integer.
* @param s A string to convert into a number.
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
* All other strings are considered decimal.
*/
native public static double parseInt(java.lang.String s, double radix);
/**
* Converts a string to a floating-point number.
* @param string A string that contains a floating-point number.
*/
native public static double parseFloat(java.lang.String string);
/**
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
* @param number A numeric value.
*/
native public static java.lang.Boolean isNaN(double number);
/**
* Determines whether a supplied number is finite.
* @param number Any numeric value.
*/
native public static java.lang.Boolean isFinite(double number);
/**
* Gets the unencoded version of an encoded Uniform Resource Identifier (URI).
* @param encodedURI A value representing an encoded URI.
*/
native public static java.lang.String decodeURI(java.lang.String encodedURI);
/**
* Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).
* @param encodedURIComponent A value representing an encoded URI component.
*/
native public static java.lang.String decodeURIComponent(java.lang.String encodedURIComponent);
/**
* Encodes a text string as a valid Uniform Resource Identifier (URI)
* @param uri A value representing an encoded URI.
*/
native public static java.lang.String encodeURI(java.lang.String uri);
/**
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
native public static java.lang.String encodeURIComponent(java.lang.String uriComponent);
/**
* Converts A string to an integer.
* @param s A string to convert into a number.
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
* All other strings are considered decimal.
*/
native public static double parseInt(java.lang.String s);
}
private Globals() {
}

/**
* The constant representing a number that is "Not A Number".
*/
public static final double NaN = 0;

/**
* The constant representing an infinite number.
*/
public static final double Infinity = 0;

/**
* The JavaScript <code>undefined</code> global property.
*/
public static final Object undefined = null;

/**
* Accesses the current method arguments (<code>arguments</code> implicit
* variable in JavaScript). This variable is only available within
* functions.
*/
public static final def.js.Object[] arguments = null;

/**
* Evaluates JavaScript code and executes it.
*
* @param x
* A String value that contains valid JavaScript code.
*/
native public static java.lang.Object eval(java.lang.String x);

/**
* Evaluates JavaScript code and executes it.
*
* @param x
* A String value that contains valid JavaScript code.
*/
native public static java.lang.Object eval(String x);

/**
* Converts A string to an integer.
*
* @param s
* A string to convert into a number.
* @param radix
* A value between 2 and 36 that specifies the base of the number
* in numString. If this argument is not supplied, strings with a
* prefix of '0x' are considered hexadecimal. All other strings
* are considered decimal.
*/
native public static double parseInt(java.lang.String s, double radix);

/**
* Converts a string to a floating-point number.
*
* @param string
* A string that contains a floating-point number.
*/
native public static double parseFloat(java.lang.String string);

/**
* Returns a Boolean value that indicates whether a value is the reserved
* value NaN (not a number).
*
* @param number
* A numeric value.
*/
native public static java.lang.Boolean isNaN(double number);

/**
* Determines whether a supplied number is finite.
*
* @param number
* Any numeric value.
*/
native public static java.lang.Boolean isFinite(double number);

/**
* Gets the unencoded version of an encoded Uniform Resource Identifier
* (URI).
*
* @param encodedURI
* A value representing an encoded URI.
*/
native public static java.lang.String decodeURI(java.lang.String encodedURI);

/**
* Gets the unencoded version of an encoded Uniform Resource Identifier
* (URI).
*
* @param encodedURI
* A value representing an encoded URI.
*/
native public static String decodeURI(String encodedURI);

/**
* Gets the unencoded version of an encoded component of a Uniform Resource
* Identifier (URI).
*
* @param encodedURIComponent
* A value representing an encoded URI component.
*/
native public static java.lang.String decodeURIComponent(java.lang.String encodedURIComponent);

/**
* Gets the unencoded version of an encoded component of a Uniform Resource
* Identifier (URI).
*
* @param encodedURIComponent
* A value representing an encoded URI component.
*/
native public static String decodeURIComponent(String encodedURIComponent);

/**
* Encodes a text string as a valid Uniform Resource Identifier (URI)
*
* @param uri
* A value representing an encoded URI.
*/
native public static java.lang.String encodeURI(java.lang.String uri);

/**
* Encodes a text string as a valid Uniform Resource Identifier (URI)
*
* @param uri
* A value representing an encoded URI.
*/
native public static String encodeURI(String uri);

/**
* Encodes a text string as a valid component of a Uniform Resource
* Identifier (URI).
*
* @param uriComponent
* A value representing an encoded URI component.
*/
native public static java.lang.String encodeURIComponent(java.lang.String uriComponent);

/**
* Encodes a text string as a valid component of a Uniform Resource
* Identifier (URI).
*
* @param uriComponent
* A value representing an encoded URI component.
*/
native public static String encodeURIComponent(String uriComponent);

/**
* Converts A string to an integer.
*
* @param s
* A string to convert into a number.
* @param radix
* A value between 2 and 36 that specifies the base of the number
* in numString. If this argument is not supplied, strings with a
* prefix of '0x' are considered hexadecimal. All other strings
* are considered decimal.
*/
native public static int parseInt(java.lang.String s);

/**
* Converts A string to an integer.
*
* @param s
* A string to convert into a number.
* @param radix
* A value between 2 and 36 that specifies the base of the number
* in numString. If this argument is not supplied, strings with a
* prefix of '0x' are considered hexadecimal. All other strings
* are considered decimal.
*/
native public static int parseInt(String s);

}
2 changes: 1 addition & 1 deletion core-lib/es5/src/main/java/def/js/Int16Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class Int16Array extends def.js.Object implements Iterable<java.lang.Doub
/**
* Converts a number to a string by using the current locale.
*/
native public java.lang.String toLocaleString();
native public String toLocaleString();
/**
* Returns a string representation of an array.
*/
Expand Down
2 changes: 1 addition & 1 deletion core-lib/es5/src/main/java/def/js/Int32Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class Int32Array extends def.js.Object implements Iterable<java.lang.Doub
/**
* Converts a number to a string by using the current locale.
*/
native public java.lang.String toLocaleString();
native public String toLocaleString();
/**
* Returns a string representation of an array.
*/
Expand Down
2 changes: 1 addition & 1 deletion core-lib/es5/src/main/java/def/js/Int8Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class Int8Array extends def.js.Object implements Iterable<java.lang.Doubl
/**
* Converts a number to a string by using the current locale.
*/
native public java.lang.String toLocaleString();
native public String toLocaleString();
/**
* Returns a string representation of an array.
*/
Expand Down
Loading

0 comments on commit 11c8062

Please sign in to comment.