How to map JavaScript code to Google v8?

190 views Asked by At

I mean, in JavaScript, there is string operation, how to find Google v8 code process string operation? How to find Google v8 code process array related operation? how to find Google v8 code process prototype related operation?

Is there any guide about how to read google v8 source code? I want to hook some Javascript operations in google v8.

Thanks, any hint is highly appriciated. Thanks in advance.

2

There are 2 answers

0
Stefan Dimov On

V8 Engine

Here you can find everything - documentation and instructions.

You have to read up on it, there is no easy way.

0
Cyrbil On

You can find google's V8 code here. If you want to see V8 code at runtime, you can't.

For instance: the IndexOf method for String is:

RUNTIME_FUNCTION(Runtime_StringIndexOf) {
  HandleScope scope(isolate);
  DCHECK(args.length() == 3);

  CONVERT_ARG_HANDLE_CHECKED(String, sub, 0);
  CONVERT_ARG_HANDLE_CHECKED(String, pat, 1);
  CONVERT_ARG_HANDLE_CHECKED(Object, index, 2);

  uint32_t start_index;
  if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);

  RUNTIME_ASSERT(start_index <= static_cast<uint32_t>(sub->length()));
  int position = StringMatch(isolate, sub, pat, start_index);
  return Smi::FromInt(position);
}