Move the guts of eval-js to its own word, add eval-js-standalone for unit tests

db4
Doug Coleman 2010-04-20 17:25:28 -05:00
parent 6ecf43b91f
commit b32782ac9b
2 changed files with 10 additions and 11 deletions

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 ;