Comments (3)
A typical example of inheriting native class is:
class AtomWindow extends BrowserWindow
constructor: ->
# blabla...
super
To make it work, the generated constructor should return the result of base class's constructor, like this:
function AtomWindow() {
return AtomWindow.__super__.constructor.apply(this, arguments);
}
But somehow coffeescript generated constructor like this:
function AtomWindow() {
AtomWindow.__super__.constructor.apply(this, arguments);
}
There seems to be tons of related issues in coffeescript's github page, I'm still investigating it.
from electron.
Hmm, coffeescript is doing the right thing, my problem is now that the native class's internal fields are not inherited via prototype inheritance, this is a limitation of V8 or JavaScript, but v8-juice does have a workaround of it:
http://code.google.com/p/v8-juice/source/browse/trunk/src/include/v8/juice/ClassWrap.h#480
from electron.
After some experiments, I decided to make BrowserWindow not inheritable again, here are my reasons:
-
Internal fields are not inheritable
Because BrowserWindow is a wrap of native C++ class, I need to store C++ object in V8 object's internal fields, however since internal fields are not inherited via prototype inheritance, I can not get the wrapped C++ object from derived class's
this
object without hacks. -
Performance
In order to be able to get the wrapped C++ object from JS object, I have to store the native
this
object in the JS object somewhere, and then manually find it when I need to lookup the C++ object, which hurts the performance. -
Too many hacks in JS
To make inheritance of native class work as expected, many hacks have to be used, the v8-juice's Wiki explains this very well:
http://code.google.com/p/v8-juice/wiki/ClassBinderPartTwo#Inheriting_Native_Classes_from_JSAnd generated JS code of Coffee Script doesn't work well with these hacks.
-
Two
this
objectDistinguished from inheritance of pure JS class, which just calls base class's constructor as plain function, inheriting native class requires calling the native class's constructor with
new
, and also remembering the created nativethis
object, which means we have to work with twothis
objects, this just make things a mess.
So my conclusion is, making inheritance of native class from JS work would cause too much troubles and we should not support it.
from electron.
Related Issues (20)
- gitHub.com/docker/repo
- [Feature Request]: add config.hideDock to BrowserWindow.setHiddenInMissionControl
- [Bug]: Calling session.defaultSession.webRequest.onHeadersReceived after ready and before window creation causes silent crash
- webContents.getPrintersAsync() not returning printer list on Linux Mint Cinnamon 19.1 HOT 3
- [Bug]: Frameless BrowserView.setAutoResize() is broken in v30.0.1
- [Infra]: Test check CI failed to execute because of npm package not found HOT 3
- [Bug]: <input type="file"> is not showing dialog on click HOT 7
- [Bug]: app.setLoginItemSettings({ openAtLogin: true }) doesnt work in APPX after publishing it.
- [Bug]: <input type=file> not working in WebContentsView HOT 1
- [Bug]: Occasional segfault when closing window on Linux
- stop removing tags from your repo HOT 12
- [Bug]: `screen.getAllDisplays()` and `desktopCapturer.getSources()` order no longer matches (29.3.2, 30.0.2)
- [Bug]: `desktopCapturer` thumbnails not respecting `thumbnailSize`, always low-res (29.3.2)
- [Bug]: Calling preventDefault on BrowserWindow close event still destroys BrowserViews' webContents
- [Feature Request]: Support webp format in NativeImage class [totoWEBP()]
- [Bug]: `fs.readdir` does not work correctly with files that contain umlauts
- [Bug]: showMessageBox ignores abort signal if BrowserWindow is not provided on MacOS HOT 1
- [Bug]: Do not working portable version HOT 1
- [Feature Request]: Computer shutdown/sleep request
- [Bug]: WebContentsView preload.js events fullscreenchange not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron.