javascriptv8

Is this V8 engine memory diagram missing stack references for object properties?


I've read some articles about V8 .However, I still have a question in my head :

As Far I As Know In V8 JavaScript engine : primitive values (like numbers and strings) and references to objects are always stored in the stack, while objects (including arrays and functions) are always stored in the heap but when (the references to objects or primitive values) is a property of another object it (the references to objects or primitive values) is stored in the heap to make the object properties together .

For example :

  let name ="Tom"; // name is stored in the stack
    let test ={name :"Tom", age:44}; // name and age are stored in the heap and test (the reference to the object) is stored in the stack
    let temp ={t1:test}; // t1 is stored in the heap and temp (the reference to the object) is stored in the stack

This article is about Shapes ( a.k.a Hidden Classes ) and there is that code

const point = {};
point.x = 4;
point.y = 5;
point.z = 6;

and there is a photo in the article that represents how the object (point) is look like in the memory : enter image description here

I think this photo only represents ( contains ) the part that is on the heap ( in another words : this photo does not represent ( contain ) the reference to the object (point) and that reference is stored in the stack ) so the photo must be like this : enter image description here

So My Question is : is my thought right ( in another words : is my photo right ? ) ?


Solution

  • In V8 JavaScript engine : primitive values (like numbers and strings) and references to objects are always stored in the stack

    Nope, that's incorrect. (See e.g. here for more detail.)

    I think this photo only represents ( contains ) the part that is on the heap

    Yes. (Note that you can actually see primitives on the heap there, which refutes your initial premise.)