Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling V8 without networking, etc

Tags:

c++

javascript

v8

I want to embed V8 into a project I'm working on. This project does not use networking at all - in fact it avoids networking for security reasons (I don't want to open a cross-site-scripting Pandora's Box that I'm not prepared for). Regardless, I only want javascript.

From what I understand, V8 is just a bare bones javascript compiler and VM, which is good - yet it needs to compile with various 3rd party libraries to be able to adapt to added functionality. Networking is one of those things, I guess. To be able to build an application that uses V8, you have to link with Winsock.

I want to be able to strip these extra libraries from the engine and add bindings to my own internal code from the ground up (besides strings and stuff like that), but I can't find a guide or bit of documentation that helps me do this. What functionality does V8 add on top of being a javascript engine that I should know about, and how can I remove it?

EDIT: I also noticed URI is included, which is not particularly useful for what I'm doing. URI functions are not optimized out since a standard library of sorts is embedded in the executable, and I'd like to remove those as well (along with any other XML/Http related javascript functions).

like image 287
NmdMystery Avatar asked Mar 04 '14 07:03

NmdMystery


1 Answers

Networking. Currently V8 needs networking for its debugger agent, it is possible to use engine without it, but you need to modify source code.

  1. src/platform/socket.h

    Replace NativeHandle typedef for your OS (like V8_OS_WIN) with:

    typedef int NativeHandle;
    

    Replace kInvalidNativeHandle const value with -1.

    Remove OS include file(s).

  2. src/platform/socket.cc

    Replace bodies of all Socket class methods with stubs, for example like this:

    bool Socket::Bind(int port) {
      assert(!"Socket usage.");
      return true;
    }
    
    bool Socket::Listen(int backlog) {
      assert(!"Socket usage.");
      return true;
    }
    ...
    

    Remove other OS-specific functions from this file, etc.

    This should remove all V8 networking dependencies.

XML/HTTP functions.. V8 does not include those. They are usually implemented by embedder.

URI functions I wouldn't recommend to remove those, as well as any other JavaScript builtin functions. This may break the engine. And they are safe to use anyway.

ICU. You can build V8 without ICU library with build option i18nsupport=off. In this case you need to initialize builtin ICU:

   v8::V8::InitializeICU();

Hope this helps. I'm myself using V8 in very restricted environment with no networking/file system etc. Let me know if I forgot about other dependencies or you have any questions.

like image 176
iefserge Avatar answered Sep 29 '22 20:09

iefserge