Merge branch 'master' of factorcode.org:/git/factor
commit
d6b56c7e25
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2010 Doug Coleman.
|
! Copyright (C) 2010 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.c-types alien.libraries alien.syntax
|
USING: alien alien.c-types alien.libraries alien.syntax
|
||||||
classes.struct combinators io.encodings.utf8 system ;
|
classes.struct combinators io.encodings.utf16n
|
||||||
|
io.encodings.utf8 system ;
|
||||||
IN: javascriptcore.ffi
|
IN: javascriptcore.ffi
|
||||||
|
|
||||||
<<
|
<<
|
||||||
|
@ -9,6 +10,7 @@ IN: javascriptcore.ffi
|
||||||
{ [ os macosx? ] [ "/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore" ] }
|
{ [ os macosx? ] [ "/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore" ] }
|
||||||
! { [ os winnt? ] [ "javascriptcore.dll" ] }
|
! { [ os winnt? ] [ "javascriptcore.dll" ] }
|
||||||
! { [ os unix? ] [ "libsqlite3.so" ] }
|
! { [ os unix? ] [ "libsqlite3.so" ] }
|
||||||
|
[ ]
|
||||||
} cond cdecl add-library
|
} cond cdecl add-library
|
||||||
>>
|
>>
|
||||||
|
|
||||||
|
@ -36,7 +38,6 @@ TYPEDEF: void* JSObjectHasInstanceCallback
|
||||||
TYPEDEF: void* JSObjectConvertToTypeCallback
|
TYPEDEF: void* JSObjectConvertToTypeCallback
|
||||||
TYPEDEF: uint unsigned
|
TYPEDEF: uint unsigned
|
||||||
TYPEDEF: ushort JSChar
|
TYPEDEF: ushort JSChar
|
||||||
! char[utf16n] for strings
|
|
||||||
|
|
||||||
C-ENUM: JSPropertyAttributes
|
C-ENUM: JSPropertyAttributes
|
||||||
{ kJSPropertyAttributeNone 0 }
|
{ kJSPropertyAttributeNone 0 }
|
||||||
|
@ -202,7 +203,7 @@ FUNCTION: void JSPropertyNameAccumulatorAddName ( JSPropertyNameAccumulatorRef a
|
||||||
|
|
||||||
FUNCTION: JSStringRef JSStringCreateWithCharacters ( JSChar* chars, size_t numChars ) ;
|
FUNCTION: JSStringRef JSStringCreateWithCharacters ( JSChar* chars, size_t numChars ) ;
|
||||||
|
|
||||||
FUNCTION: JSStringRef JSStringCreateWithUTF8CString ( c-string[utf8] string ) ;
|
FUNCTION: JSStringRef JSStringCreateWithUTF8CString ( c-string string ) ;
|
||||||
|
|
||||||
FUNCTION: JSStringRef JSStringRetain ( JSStringRef string ) ;
|
FUNCTION: JSStringRef JSStringRetain ( JSStringRef string ) ;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
! Copyright (C) 2010 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: accessors javascriptcore kernel tools.test ;
|
||||||
|
IN: javascriptcore.tests
|
||||||
|
|
||||||
|
[ "2" ] [ "1+1" eval-js ] unit-test
|
||||||
|
|
||||||
|
[ "1+shoes" eval-js ]
|
||||||
|
[ error>> "ReferenceError: Can't find variable: shoes" = ] must-fail-with
|
||||||
|
|
|
@ -1,8 +1,48 @@
|
||||||
! Copyright (C) 2010 Doug Coleman.
|
! Copyright (C) 2010 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: javascriptcore.ffi.hack kernel ;
|
USING: alien.c-types alien.data byte-arrays continuations fry
|
||||||
|
io.encodings.string io.encodings.utf8 io.files
|
||||||
|
javascriptcore.ffi javascriptcore.ffi.hack kernel namespaces
|
||||||
|
sequences ;
|
||||||
IN: javascriptcore
|
IN: javascriptcore
|
||||||
|
|
||||||
|
ERROR: javascriptcore-error error ;
|
||||||
|
|
||||||
: with-javascriptcore ( quot -- )
|
: with-javascriptcore ( quot -- )
|
||||||
set-callstack-bounds
|
set-callstack-bounds
|
||||||
call ; inline
|
call ; inline
|
||||||
|
|
||||||
|
SYMBOL: js-context
|
||||||
|
|
||||||
|
: with-global-context ( quot -- )
|
||||||
|
[
|
||||||
|
[ f JSGlobalContextCreate ] dip
|
||||||
|
[ '[ _ @ ] ]
|
||||||
|
[ drop '[ _ JSGlobalContextRelease ] ] 2bi
|
||||||
|
[ ] cleanup
|
||||||
|
] with-scope ; inline
|
||||||
|
|
||||||
|
: JSString>string ( JSString -- string )
|
||||||
|
dup JSStringGetMaximumUTF8CStringSize [ <byte-array> ] keep
|
||||||
|
[ JSStringGetUTF8CString drop ] [ drop ] 2bi
|
||||||
|
utf8 decode [ 0 = ] trim-tail ;
|
||||||
|
|
||||||
|
: JSValueRef>string ( ctx JSValueRef/f -- string/f )
|
||||||
|
[
|
||||||
|
f JSValueToStringCopy
|
||||||
|
[ JSString>string ] [ JSStringRelease ] bi
|
||||||
|
] [
|
||||||
|
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-path ( path -- result-string ) utf8 file-contents eval-js ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue