Search code examples
chromiumv8

How torque's "extern transitioning macro" is implemented in CodeStubAssembler


My question is a kind of sequel to that question. There @jmrk explained to me where the valueOf() method is called when converting an object to a number. The TryToPrimitiveMethod code has a GetProperty call, which is declared here as extern transitioning macro GetProperty(...).

The Torque user manual says that if a macro is marked as extern, "the implementation must be provided as hand-written CSA code in a CodeStubAssembler class". I found an implementation of this method here and tried first to output a stack trace and then a plain string in std::cout. But I didn't get any results at all at runtime. Why does this happen and is it possible to get any output at all?


Solution

  • You've almost found the right implementation: Torque's JSAny maps to the CodeStubAssembler's TNode<Object>, so the GetProperty overload you're looking for is the other one, in line 3290:

      TNode<Object> GetProperty(TNode<Context> context, TNode<Object> receiver,
                                TNode<Object> name) {
        return CallBuiltin(Builtin::kGetProperty, context, receiver, name);
      }
    

    When inserting any printing code there (or setting a breakpoint, for that matter), you won't see any output at runtime because all of that code (both Torque and CSA) only runs during the V8 build process. It's not even included in the final binaries. It's used to generate builtins; these builtins are in the final binaries.

    For printf-style debugging, there are a few Print functions in CSA, which emit the equivalent of printf calls into the generated builtins.