Explore WebKit kernel (2) -- IDL and bindings

Source: Internet
Author: User
Tags comparison table perl script

The most amazing thing about WebKit is that JS can be tuned to the kernel (C/C ++), which is the key for WebOS to provide extended capabilities (to implement or expand W3C APIs ). To understand how a js method can be adjusted to C/C ++, we need to understand IDL and bindings. First, we need to explain the two terms:

  • IDL: Interface Definition Language, detailed explanation of visible http://trac.webkit.org/wiki/WebKitIDL
  • Bindings: WebKit dynamically generates code that is integrated with other frameworks (such as javascriptcore and V8 ).

I guess this is still confusing, so let's see why WebKit needs these two concepts. First, we have to understand that in the WebKit world, there are only dom-related behaviors. It does not know scripts, for example:

Document. getelementbyid ('domid ')

WebKit knows document and what to do with getelementbyid, but it does not know the getelementbyid function and does not have the ability to parse and execute scripts. Therefore, it needs a third-party parser to help, this is what javascriptcore (jscore) or V8 needs to do. However, javascriptcore or V8 is thin and can parse and execute the Javascript language itself. It does not know the specific implementation of getelementbyid. Therefore, WebKit needs to inject the specific implementation into it, speaking of this, we will probably understand why we need IDL and bindings. In fact, we are trying to provide a standard method (IDL) to let WebKit inject the implementation behind the js api into the Javascript parser, in addition, the specific registration and execution mechanisms of each parser are different. Therefore, bindings is required to dynamically generate the part that is combined with each parser, in this way, the same set of standard WebKit can be integrated with various Resolvers. After talking about it for half a day, you can see the following figure:

Among them, V8/jscore bindings contains products that are dynamically generated for each JS Based on the IDL specification. These products are registered on each Dom and can be recognized by V8/jscore, so take the document on V8. getelementbyid is used as an example. The Calling process is as follows:

  1. During compilation, v8document. cpp and v8document. h are dynamically generated based on document. IDL for document. cpp and document. H (this part of the logic will be dynamically generated later)
  2. V8document. cpp and v8document. h actually contain two things: one is the proxy for each method of document. cpp and document. h, and the other is the comparison between js api and each implementation method.
  3. WebKit registers the comparison table in v8document to the document Dom.
  4. Execute the script document. getelementbyid in WebKit.
  5. WebKit initializes V8 context according to the DOM structure of the latest document
  6. V8 parses and executes document. getelementbyid
  7. V8 executes the implementation in v8document. cpp corresponding to the getelementbyid method according to the table of comparison.
  8. Implementation of v8document. cpp proxy document. cpp

For jscore, the process and principle are the same, but the specific implementation details are different. The difference is embodied in bindings and jscore. For WebKit, the process is exactly the same, and the document is the same. CPP and document. the H standard implementation can be adapted to different Resolvers for parsing and execution. This is the subtlety of IDL and bindings, allowing WebKit to be both single and fast.

There are two key points in the above process: one is to dynamically generate bindings, and the other is how to register and execute bindings, which is not fully understood due to the limited skill of C/C ++, leave it to the end for further consideration. The previous point is part of the powerful compilation system of WebKit. The following is a detailed explanation.

First extract the differences between different compilation platforms, WebKit is through the WebCore/bindings/scripts/In the generate-bindings.pl Perl script to generate bindings code, it will be android on the Android platform. derived. v8bindings. MK is called and derivedsources is used on Mac. the general process of calling make is very clear:

  1. Parse IDL
  2. Call the corresponding codegenerate script of each platform
  3. Generate the final bindings code

See:

For the specific implementation logic, let's look at the source code of each script. In addition, for the script registration and execution, you can look at the scriptcontroller under bindings. CPP. Of course, to learn how to call the code in the comparison table in V8/jscore, you need to look at the V8/jscore source code. V8 depends on execution. for CC and jscore, check jitcode. h.

To sum up, WebKit uses IDL and bindings to remove itself from the JS language itself, allowing itself to implement the logic behind the js api without having to understand the JS language!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.