Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze HeapNumber for js engine v8 source code

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to carry out js engine v8 source code analysis HeapNumber. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

A HeapNumber is an object that holds a large plastic shape. Smi saves plastic surgery in V8, but it only has 31 bits, and those with more than 31 bits need to use HeapNumber.

/ / A heap object with stored numbers

Class HeapNumber: public HeapObject {

Public:

Inline double value ()

Inline void set_value (double value)

Static inline HeapNumber* cast (Object* obj)

Object* HeapNumberToBoolean ()

/ / Layout description.

/ / the space before kSize stores pointers to map objects

Static const int kValueOffset = HeapObject::kSize

/ / the value of the number stored between kValueOffset-kSize.

Static const int kSize = kValueOffset + kDoubleSize

Private:

DISALLOW_IMPLICIT_CONSTRUCTORS (HeapNumber)

}

The following is implemented.

1 access value

/ / returns the value of type double

Double HeapNumber::value () {

Return READ_DOUBLE_FIELD (this, kValueOffset)

}

/ / write double value to object

Void HeapNumber::set_value (double value) {

WRITE_DOUBLE_FIELD (this, kValueOffset, value)

}

2 digits are converted to Boolean values. 0 and NAN are false, and the rest are true.

Object* HeapNumber::HeapNumberToBoolean () {

/ / NaN, + 0, and-0 should return the false object

Switch (fpclassify (value () {

Case FP_NAN: / / fall through

Case FP_ZERO: return Heap::false_value ()

Default: return Heap::true_value ()

}

}

/ / refer to the definition of floating point number in ieee.

Int fpclassify (double x) {

/ / Use the MS-specific _ fpclass () for classification.

Int flags = _ fpclass (x)

/ / non-0 positive or non-0 negative

If (flags & (_ FPCLASS_PN | _ FPCLASS_NN)) return FP_NORMAL

/ / positive or negative 0

If (flags & (_ FPCLASS_PZ | _ FPCLASS_NZ)) return FP_ZERO

/ / non-standardized positive or negative values

If (flags & (_ FPCLASS_PD | _ FPCLASS_ND)) return FP_SUBNORMAL

/ / positive and negative infinity

If (flags & (_ FPCLASS_PINF | _ FPCLASS_NINF)) return FP_INFINITE

/ / All cases should be covered by the code above.

/ / not a numeric value

ASSERT (flags & (_ FPCLASS_SNAN | _ FPCLASS_QNAN))

Return FP_NAN

}

The above is the editor for you to share how to carry out js engine v8 source code analysis HeapNumber, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report