Merge branch 'master' of factorcode.org:/git/factor

db4
Joe Groff 2010-04-20 15:28:19 -07:00
commit 1f30eba364
3 changed files with 18 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -35,14 +35,13 @@ SYMBOL: js-context
drop f
] if* ;
: eval-js ( string -- result-string )
'[
[
dup _ JSStringCreateWithUTF8CString f f 0 JSValueRef <c-object>
[ 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 <c-object>
[ 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 ;