Last active
December 15, 2015 21:59
-
-
Save JacobFierro/5329526 to your computer and use it in GitHub Desktop.
some research notes for use in a blog post. trying to understand how 'undefined' is implemented in the v8 engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//objects-inl.h | |
// undefined is a Primitive, which inherits from Object | |
bool Object::IsUndefined() { | |
return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUndefined; | |
} | |
// what's an Oddball and where is kUndefined defined and what is it set to? | |
/* | |
objects.h:8213 | |
Oddball class description | |
Oddball : HeapObject | |
The Oddball describes objects null, undefined, true, and false. | |
*/ | |
//objects.h:8247 | |
static const byte kUndefined = 5; // generally unsure is 5 is somehow significant | |
//include/v8.h:4301 | |
static const int kUndefinedValueRootIndex = 5; // not sure why this is defined twice, and this time it is an int | |
//factory.cc:1476 | |
Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { | |
Heap* h = isolate()->heap(); | |
if (name->Equals(h->undefined_string())) return undefined_value(); // look here | |
if (name->Equals(h->nan_string())) return nan_value(); | |
if (name->Equals(h->infinity_string())) return infinity_value(); | |
return Handle<Object>::null(); | |
} | |
// and where are undefined_string and undefined_value? | |
//heap.h:56 | |
V(Oddball, undefined_value, UndefinedValue) | |
//heap.h:221 | |
V(undefined_string, "undefined") // this must be where typeof x == "undefined" comes from | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment