0.10.0 #915
konsoletyper
announced in
Announcements
0.10.0
#915
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Improvements to native JavaScript interaction
Exporting declarations from Java to JavaScript
This long expected feature is finally delivered by this release. Now TeaVM can not only take standard Java main classes with main methods, but also module classes. Instead of
main
method, they can declarestatic
methods annotated with@JSExport
.These methods will be exported from generated TeaVM module (or rather as top-level declarations in non-module output).
Additionally,
@JSExport
annotation can be used to mark methods of classes that should be available in JS. See full documentation in Creating JavaScript modules section.Generating modules
From this release, TeaVM can produce ES2015 modules. Moreover, there's a new build parameter that allows to specify module type (CommonJS, ES2015, UMD, immediately-invoked function).
Importing constructors
Previously, to declare a constructor for a JS class, you had to define static factory method, annotated with
@JSBody
and some JS within. Now, it's possible to declare a non-abstract overlay class (should be additionally annotated with@JSClass
) with constructors. To instantiate such classes, you can usenew
syntax, as you used for normal Java classes.Importing static and top-level methods
Since this release, you can define
static native
methods of overlay classes without extra annotations. These methods will be automatically mapped to corresponding static JS methods.You can also put
@JSTopLevel
annotation on such methods so that they aren't mapped to static methods of containing classes, but to top-level methods.Support
instanceof
Overlay classes now properly support
instanceof
and casts (in strict mode). Note thatinstanceof
is not available for interfaces (i.e. as previously, always producestrue
). Support ofinstanceof
can be disabled for classes by applying@JSClass(transparent = true)
.Importing declarations from external modules
You can also use
@JSModule
annotation to import declarations from JS modules. Following cases possible:@JSModule
on class – imports class@JSModule
and@JSTopLevel
– imports function@JSModule
,@JSTopLevel
and@JSProperty
– imports propertySupport varargs
Varargs methods of overlay classes now automatically mapped to varargs methods in JS.
Improved string representation
This release has changed the way
java.lang.String
represented internally. Instead of array ofchar
,java.lang.String
now contains field of native JS string. This can improve performance in some cases, most likely in calls to native JS methods. Previously, to convertjava.lang.String
to and from JS method, a full copy should have been made. Now, TeaVM only wraps/unwraps JS string withjava.lang.String
implementation, which is much faster.This also improves debugging experience. Previously, if you open a
java.lang.String
value in browser dev tools, you had a object, which has a field, which is an object in turn, which wrapsUInt16Array
. Now, you only have to deal with one level of indirection (object that has a field), and an actual representation is not array of char codes, but JS string, easily readable in dev tools.ES2015 modules
Since this release, TeaVM generates ES2015 output, not ES5. This allows not only to support ES2015 modules, but reduces output side thanks to arrow function syntax.
Class library emulation
String.toLowerCase
/toUpperCase
methods that takeLocale
parameterchars
andcodePoints
methods inCharSequence
String.format
/Formatter.format
now support more format specifiersMath
methods for arithmetic operations that throw exception on overflowOutputStream.nullOutputStream
SecureRandom
BigInteger.sqrt
WeakHashMap
CopyOnWriteArrayList
ThreadLocal
in green threads@Inherited
annotationsPrintStream
implementsAppendable
BufferedReader.lines
methodGradle plugin improvements
Other stuff
Promise
(JSPromise
class)@Inherited
annotationsRegistration
to unbind the listener, instead of listenEventName/neglectEventName).Sponsorship
Worth mentioning that TeaVM evolved with the support from its sponsors. If you like this project, you can start donating.
Special thanks to @reportmill and @shannah, our permanent sponsors!
Contributors
This discussion was created from the release 0.10.0.
Beta Was this translation helpful? Give feedback.
All reactions