@@ -137,10 +137,8 @@ public class JSFunction: JSObject, _JSFunctionProtocol {
137137 id, argv, Int32 ( argc) ,
138138 & payload1, & payload2
139139 )
140- let kindAndFlags = unsafeBitCast ( resultBitPattern, to: JavaScriptValueKindAndFlags . self)
141- #if !hasFeature(Embedded)
140+ let kindAndFlags = valueKindAndFlagsFromBits ( resultBitPattern)
142141 assert ( !kindAndFlags. isException)
143- #endif
144142 let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
145143 return result
146144 }
@@ -156,7 +154,7 @@ public class JSFunction: JSObject, _JSFunctionProtocol {
156154 id, argv, Int32 ( argc) ,
157155 & payload1, & payload2
158156 )
159- let kindAndFlags = unsafeBitCast ( resultBitPattern, to : JavaScriptValueKindAndFlags . self )
157+ let kindAndFlags = valueKindAndFlagsFromBits ( resultBitPattern)
160158 #if !hasFeature(Embedded)
161159 assert ( !kindAndFlags. isException)
162160 #endif
@@ -241,4 +239,25 @@ public extension _JSFunctionProtocol {
241239 new ( arguments: [ arg0. jsValue, arg1. jsValue, arg2. jsValue, arg3. jsValue, arg4. jsValue, arg5. jsValue, arg6. jsValue] )
242240 }
243241}
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