-
Notifications
You must be signed in to change notification settings - Fork 68
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
Feature/es6 class constructor support #182
base: master
Are you sure you want to change the base?
Conversation
47f50d0
to
81e44b8
Compare
Tests on older versions of node are failing in some unexpected ways, I will have to debug it further. |
Wow, thanks for digging into this @OJezu. I'll try to take a look tonight. |
81e44b8
to
b365c09
Compare
The tests on older versions of node were failing because of my adjustments to isConstructor function:
I removed that check, although now I'm unable to detect es6 classes automatically. |
4d1d6a9
to
2eaa2b7
Compare
I've added detection of class functions back, this time using |
|
||
// detect broken old prototypes with missing constructor | ||
if (result.constructor !== func) { | ||
Object.defineProperty(result, 'constructor', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to modify the prototype from here, so I set the constructor property on object itself.
2eaa2b7
to
717abda
Compare
|
||
// this has to work, according to spec: | ||
// https://tc39.github.io/ecma262/#sec-function.prototype.tostring | ||
is = is || func.toString().trim().substr(0,5) === 'class'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks right. Nice find. Any idea of the performance characteristics of this? I figure it's probably fine, but just want to make sure we're not introducing a big perf hit by toString
ing every create
d function.
This looks good @OJezu. Really awesome that you created separate tests for es6, too. Just one question about performance. Is there anything else you feel needs to be done before we merge? |
I did not test the code in any browsers, it would be good if someone would check if their web app is not broken by this in major ones. Performance-wise I don't see potential slowdowns, maybe except toString on big functions. Dnia 12 kwietnia 2016 13:28:55 CEST, Brian Cavalier [email protected] napisał(a):
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
Oh, and toString is used only in modern, es6 capable browsers. Hopefully, that means optimised browsers. Dnia 12 kwietnia 2016 13:42:02 CEST, Krzysztof Chrapka [email protected] napisał(a):
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
Yeah, IE might be a concern. I'm not too worried about FF, Chrome, and Safari. I don't have direct access to IE, but we could potentially setup a simple test case, and use saucelabs or some other service to smoke test it. What do you think?
Nice. |
I have IE in an virtual machine, but I don't have an app to test it. Dnia 12 kwietnia 2016 13:54:39 CEST, Brian Cavalier [email protected] napisał(a):
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
Could you write a test similar to the other browser tests, e.g. this one and use that to verify in your VM? |
I'm under a pile of work, I should be able to do the testing at the beginning of the next week, or over the weekend. |
Now worries, @OJezu, I know the feeling! |
I'm unable to run tests in browsers. Wire seems to depend on some old version of doh for this, which is not included in npm package. If I install doh from bower, I have to update dojo too, and then everything fails on no |
717abda
to
1d7945d
Compare
I've made buster node tests runnable in browser. I had to disable some of them in browser, because gent does not work with AMD. |
8497fe8
to
62a7959
Compare
62a7959
to
a51d2a1
Compare
@briancavalier sorry for 20 day delay, but I found reason why this test was not passing in IE (turns out |
Adds support for constructing es6 class instances. Fixes #181
Tests do not pass at this moment to highlight the non-backwards compatible change in automatic constructor detection. In order to accurately detect es6 classes I added check whether functions have a "constructor" property. As I have no better idea how to detect those classes, it's either this or explicit isConstructor will be needed in all components loading es6 classes.
When a decision is made how to approach this, I will adjust tests to conform to it.