@@ -84,6 +84,9 @@ class JSContextTests : XCTestCase {
84
84
}
85
85
86
86
func testIntl( ) throws {
87
+ // the Skip side uses jsc-android rather than jsc-android-intl for size savings
88
+ // TODO: provide a separate SkipScriptIntl target that depends on jsc-android-intl
89
+ #if !SKIP
87
90
let ctx = try XCTUnwrap ( JSContext ( ) )
88
91
89
92
XCTAssertEqual ( " 12,34 € " , ctx. evaluateScript ( " new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(12.34) " ) ? . toString ( ) )
@@ -104,6 +107,7 @@ class JSContextTests : XCTestCase {
104
107
105
108
XCTAssertEqual ( " 10/24/2022 " , ctx. evaluateScript ( " new Intl.DateTimeFormat('en-US', {timeZone: 'UTC'}).format(new Date('2022-10-24')) " ) ? . toString ( ) )
106
109
XCTAssertEqual ( " 24/10/2022 " , ctx. evaluateScript ( " new Intl.DateTimeFormat('fr-FR', {timeZone: 'UTC'}).format(new Date('2022-10-24')) " ) ? . toString ( ) )
110
+ #endif
107
111
}
108
112
109
113
func testProxy( ) throws {
@@ -164,56 +168,6 @@ class JSContextTests : XCTestCase {
164
168
XCTAssertEqual ( false , ctx. objectForKeyedSubscript ( " boolProp " ) . toObject ( ) as? Bool )
165
169
}
166
170
167
- func testJSCCallbacks( ) throws {
168
- let jsc = JavaScriptCore . JSGlobalContextCreate ( nil )
169
- defer { JavaScriptCore . JSGlobalContextRelease ( jsc) }
170
- let ctx = try XCTUnwrap ( JSContext ( jsGlobalContextRef: jsc) )
171
-
172
- func eval( _ script: String ) throws -> JSValue {
173
- let result = ctx. evaluateScript ( script)
174
- if let exception = ctx. exception {
175
- throw JSEvalException ( exception: exception)
176
- }
177
- if let result = result {
178
- return result
179
- } else {
180
- throw JSEvalException ( )
181
- }
182
- }
183
-
184
- XCTAssertEqual ( " test " , try eval ( " 'te' + 'st' " ) . toString ( ) )
185
-
186
- let callbackName = JavaScriptCore . JSStringCreateWithUTF8CString ( " skip_cb " )
187
- defer { JavaScriptCore . JSStringRelease ( callbackName) }
188
-
189
- #if !SKIP
190
- func callbackPtr( ctx: JSContextRef ? , function: JSObjectRef ? , thisObject: JSObjectRef ? , argumentCount: Int , arguments: UnsafePointer < JSValueRef ? > ? , exception: UnsafeMutablePointer < JSValueRef ? > ? ) -> JSValueRef ? {
191
- JavaScriptCore . JSValueMakeNumber ( ctx, callbackResult)
192
- }
193
- #else
194
- let callbackPtr = JSCCallback ( )
195
- #endif
196
-
197
- let callbackFunction = JavaScriptCore . JSObjectMakeFunctionWithCallback ( jsc, callbackName, callbackPtr)
198
-
199
- // invoke the callback directly
200
- let f = try XCTUnwrap ( JavaScriptCore . JSObjectCallAsFunction ( jsc, callbackFunction, nil , 0 , nil , nil ) )
201
- XCTAssertEqual ( callbackResult, JavaScriptCore . JSValueToNumber ( jsc, f, nil ) )
202
-
203
- if !isAndroid { // crashes on Android, passes on Robolectric
204
- JavaScriptCore . JSObjectSetProperty ( jsc, jsc, callbackName, callbackFunction, JSPropertyAttributes ( kJSPropertyAttributeNone) , nil )
205
- XCTAssertEqual ( callbackResult. description, try eval ( " skip_cb() " ) . toString ( ) )
206
- }
207
- }
208
-
209
- #if SKIP
210
- class JSCCallback : com . sun . jna . Callback {
211
- func callback( ctx: JSContextRef ? , function: JSObjectRef ? , thisObject: JSObjectRef ? , argumentCount: Int32 , arguments: UnsafeMutableRawPointer ? , exception: UnsafeMutableRawPointer ? ) -> JSValueRef {
212
- JavaScriptCore . JSValueMakeNumber ( ctx!, callbackResult)
213
- }
214
- }
215
- #endif
216
-
217
171
func testJSCAPILow( ) throws {
218
172
let ctx = JavaScriptCore . JSGlobalContextCreate ( nil )
219
173
defer { JavaScriptCore . JSGlobalContextRelease ( ctx) }
0 commit comments