Javascript解析器v8庫入門

來源:互聯網
上載者:User

1) 簽出原始碼

svn checkout http://v8.googlecode.com/svn/trunk/ v8


2)在v8根目錄下簽出gyp

svn co http://gyp.googlecode.com/svn/trunk build/gyp

3)在v8根目錄下籤出python和cygwin

svn co http://src.chromium.org/svn/trunk/tools/third_party/python_26@89111 third_party/python_26
svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@66844 third_party/cygwin

4)添加python和cygwin的路徑到環境變數

set path="%cd%\third_party\python_26";"%cd%\third_party\cygwin\bin;%path%

5) 產生編譯專案檔(gyp是json設定檔和python指令碼的工具集,是一個元編譯系統,用來產生真正的編譯系統,比如常見的Makefile, *.sln, *.vcproj 等)

python build\gyp_v8

6) 開啟編譯項目編譯(在命令列裡面用start方式開啟sln檔案,可以讓visual studio編譯系統繼承環境變數)

start build\all.sln 

7) 編譯

build/{debug,release}/lib 下得到4個靜態庫檔案(windows上預設也是靜態庫檔案)

preparser_lib.lib
v8_base.lib
v8_nosnapshot.lib
v8_snapshot.lib

標頭檔在v8根目錄下的include檔案夾裡面

8) 測試

testv8.cxx

// testv8.cpp : Defines the entry point for the console application.//#include <v8.h>using namespace v8;int main(int argc, char* argv[]) {// Create a stack-allocated handle scope.HandleScope handle_scope;// Create a new context.Persistent<Context> context = Context::New();// Enter the created context for compiling and// running the hello world script. Context::Scope context_scope(context);// Create a string containing the JavaScript source code.Handle<String> source = String::New("var x='xyziamheres2///sdfsdf123'; x.match(/\\d{3,3}/);");// Compile the source code.Handle<Script> script = Script::Compile(source);// Run the script to get the result.Handle<Value> result = script->Run();// Dispose the persistent context.context.Dispose();// Convert the result to an ASCII string and print it.String::AsciiValue ascii(result);printf("%s\n", *ascii);return 0;}

在testv8.cxx所在目錄下建立檔案夾

v8/inc

v8/lib/debug

v8/lib/release

把產生lib檔案和標頭檔一起複製到相應的目錄

9) 編譯測試testv8

cl /Od /I "v8/inc" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\testv8.cpp"

link "/OUT:C:\Users\Administrator\Documents\Visual Studio 2008\Projects\testv8\Debug\testv8.exe" /INCREMENTAL "/LIBPATH:v8/lib/Debug" /MANIFEST "/MANIFESTFILE:Debug\testv8.exe.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /DEBUG "/PDB:c:\Users\Administrator\Documents\Visual Studio 2008\Projects\testv8\Debug\testv8.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /MACHINE:X86 v8_snapshot.lib v8_base.lib preparser_lib.lib ws2_32.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 

10) 運行testv8

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.