Refactoring and bug fixes in the V8 API
Merged
19
2y ago+1917+1917+0123456789012345678901234567890123456789-1244-1244-0123456789012345678901234567890123456789
What does this PR do?
Refactors and bugfixes in our V8 API implementation. So far:
- Fix some places that did not handle oddballs (booleans or nullish JS values) properly (EscapableHandleScope, Global)
- Support
NewStringType::kInternalized- Previously the type was ignored. Now internalized strings are created with
WTF::AtomString.
- Previously the type was ignored. Now internalized strings are created with
- Remove or merge many functions that convert between V8 and JSC values
- Make
v8::Contextbe aZig::GlobalObjectinstead of the same thing asv8::Isolate, which lets us access the global object with less indirection in functions that take a Context- side effect: there are now only 2 kinds of V8 handle, for cells and doubles, instead of 3. Context was the only place a
void *handle was used.
- side effect: there are now only 2 kinds of V8 handle, for cells and doubles, instead of 3. Context was the only place a
- Make
v8::Isolatean actual class containing everythingv8::Rootsused to, and deletev8::Roots, instead of reinterpreting betweenIsolateandRootsv8::Roots's only purpose was to hold values at the offsets from anIsolatepointer that V8 expects. Now we actually store those values in theIsolatelike V8 does.
- Test case and bug fix for
EscapableHandleScope - Use
m_on C++ class field names for clarity - Move Bun-specific classes (i.e. classes that we use to implement the V8 API, but that don't actually exist in the real V8 API) into the namespace
v8::shim.- All V8 classes that are kept in a
Local(String,ObjectTemplate, etc.) now have zero fields, matching how V8's API works and making it less likely to crash by accessing a member whilethisis the invalid pointer that we get from V8. The cell pointer stored in the handle is either a built-in type (JSString,JSObject) or a type inv8::shim(v8::shim::InternalFieldObject,v8::shim::Function)
- All V8 classes that are kept in a
- Move isosubspace declarations for V8 types next to the ones for other Bun-specific types
- Support
Function::GetNameandValue::IsFunction - Make the
thisvalue received by native functions correct (it should be coerced to an object, or overridden byglobalThisif null or undefined, like in JavaScript sloppy mode) - Add a ton of static assertions to check that we match important V8 implementation details
How did you verify your code works?
Most of the V8 API is covered by existing tests. A couple new tests were added.