Skip to content
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

Mirrors and runtime information for current function #11916

Closed
DartBot opened this issue Jul 19, 2013 · 11 comments
Closed

Mirrors and runtime information for current function #11916

DartBot opened this issue Jul 19, 2013 · 11 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue library-mirrors type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jul 19, 2013

This issue was originally filed by off...@mikemitterer.at


What steps will reproduce the problem?
class RestSimulator {

@path("/var")
void functionOne() {
  final Type type = this.runtimeType;
  final InstanceMirror instanceMirror = reflect(this);
  final ClassMirror classMirror = instanceMirror.type;

  final MethodMirror methodMirror = ?????
  var metadata = methodMirror.metadata;
  var path = metadata.first.reflectee;

  print(path.toString()):
  }
}

What is the expected output? What do you see instead?
I want a MethodMirror for "functionOne" but without doing something like:
final MethodMirror methodMirror = xxx.functions[const Symbol('functionOne')];

The MethodName (Symbol) of the current function should be available at runtime.

What version of the product are you using? On what operating system?
Dart Editor version 0.6.5_r25017
Dart SDK version 0.6.5.0_r25017

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Jul 19, 2013

This comment was originally written by off...@mikemitterer.at


If someone is able to correct the typo in the headline... pls change it.

@DartBot
Copy link
Author

DartBot commented Jul 19, 2013

This comment was originally written by @mezoni


This is a compile-time constant but not the runtime.
Currently Dart language does not support the compile-time constants.
You cannot get function name without having reference to it.
Also in Dart not possible get these common compile-time constant:

  • Class name
  • File name
  • Line number

@iposva-google
Copy link
Contributor

I am assuming this is in the context of dart2js, correct?


Added Area-Dart2JS, Library-Mirrors, Triaged labels.

@peter-ahe-google
Copy link
Contributor

Changed the title to: "Mirrors and runtime information for current function".

@peter-ahe-google
Copy link
Contributor

Mike, it sounds to me that you're looking for a new method in the mirror API that could look something like this:

/**
  * Returns a [MethodMirror] corresponding to the closure [function].
  *
  * If [function] is the implicit closure of a top-level, static,
  * or instance method, this method returns a MethodMirror on that method.
  *
  * Otherwise, this method throws [ArgumentError].
  */
MethodMirror reflectFunction(Function function);

Am I understanding you correctly?


cc @gbracha.
Removed Area-Dart2JS label.
Added Area-Library label.

@DartBot
Copy link
Author

DartBot commented Jul 20, 2013

This comment was originally written by @a14n


His original question on stackoverflow : http://stackoverflow.com/questions/17741543/how-do-i-get-a-methodmirror-for-the-current-function

I think he is looking for an equivalent of the JS "arguments.callee" returning a MethodMirror.

@DartBot
Copy link
Author

DartBot commented Jul 22, 2013

This comment was originally written by off...@mikemitterer.at


Yeah #­6 is almost right. The difference to callee is that it gives you a reference to the calling function - I just need it's name. If I have the name - sure, then #­5 would be necessary.
I want to be able to get access to @­Path in the function where it is notated and for this I need to know what the name of the calling function is (programmatically) .

BTW: #­2 File name, Line number usw. would also be very helpful

@peter-ahe-google
Copy link
Contributor

I doubt we will expose access to anything like JavaScript's arguments.callee in Dart.

@DartBot
Copy link
Author

DartBot commented Jul 22, 2013

This comment was originally written by @mezoni


I doubt we will expose access to anything like JavaScript's arguments.callee in Dart.

Something similar.

void foo(int a, int b) {
  Function callee = Function.callee();
  var args = Function.arguments();
  print(Function.getName(callee));
  print(args['a']);
}

abstract class Function {
  external static Map<Symbol, dynamic> arguments();

  external static Function callee();

  external static Symbol getName(Function function);

  external static apply(Function function, List positionalArguments,
    [Map<Symbol, dynamic> namedArguments]);
}

Or maybe another class for this purpose.

@gbracha
Copy link
Contributor

gbracha commented Jul 22, 2013

FWIW

MethodMirror methodMirror = reflect(functionOne).function;

should work, because reflecting a function gives you a ClosureMirror, which is a specialization of InstanceMirror that supports the function accessor. We are shaking out the bugs in this area, so it might not work in JS yet, or even in every case on the VM (but it does for a top level function).

So I don't think reflectFunction is necessary.


Removed Type-Defect label.
Added Type-Enhancement, Accepted labels.

@gbracha
Copy link
Contributor

gbracha commented Aug 24, 2013

This now works as advertised in the VM. So I'm closing the bug.


Set owner to @gbracha.
Added WontFix label.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors labels Aug 24, 2013
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue library-mirrors type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants