-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathshims.swift
More file actions
84 lines (77 loc) · 2.46 KB
/
Copy pathshims.swift
File metadata and controls
84 lines (77 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#if os(Linux)
import CJavaScriptCore
#else
import JavaScriptCore
#endif
public func JSValueToStringCopy(
_ ctx: JSContextRef,
_ value: JSValueRef
) throws -> JSStringRef {
var exception: JSValueRef?
let result = JSValueToStringCopy(ctx, value, &exception)
if let exception = exception {
throw JSError(context: ctx, pointer: exception)
}
return result!
}
public func JSValueToNumber(
_ ctx: JSContextRef,
_ value: JSValueRef
) throws -> Double {
var exception: JSValueRef?
let result = JSValueToNumber(ctx, value, &exception)
if let exception = exception {
throw JSError(context: ctx, pointer: exception)
}
return result
}
@discardableResult
public func JSEvaluateScript(
_ ctx: JSContextRef!,
_ script: JSStringRef!,
_ thisObject: JSObjectRef!,
_ sourceURL: JSStringRef!,
_ startingLineNumber: Int32
) throws -> JSValueRef {
var exception: JSValueRef?
let result = JSEvaluateScript(
ctx, script, thisObject, sourceURL, startingLineNumber, &exception)
if let exception = exception {
// FIXME: Exited with signal code 11
throw JSError(context: ctx, pointer: exception)
}
return result!
}
public struct JSPropertyAttributes: OptionSet, Sendable {
public let rawValue: UInt32
public init(rawValue: UInt32) {
self.rawValue = rawValue
}
/// Specifies that a property has no special attributes.
static let none = JSPropertyAttributes(
rawValue: UInt32(kJSPropertyAttributeNone))
/// Specifies that a property is read-only.
static let readOnly = JSPropertyAttributes(
rawValue: UInt32(kJSPropertyAttributeNone))
/// Specifies that a property should not be enumerated by
/// JSPropertyEnumerators and JavaScript for...in loops.
static let dontEnum = JSPropertyAttributes(
rawValue: UInt32(kJSPropertyAttributeNone))
/// Specifies that the delete operation should fail on a property.
static let dontDelete = JSPropertyAttributes(
rawValue: UInt32(kJSPropertyAttributeNone))
}
public func JSObjectSetProperty(
_ ctx: JSContextRef!,
_ object: JSObjectRef!,
_ propertyName: JSStringRef!,
_ value: JSValueRef!,
_ attributes: JSPropertyAttributes
) throws {
var exception: JSValueRef?
JSObjectSetProperty(
ctx, object, propertyName, value, attributes.rawValue, &exception)
if let exception = exception {
throw JSError(context: ctx, pointer: exception)
}
}