Skip to content

dart2js: create interceptors for static subclasses of Function #9586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rakudrama opened this issue Apr 2, 2013 · 9 comments
Closed

dart2js: create interceptors for static subclasses of Function #9586

rakudrama opened this issue Apr 2, 2013 · 9 comments

Comments

@rakudrama
Copy link
Member

Static functions get methods from the JSFunction interceptor.
Some methods ($asFoo) are different depending on the type of the static function.

For each subtype of Function implemented by a static function, introduce a new interceptor subclass of JSFunction.
Instead of decorating each static function with type information, decorate it with the created interceptor for the subtype it implements.

getInterceptor should be changed to use the decorating interceptor if present, otherwise use the JSFunction interceptor.

$.typeNameInFirefox.call$1 = $.typeNameInFirefox;
$.typeNameInFirefox.$name = "typeNameInFirefox";
$.typeNameInFirefox.$isAnimationCallback = true;
$.typeNameInFirefox.$isChangeListener = true;
$.typeNameInFirefox.$isSelectHandler = true;
$.typeNameInFirefox.$is_FutureOnError = true;
$.typeNameInFirefox.$is_ErrorHandler = true;
$.typeNameInFirefox.$isEventListener = true;
$.typeNameInIE.call$1 = $.typeNameInIE;
$.typeNameInIE.$name = "typeNameInIE";
$.typeNameInIE.$isAnimationCallback = true;
$.typeNameInIE.$isChangeListener = true;
$.typeNameInIE.$isSelectHandler = true;
$.typeNameInIE.$is_FutureOnError = true;
$.typeNameInIE.$is_ErrorHandler = true;
$.typeNameInIE.$isEventListener = true;

-->
$$.JSFunction123 = {"": "JSfunction",
  $isAnimationCallback: true,
  $isChangeListener: true,
  $isSelectHandler: true,
  $is_FutureOnError: true,
  $is_ErrorHandler: true,
  $isEventListener: true
};

$.typeNameInFirefox.call$1 = $.typeNameInFirefox;
$.typeNameInFirefox.$name = "typeNameInFirefox";
$.typeNameInFirefox.$interceptor = $.JSFunction123.prototype;
$.typeNameInIE.call$1 = $.typeNameInIE;
$.typeNameInIE.$name = "typeNameInIE";
$.typeNameInIE.$interceptor = $.JSFunction123.prototype;

@rakudrama
Copy link
Member Author

Note that with this change, the generated code in getInterceptor will be modified from

  if (typeof receiver == "function")
    return $.JSFunction_methods;

to

  if (typeof receiver == "function")
    return receiver.$interceptor || $.JSFunction_methids;


cc @karlklose.

@rakudrama
Copy link
Member Author

Marked this as blocking #9726.

@karlklose
Copy link
Contributor

cc @johnniwinther.

@DartBot
Copy link

DartBot commented Apr 10, 2013

This comment was originally written by [email protected]


Static functions are starting to get more and more complicated. Please also consider using our general closure mechanism (i.e. creating a Dart class).

@rakudrama
Copy link
Member Author

Regarding #­4, I don't think it is any more complicated than what we need to do to reduce the size of closures.
In a large program with --checked, many closures implement many function types.

$$.WebBackButton_afterRender_anon = {"": "Closure;",
  call$1: function(e) {
    window.history.back();
  },
  $isFunction: true,
  $isAnimationCallback: true,
  $isChangeListener: true,
  $isNumericValueSelector: true,
  $isSelectHandler: true,
  $is_FutureOnError: true,
  $is_FutureErrorTest: true,
  $is_ErrorHandler: true,
  $is_Transformation: true,
  $isEventListener: true
};
$$.WebForwardButton_afterRender_anon = {"": "Closure;",
  call$1: function(e) {
    window.history.forward();
  },
  $isFunction: true,
  $isAnimationCallback: true,
  $isChangeListener: true,
  $isNumericValueSelector: true,
  $isSelectHandler: true,
  $is_FutureOnError: true,
  $is_FutureErrorTest: true,
  $is_ErrorHandler: true,
  $is_Transformation: true,
  $isEventListener: true
};

This could be modeled by an in-line mixin application that copies type information:

$$._FunctionType123 = {"": ";",
  $isFunction: true,
  $isAnimationCallback: true,
  $isChangeListener: true,
  $isNumericValueSelector: true,
  $isSelectHandler: true,
  $is_FutureOnError: true,
  $is_FutureErrorTest: true,
  $is_ErrorHandler: true,
  $is_Transformation: true,
  $isEventListener: true
};

$$.WebBackButton_afterRender_anon = {"": "Closure+FunctionType123;",
  call$1: function(e) {
    window.history.back();
  }
};
$$.WebForwardButton_afterRender_anon = {"": "Closure+FunctionType123;",
  call$1: function(e) {
    window.history.forward();
  }
};

If we make FunctionType123 derive from the JSFunction interceptor, we can also use it on static functions:

$.myStaticFn.$interceptor = $.FunctionType123.prototype;

@kasperl
Copy link

kasperl commented Apr 22, 2013

Added this to the Later milestone.

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@DartBot
Copy link

DartBot commented May 27, 2013

This comment was originally written by [email protected]


This has been fixed in https://codereview.chromium.org/14986002/.


Added Fixed label.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed TriageForM5 label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants