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)
- [Bug]: 30.0.0-alpha7 and up crash on fullscreen with SIGSEGV HOT 9
- [Bug]: Font substituting while printing doesn't work on Windows Server 2016 HOT 2
- [Bug]: in my electron i am using multiple webview and i am not able to get which webview is in focus or even onclick event HOT 2
- feature request: allow build with enable_extensions=false HOT 2
- [Feature Request]: Possibility to set a default zoom level
- [Bug]: WARNING: AVCaptureDeviceTypeExternal is deprecated for Continuity Cameras. Please use AVCaptureDeviceTypeContinuityCamera and add NSCameraUseContinuityCameraDeviceType to your Info.plist. HOT 1
- [Bug]: macos v14 sonoma Previously developed electron, now white screen no content HOT 1
- [Bug]: process.exit does return and is not exiting synchronously when called in async function HOT 3
- [Bug]: process.env.npm_package_version cannot be read in product HOT 1
- [Bug]: ReadableStream is malformed when protocol.handle'd HOT 2
- [Bug]: Window Not Displaying Over Dock in Fullscreen Mode HOT 5
- [Bug]: IndexedDB corrupted and reset when no disk space
- electron应用在分辨率为1600*900的时候,出现亮线问题 HOT 10
- [Bug]: core dump on showing the app window via clicking tray icon HOT 3
- [Bug]: autoUpdater.quitAndInstall() not working on M1 Mac, works on Intel Mac HOT 1
- [Bug]: touchmove coordinates screenX and screenY errors
- [Bug]: App. DisableHardwareAcceleration() affect transparent effect HOT 2
- 打包后的安装包在安装时会卡死 HOT 1
- [Bug]: electron应用在linux端刚启动的时候出现白屏问题 HOT 1
- [Bug]: File picker not always on top
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.