On Sat, May 25, 2019 at 12:01 AM <teempe...@gmail.com> wrote:
>
> 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

I'd tackle that at the API boundary.
ScriptCompiler::CompileUnboundInternal() in src/api.cc should cover
all C++ entry points.

Compiler::GetFunctionFromEval() in src/compiler.cc is probably the
method you want to patch if you also want to intercept eval() and
Function().

-- 
-- 
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAHQurc-hJETpN8QrGaeXkYnOCTsu8pfBdz9aw9nhuDGdRdcemQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to