Hi all,
I'm trying to create some automatic rewriting of all the JS code that is being parsed by Chrome/V8. For that I went to ParseInfo::CreateScript and just replaced the source string with my rewritten one:
std::string s = source->ToCString().get();
std::string transformed = rewrite(isolate, s); // rewrite is implemented somewhere else.
v8::internal::Factory* factory = isolate->factory();
v8::internal::Vector<const char> vec(transformed.data(), static_cast<size_t>(transformed.size()));
source = factory->NewStringFromUtf8(vec).ToHandleChecked();
However that seems to mess with the rest of the parsing process, because the first few hundred characters of my source go randomly missing when the parser starts parsing (I couldn't figure that bug out yet).
Are there any better functions where I can inject this rewriting logic, e.g. some central parsing function where it's safer to replace the string?
(Note that I only want to create some proof-of-concept, not something that would ever go into production).
Cheers,
- Raphael