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

Way to inject target code to the output for monkey-patching #154

Open
gfx opened this issue May 5, 2013 · 4 comments
Open

Way to inject target code to the output for monkey-patching #154

gfx opened this issue May 5, 2013 · 4 comments

Comments

@gfx
Copy link
Member

gfx commented May 5, 2013

To deal with IE10's patch:

https://gist.github.com/7shi/5487552

See also #152

@kazuho
Copy link
Member

kazuho commented May 6, 2013

I see several problems here.

if (!window.HTMLDocument) window.HTMLDocument = Document;

could be solved by changing the definition of HTMLDocument (in JSX) to

native("HTMLDocument || Document") final class HTMLDocument

OTOH,

xhr = window.ActiveXObject ? new ActiveXObject("Msxml2.XMLHTTP") : new XMLHttpRequest();

cannot be solved as native("window.ActiveXObject || XMLHttpRequest") since IIRC Internet Explorer does not support holding references to ActiveXObjects and then applying new operator against them (please correct me if I am wrong). And IIRC @gfx was talking about Google Chrome sending objects of wrong type of objects as arguments of callbacks?

To tackle these cases, we would need a syntax to override ordinary operations in JSX, like the following (and hereby I bring back my proposal to introduce = "..." notation against native definitions (#155 (comment)); sorry for the fact that this is after #152 has been merged).

final native class XMLHttpRequest {
    function constructor() = "(window.ActiveXObject ? new ActiveXObject("Hsxml2.XMLHTTP") : new XMLHttpRequest)";
    static function __native_instanceof__(v : variant) : boolean = "...";
}

@gfx
Copy link
Member Author

gfx commented May 7, 2013

Are there other situations which that spec will solve? If it solves only XHR incompatibility, it shouldn't be in the JSX language.

For XHR, native fake class also can solve the issue:

import "js/web.jsx";

native __fake__ class XHR {
  function open(method : string, url : string) : void;
}

native class ActiveXObject {
  function constructor(feature : string);
}

class _Main {
  static function main(args : string[]) : void {
    var xhr = dom.window["XMLHttpRequest"]
      ? new XMLHttpRequest() as __noconvert__ XHR
      : new ActiveXObject("Msxml2.XMLHTTP") as __noconvert__ XHR;
    log "Hello, world!";

    xhr.open("GET", "http://example.com");
    // ...
  }
}

It's a dirty hack but works well.

@kazuho
Copy link
Member

kazuho commented May 7, 2013

@gfx

And IIRC @gfx was talking about Google Chrome sending objects of wrong type of objects as arguments of callbacks?

What about this?

@kazuho
Copy link
Member

kazuho commented May 9, 2013

A real-world requirement for the issue has been pointed out by @shibukawa (https://twitter.com/shibukawa/status/332400006164250624). According to the tweet and the blog entry, the JavaScript binding of Qt uses it's own mangling scheme, and it is desirable if the per-method native attribute of JSX could be used to specify each of the underlying property names.

comboBox["currentIndexChanged(int)"].connect(handler); 
comboBox['currentIndexChanged(QString)'].connect(handler);  

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

2 participants