Merge branch 'master' of factorcode.org:/git/factor into symbolic-enums

db4
Joe Groff 2010-04-20 17:17:35 -07:00
commit 305c3de2af
1 changed files with 10 additions and 9 deletions

View File

@ -8,20 +8,20 @@ IN: javascriptcore
ERROR: javascriptcore-error error ; ERROR: javascriptcore-error error ;
: with-javascriptcore ( quot -- )
set-callstack-bounds
call ; inline
SYMBOL: js-context SYMBOL: js-context
: with-global-context ( quot -- ) : with-global-context ( quot -- )
[ [
[ f JSGlobalContextCreate ] dip [ f JSGlobalContextCreate dup js-context set ] dip
[ '[ _ @ ] ] [ nip '[ @ ] ]
[ drop '[ _ JSGlobalContextRelease ] ] 2bi [ drop '[ _ JSGlobalContextRelease ] ] 2bi
[ ] cleanup [ ] cleanup
] with-scope ; inline ] with-scope ; inline
: with-javascriptcore ( quot -- )
set-callstack-bounds
with-global-context ; inline
: JSString>string ( JSString -- string ) : JSString>string ( JSString -- string )
dup JSStringGetMaximumUTF8CStringSize [ <byte-array> ] keep dup JSStringGetMaximumUTF8CStringSize [ <byte-array> ] keep
[ JSStringGetUTF8CString drop ] [ drop ] 2bi [ JSStringGetUTF8CString drop ] [ drop ] 2bi
@ -35,13 +35,14 @@ SYMBOL: js-context
drop f drop f
] if* ; ] if* ;
: eval-js ( context string -- result-string ) : eval-js ( string -- result-string )
dupd JSStringCreateWithUTF8CString f f 0 JSValueRef <c-object> [ js-context get dup ] dip
JSStringCreateWithUTF8CString f f 0 JSValueRef <c-object>
[ JSEvaluateScript ] keep *void* [ JSEvaluateScript ] keep *void*
dup [ nip JSValueRef>string javascriptcore-error ] [ drop JSValueRef>string ] if ; dup [ nip JSValueRef>string javascriptcore-error ] [ drop JSValueRef>string ] if ;
: eval-js-standalone ( string -- result-string ) : eval-js-standalone ( string -- result-string )
'[ [ _ eval-js ] with-global-context ] with-javascriptcore ; '[ _ eval-js ] with-javascriptcore ;
: eval-js-path-standalone ( path -- result-string ) utf8 file-contents eval-js-standalone ; : eval-js-path-standalone ( path -- result-string ) utf8 file-contents eval-js-standalone ;