diff --git a/extra/javascriptcore/ffi/ffi.factor b/extra/javascriptcore/ffi/ffi.factor index 6489699d4d..7a038b0883 100644 --- a/extra/javascriptcore/ffi/ffi.factor +++ b/extra/javascriptcore/ffi/ffi.factor @@ -2,16 +2,18 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.libraries alien.syntax classes.struct combinators io.encodings.utf16n -io.encodings.utf8 system ; +io.encodings.utf8 kernel system ; IN: javascriptcore.ffi << "javascriptcore" { - { [ os macosx? ] [ "/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore" ] } - ! { [ os winnt? ] [ "javascriptcore.dll" ] } - ! { [ os unix? ] [ "libsqlite3.so" ] } - [ ] - } cond cdecl add-library + { [ os macosx? ] [ + "/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore" cdecl add-library + ] } + ! { [ os winnt? ] [ "javascriptcore.dll" ] } + ! { [ os unix? ] [ "libsqlite3.so" ] } + [ drop ] +} cond >> LIBRARY: javascriptcore diff --git a/extra/javascriptcore/javascriptcore-tests.factor b/extra/javascriptcore/javascriptcore-tests.factor index f04ada89f2..53ae12d2b0 100644 --- a/extra/javascriptcore/javascriptcore-tests.factor +++ b/extra/javascriptcore/javascriptcore-tests.factor @@ -3,8 +3,8 @@ USING: accessors javascriptcore kernel tools.test ; IN: javascriptcore.tests -[ "2" ] [ "1+1" eval-js ] unit-test +[ "2" ] [ "1+1" eval-js-standalone ] unit-test -[ "1+shoes" eval-js ] +[ "1+shoes" eval-js-standalone ] [ error>> "ReferenceError: Can't find variable: shoes" = ] must-fail-with diff --git a/extra/javascriptcore/javascriptcore.factor b/extra/javascriptcore/javascriptcore.factor index eabb97df61..65b6fe5fff 100644 --- a/extra/javascriptcore/javascriptcore.factor +++ b/extra/javascriptcore/javascriptcore.factor @@ -35,14 +35,13 @@ SYMBOL: js-context drop f ] if* ; -: eval-js ( string -- result-string ) - '[ - [ - dup _ JSStringCreateWithUTF8CString f f 0 JSValueRef - [ JSEvaluateScript ] keep *void* - dup [ nip JSValueRef>string javascriptcore-error ] [ drop JSValueRef>string ] if - ] with-global-context - ] with-javascriptcore ; +: eval-js ( context string -- result-string ) + dupd JSStringCreateWithUTF8CString f f 0 JSValueRef + [ JSEvaluateScript ] keep *void* + dup [ nip JSValueRef>string javascriptcore-error ] [ drop JSValueRef>string ] if ; -: eval-js-path ( path -- result-string ) utf8 file-contents eval-js ; +: eval-js-standalone ( string -- result-string ) + '[ [ _ eval-js ] with-global-context ] with-javascriptcore ; + +: eval-js-path-standalone ( path -- result-string ) utf8 file-contents eval-js-standalone ;