开发者

understanding GWT compiler output

开发者 https://www.devze.com 2023-02-22 21:28 出处:网络
I am not JS developer but I am trying to understand the way the java code converted to JS by GWT compiler do find the cause of memory increase in our large application .

I am not JS developer but I am trying to understand the way the java code converted to JS by GWT compiler do find the cause of memory increase in our large application .

Some time i see some variable with assigened to " _ " for example

_ = com_google_gwt_event_shared_GwtEvent.prototype = new java_lang_Object;

These kind of assignm开发者_开发技巧ents are in many place in the code . What does it means ?


The GWT compiler models the Java type hierarchy using JavaScript prototype chains. The _ symbol is used as a global temporary variable by the compiler and short JSNI methods. In the top scope of the generated script, you should see something like

// Define the JS constructor(s) for the type
function com___GwtEvent() {}
// Inherit methods from the supertype by prototype chain
_ = com___GwtEvent.prototype = new java_lang_Object;
// Attach polymorphically-dispatched methods to the new type
_.someInstanceMethod = function(a,b,c){.....}
// Static-dispatch methods
function $someOtherMethod(this$static, d, e) {...}

Where you see methods that have a this$static parameter, the compiler has deduced that the Java expression instance.someOtherMethod() is not polymorphic (possibly via type-tightening) and avoids the overhead of the intermediate symbol lookup at runtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消