@@ -137,10 +137,8 @@ public class JSFunction: JSObject, _JSFunctionProtocol {
137
137
id, argv, Int32 ( argc) ,
138
138
& payload1, & payload2
139
139
)
140
- let kindAndFlags = unsafeBitCast ( resultBitPattern, to: JavaScriptValueKindAndFlags . self)
141
- #if !hasFeature(Embedded)
140
+ let kindAndFlags = valueKindAndFlagsFromBits ( resultBitPattern)
142
141
assert ( !kindAndFlags. isException)
143
- #endif
144
142
let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
145
143
return result
146
144
}
@@ -156,7 +154,7 @@ public class JSFunction: JSObject, _JSFunctionProtocol {
156
154
id, argv, Int32 ( argc) ,
157
155
& payload1, & payload2
158
156
)
159
- let kindAndFlags = unsafeBitCast ( resultBitPattern, to : JavaScriptValueKindAndFlags . self )
157
+ let kindAndFlags = valueKindAndFlagsFromBits ( resultBitPattern)
160
158
#if !hasFeature(Embedded)
161
159
assert ( !kindAndFlags. isException)
162
160
#endif
@@ -241,4 +239,25 @@ public extension _JSFunctionProtocol {
241
239
new ( arguments: [ arg0. jsValue, arg1. jsValue, arg2. jsValue, arg3. jsValue, arg4. jsValue, arg5. jsValue, arg6. jsValue] )
242
240
}
243
241
}
244
- #endif
242
+
243
+ // C bit fields seem to not work with Embedded
244
+ // in "normal mode" this is defined as a C struct
245
+ private struct JavaScriptValueKindAndFlags {
246
+ let errorBit : UInt32 = 1 << 32
247
+ let kind : JavaScriptValueKind
248
+ let isException : Bool
249
+
250
+ init ( bitPattern: UInt32 ) {
251
+ self . kind = JavaScriptValueKind ( rawValue: bitPattern & ~ errorBit) !
252
+ self . isException = ( bitPattern & errorBit) != 0
253
+ }
254
+ }
255
+ #endif
256
+
257
+ private func valueKindAndFlagsFromBits( _ bits: UInt32 ) -> JavaScriptValueKindAndFlags {
258
+ #if hasFeature(Embedded)
259
+ JavaScriptValueKindAndFlags ( bitPattern: bits)
260
+ #else
261
+ unsafeBitCast ( resultBitPattern, to: JavaScriptValueKindAndFlags . self)
262
+ #endif
263
+ }
0 commit comments