http://www.ibm.com/developerworks/cn/linux/l-cn-spidermonkey/linux
https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_User_Guidec++
http://zh.wikipedia.org/wiki/SpiderMonkey編程
下載地址:api
http://ftp.mozilla.org/pub/mozilla.org/js/多線程
http://blog.csdn.net/singlerace/article/details/1370215ide
使用 SpiderMonkey 腳本化您的應用函數式編程
JavaScript 語言具備動態性,支持函數式編程,動態弱類型等等優勢。做爲一個腳本語言,能夠很方便的腳本化須要高度可定製的應用程序。本文介紹基於 C 語言的 JavaScript 引擎 SpiderMonkey,詳細討論如何經過該引擎,使得 C 語言和 JavaScript 語言進行交互。函數
和其餘的 JavaScript 引擎同樣,SpiderMonkey 不直接提供像 DOM 這樣的對象,而是提供解析,執行 JavaSccript 代碼,垃圾回收等機制。SpidlerMonkey 是一個在 Mozilla 之下的開源項目,要使用 SpiderMonkey,須要下載其源碼,而後編譯爲靜態 / 動態庫使用。ui
要在本身的應用程序中使用 SpiderMonkey,首先須要瞭解如下三個核心概念:spa
運行時環境運行時環境是全部 JavaScript 變量,對象,腳本以及代碼的上下文所存在的空間。每個上下文對象,以及全部的對象均存在於此。通常應用僅須要一個運行時便可。
上下文上 下文即腳本執行的環境,在 SpiderMonkey 中,上下文能夠編譯執行腳本,能夠存取對象的屬性,調用 JavaScript 的函數,轉換類型,建立 / 維護對象等。幾乎全部的 SpiderMonkey 函數都須要上下文做爲其第一個參數 (JSContext *)。
上下文與線程密不可分,通常來說,單線程應用可使用一個上下文來完成全部的操做,每個上下文每次只能完成一個操做,全部在多線程應用中,同一時刻只能有一個線程來使用上下文對象。通常而言,多線程應用中,每一個線程對應一個上下文。
全局對象全局對象包含 JavaScript 代碼所用到的全部類,函數,變量。在 DOM 操做中,咱們使用的:
alter("something");
事實上使用的是全局變量 window 的一個屬性 alter( 這個屬性正好是一個函數 ),事實上上邊的語句在執行時會別解釋爲:
window.alter("something");
http://stackoverflow.com/questions/10205202/error-while-compiling-an-embedded-spidermonkey-program
helloworld.cpp:In function ‘int main(int,constchar**)’: helloworld.cpp:74:20: warning: deprecated conversion from string constant to ‘char*’[-Wwrite-strings] helloworld.cpp:83:17: warning: NULL used in arithmetic [-Wpointer-arith]/tmp/ccUU9may.o:In function `main': helloworld.cpp:(.text+0x6e): undefined reference to `JS_Init' helloworld.cpp:(.text+0x94): undefined reference to `JS_NewContext' helloworld.cpp:(.text+0xba): undefined reference to `JS_SetOptions' helloworld.cpp:(.text+0xcb): undefined reference to `JS_SetVersion' helloworld.cpp:(.text+0xdc): undefined reference to `JS_SetErrorReporter'
https://bugzilla.mozilla.org/show_bug.cgi?id=547715
c++ -o jsapi-tests -fno-rtti -fno-exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof -Wno-variadic-macros -Wno-long-long -g -fno-strict-aliasing -pthread -pipe -DNDEBUG -DTRIMMED -Os -freorder-blocks -fno-reorder-functions tests.o selfTest.o testPropCache.o testXDR.o testIntString.o testIsAboutToBeFinalized.o testSameValue.o testDebugger.o testDefineGetterSetterNonEnumerable.o testExtendedEq.o -Wl,--as-needed -lpthread -Wl,-rpath-link,/bin -Wl,-rpath-link,/lib -L../../../dist/bin -L../../../dist/lib -L/usr/lib -lplds4 -lplc4 -lnspr4 -lpthread -ldl ../libjs_static.a -ldl -lm ../libjs_static.a(jsapi.o): In function `JS_ClearContextThread': /tmp/xulrunner/js/src/jsapi.cpp:5901: undefined reference to `PR_Lock' /tmp/xulrunner/js/src/jsapi.cpp:5904: undefined reference to `PR_Unlock' ../libjs_static.a(jsapi.o): In function `JS_SetContextThread': /tmp/xulrunner/js/src/jsapi.cpp:5876: undefined reference to `PR_Unlock' ../libjs_static.a(jsapi.o): In function `JS_DropPrincipals': /tmp/xulrunner/js/src/jsapi.cpp:4184: undefined reference to `PR_AtomicDecrement' ../libjs_static.a(jsapi.o): In function `JS_ToggleOptions': /tmp/xulrunner/js/src/jsapi.cpp:1184: undefined reference to `PR_Lock' /tmp/xulrunner/js/src/jsapi.cpp:1189: undefined reference to `PR_Unlock' (snip) This is because the static library comes after the nspr link flags.