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

InvocationMirror.invokeOn does not work for getters and setters on dart2js. #6907

Closed
mraleph opened this issue Nov 24, 2012 · 6 comments
Closed
Assignees
Milestone

Comments

@mraleph
Copy link
Member

mraleph commented Nov 24, 2012

It works fine with normal methods but not with getters and setters:

class A {
  set x(val) {
    print("A.x <- $val");
  }
  
  get x {
    print("<- A.x");
  }
}

class B {
  final a = new A();
  noSuchMethod(mirror) => mirror.invokeOn(a);
}

main () {
  var b = new B();
  print('before set x');
  b.x = 10;
  print('before get x');
  b.x;
}

explodes.

@peter-ahe-google
Copy link
Contributor

Added Duplicate label.
Marked as being merged into #6490.

@peter-ahe-google
Copy link
Contributor

Added Triaged label.
Marked as being merged into #.

@peter-ahe-google
Copy link
Contributor

Hi Johnni, could you investigate this?


Set owner to @johnniwinther.
Added this to the M2 milestone.

@DartBot
Copy link

DartBot commented Dec 6, 2012

This comment was originally written by @aam


Quick observation:

invokeOn() in js_helper.dart:404 uses internalName to find methods.

For regular methods internalName(second argument to createInvocationMirror below) matches function name "test$0":
===
 test$0: function() {
  return this.noSuchMethod$1($.createInvocationMirror("test", "test$0", 0, [], []));
 },
===

For getter/setters it doesn't:
===
 get$x: function() {
  return this.noSuchMethod$1($.createInvocationMirror("x", "x$0", 1, [], []));
 },
 set$x: function($0) {
  return this.noSuchMethod$1($.createInvocationMirror("x=", "x=$1", 2, [$0], []));
 },
===
"get$x" and "set$x" are actual function names, but internalName are passed as "x$0" and "x=$1".

This mismatch leads to the following error as object[this._internalName] returns undefined:
===
E:\g4\dart-repo\dart>build\ReleaseIA32\d8 out.js
before set x
out.js:184: TypeError: Cannot call method 'apply' of undefined
  return object[this._internalName].apply(object, arguments$);
                                    ^
TypeError: Cannot call method 'apply' of undefined
    at JSInvocationMirror.$$.JSInvocationMirror.invokeOn$1 (out.js:184:37)
    at B.$$.B.noSuchMethod$1 (out.js:1282:17)
    at B.$$.Object.get$x (out.js:791:15)
    at $.main (out.js:1959:5)
    at out.js:2141:7
===

@peter-ahe-google
Copy link
Contributor

@johnniwinther
Copy link
Member

Fixed by https://codereview.chromium.org/11447008/


Added Fixed 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