GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fixed C bit field thing · rarestype/JavaScriptKit@11897e1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Sources
    • JavaScriptKit/FundamentalObjects
      • JSFunction.swift
    • _CJavaScriptKit/include
      • _CJavaScriptKit.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift‎

Copy file name to clipboardExpand all lines: Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift
+24-5Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}
Collapse file

‎Sources/_CJavaScriptKit/include/_CJavaScriptKit.h‎

Copy file name to clipboardExpand all lines: Sources/_CJavaScriptKit/include/_CJavaScriptKit.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ typedef enum __attribute__((enum_extensibility(closed))) {
2929
JavaScriptValueKindBigInt = 8,
3030
} JavaScriptValueKind;
3131

32+
#if __Embedded
33+
// something about the bit field widths is not working with embedded
34+
typedef unsigned short JavaScriptValueKindAndFlags;
35+
#else
3236
typedef struct {
3337
JavaScriptValueKind kind: 31;
3438
bool isException: 1;
3539
} JavaScriptValueKindAndFlags;
40+
#endif
3641

3742
typedef unsigned JavaScriptPayload1;
3843
typedef double JavaScriptPayload2;

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.