Skip to content

Make the tearOff return the correct function instead of a closure that returns the created object #48269

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

Open
jodinathan opened this issue Jan 31, 2022 · 0 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-enhancement A request for a change that isn't a bug web-js-interop Issues that impact all js interop

Comments

@jodinathan
Copy link

jodinathan commented Jan 31, 2022

I am playing with webcomponents in Dart.
One way to be able to use webcomponents is making the underlying js class extend the implemented HTMLElement: #48261

Another way was if the tearOff in JS was the function with the constructor calls inside of it.

Example:

class Foo implements HTMLElement {
  Foo() {
    print('Foo constructor!');
  }
}

void main () {
  print(Foo.new);
}

Today this results in this JS:

   Foo___new_tearOff() { // the tearOff here is in reality a function that creates the object
      A.print("Foo constructor!");
      return new A.Foo(); 
    },
    Foo: function Foo() { // we don't really have access to this
       // also, the constructor calls are outside this function
    }

There is a high change that WebComponents could work if the js result was something like this:

    Foo: function Foo() {
      A.print("Foo constructor!"); // remove the constructor calls from the Foo___new_tearOff and make it inside 
     // the correct constructor function
    },
   Foo___new_tearOff: A.Foo, // let the tearOff really return the function callback

Then we can use Reflect.construct(HTMLElement, [], Foo___new_tearOff) in webcomponents

@lrhn lrhn added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Feb 1, 2022
@rileyporter rileyporter added web-js-interop Issues that impact all js interop type-enhancement A request for a change that isn't a bug labels Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-enhancement A request for a change that isn't a bug web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

3 participants