I can't find in the V8 code a call to the valueOf method during type casting in this example:
let foo = {
valueOf: () => 0
};
foo + 1; // 1
I tried debugging the code and printing the stack trace via base::debug::StackTrace().Print()
in the LookupIterator constructor here here, but alas, I did not understand exactly where the valueOf call comes from.
It's a fairly long chain to trace through "builtins" implemented in various techniques. It starts at Generate_AddWithFeedback
and ends in builtin OrdinaryToPrimitive_Number_Inline
which passes ValueOfStringConstant()
as a parameter to macro TryToPrimitiveMethod
defined right above it.
(That's for the interpreter; other execution tiers will use other code paths. V8 is complex.)
How do V8 "internal" calls work, such as valueOf?
As far as the call itself is concerned, it works just like any other call. From the rest of your question, it seemed that what you really wanted to know was where that call is happening.