12

From the Blink Blog:

Finally we’d like to explore even larger ideas like moving the entire Document Object Model (DOM) into JavaScript.

What does this mean? Does it mean WebKit's DOM is currently not coded in JavaScript but in some other language? Does it mean that they want to expose more public accessors to the DOM? Or what?

BSalita
  • 323
  • 2
  • 6

1 Answers1

14

The way I read it there are two options. But before we look into this, you have to understand how the old model works.

In most, if not all implementations of HTML rendering engines, the DOM is implemented in C or C++ and the JavaScript engine is an add-on that has bindings exported to the DOM. This makes sense, if you look at how HTML and JavaScript evolved. But a lot of time is wasted in marshaling the calls from JavaScript to C/C++ and back.

The first option is that the DOM becomes more closely bound to the JavaScript engine. Basically the DOM objects becomes core JavaScript objects, like Array. This does not do much except reduce some marshaling, since the DOM uses the native data types from the JavaScript engine. The DOM is then still implemented in C or C++.

The second option and probably what they mean, is that the actual DOM is implemented in JavaScript. The downside is that the access to the DOM is fully interpreted, but on the upside it removes any marshaling. This is probably a net gain, since the DOM is mostly data anyway.

Then again I can't give you a definite answer - I don't work for Google and thus don't have that much insight.

rioki
  • 256
  • 2
  • 4
  • 1
    I don't think there is any overhead in binding special types compared to the "native" types of the JavaScript engines as that engine is written in C++ and all types are implemented using the same mechanism. What can be saved by using the native JavaScript types is a code as a lot of code needs to be duplicated for the native types and the DOM types. – Jan Hudec Apr 10 '13 at 07:29
  • From what I know (from es-discuss mailing list, for example), it is definitely the latter. There is a wish to have DOM written in JS, not just because of marshalling cost (which _is_ there), but also for removing as much of the "exotic", "non-native", "special" objects from the language space as possible. DOM is big PITA for language designers, because it is special. – herby Apr 10 '13 at 08:23
  • There is a design document on this topic recently https://docs.google.com/document/d/13cT9Klgvt_ciAR3ONGvzKvw6fz9-f6E0FrqYFqfoc8Y/edit# – subbul Jan 21 '14 at 16:07