Skip to content

Commit 9aba8f3

Browse files
committed
Fix code style
1 parent 9ad57c9 commit 9aba8f3

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

Sources/SJavaScriptCore/JSContext+closure.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#if os(Linux)
32
import CJavaScriptCore
43
#else
@@ -12,16 +11,16 @@ private var functions: [OpaquePointer: ([JSValue]) throws -> Value] = [:]
1211
extension JSContext {
1312
public func createFunction(
1413
name: String,
15-
_ body: @escaping ([JSValue]) throws -> Value) throws
16-
{
14+
_ body: @escaping ([JSValue]) throws -> Value
15+
) throws {
1716
let function = try createFunction(name: name, callback: wrapper)
1817
functions[function] = body
1918
}
2019

2120
public func createFunction(
2221
name: String,
23-
_ body: @escaping ([JSValue]) throws -> Void) throws
24-
{
22+
_ body: @escaping ([JSValue]) throws -> Void
23+
) throws {
2524
let function = try createFunction(name: name, callback: wrapper)
2625
functions[function] = { arguments in
2726
try body(arguments)
@@ -33,17 +32,17 @@ extension JSContext {
3332
extension JSContext {
3433
public func createFunction(
3534
name: String,
36-
_ body: @escaping () throws -> Value) throws
37-
{
35+
_ body: @escaping () throws -> Value
36+
) throws {
3837
return try createFunction(name: name) { _ in
3938
return try body()
4039
}
4140
}
4241

4342
public func createFunction(
4443
name: String,
45-
_ body: @escaping () throws -> Void) throws
46-
{
44+
_ body: @escaping () throws -> Void
45+
) throws {
4746
try createFunction(name: name) { _ in
4847
try body()
4948
}
@@ -56,8 +55,8 @@ func wrapper(
5655
thisObject: JSObjectRef!,
5756
argumentCount: Int,
5857
arguments: UnsafePointer<JSValueRef?>?,
59-
exception: UnsafeMutablePointer<JSValueRef?>?) -> JSValueRef?
60-
{
58+
exception: UnsafeMutablePointer<JSValueRef?>?
59+
) -> JSValueRef? {
6160
guard let body = functions[function] else {
6261
if let exception = exception {
6362
let error = "swift error: unregistered function"

Sources/SJavaScriptCore/JSContext.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#if os(Linux)
32
import CJavaScriptCore
43
#else
@@ -8,7 +7,7 @@ import JavaScriptCore
87
public class JSContext {
98
let group: JSContextGroupRef
109
let context: JSGlobalContextRef
11-
var exception: JSObjectRef? = nil
10+
var exception: JSObjectRef?
1211

1312
var global: JSObjectRef {
1413
return JSContextGetGlobalObject(context)!

Sources/SJavaScriptCore/JSError.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#if os(Linux)
32
import CJavaScriptCore
43
#else

Sources/SJavaScriptCore/JSValue.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#if os(Linux)
32
import CJavaScriptCore
43
#else
@@ -79,7 +78,7 @@ extension JSValue {
7978
let property = JSStringCreateWithCharacters(bytes, bytes.count)
8079
defer { JSStringRelease(property) }
8180

82-
var exception: JSValueRef? = nil
81+
var exception: JSValueRef?
8382
let result = JSObjectGetProperty(context, pointer, property, &exception)
8483

8584
if exception != nil {
@@ -89,7 +88,6 @@ extension JSValue {
8988
}
9089
}
9190

92-
9391
extension JSValue {
9492
public var isNull: Bool {
9593
return JSValueIsNull(context, pointer)

Sources/SJavaScriptCore/shims.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#if os(Linux)
32
import CJavaScriptCore
43
#else
@@ -9,7 +8,7 @@ public func JSValueToStringCopy(
98
_ ctx: JSContextRef,
109
_ value: JSValueRef
1110
) throws -> JSStringRef {
12-
var exception: JSValueRef? = nil
11+
var exception: JSValueRef?
1312
let result = JSValueToStringCopy(ctx, value, &exception)
1413
if let exception = exception {
1514
throw JSError(context: ctx, pointer: exception)
@@ -21,7 +20,7 @@ public func JSValueToNumber(
2120
_ ctx: JSContextRef,
2221
_ value: JSValueRef
2322
) throws -> Double {
24-
var exception: JSValueRef? = nil
23+
var exception: JSValueRef?
2524
let result = JSValueToNumber(ctx, value, &exception)
2625
if let exception = exception {
2726
throw JSError(context: ctx, pointer: exception)
@@ -37,7 +36,7 @@ public func JSEvaluateScript(
3736
_ sourceURL: JSStringRef!,
3837
_ startingLineNumber: Int32
3938
) throws -> JSValueRef {
40-
var exception: JSValueRef? = nil
39+
var exception: JSValueRef?
4140
let result = JSEvaluateScript(
4241
ctx, script, thisObject, sourceURL, startingLineNumber, &exception)
4342
if let exception = exception {
@@ -55,13 +54,18 @@ public struct JSPropertyAttributes: OptionSet {
5554
}
5655

5756
/// Specifies that a property has no special attributes.
58-
static let none = JSPropertyAttributes(rawValue: UInt32(kJSPropertyAttributeNone))
57+
static let none = JSPropertyAttributes(
58+
rawValue: UInt32(kJSPropertyAttributeNone))
5959
/// Specifies that a property is read-only.
60-
static let readOnly = JSPropertyAttributes(rawValue: UInt32(kJSPropertyAttributeNone))
61-
/// Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
62-
static let dontEnum = JSPropertyAttributes(rawValue: UInt32(kJSPropertyAttributeNone))
60+
static let readOnly = JSPropertyAttributes(
61+
rawValue: UInt32(kJSPropertyAttributeNone))
62+
/// Specifies that a property should not be enumerated by
63+
/// JSPropertyEnumerators and JavaScript for...in loops.
64+
static let dontEnum = JSPropertyAttributes(
65+
rawValue: UInt32(kJSPropertyAttributeNone))
6366
/// Specifies that the delete operation should fail on a property.
64-
static let dontDelete = JSPropertyAttributes(rawValue: UInt32(kJSPropertyAttributeNone))
67+
static let dontDelete = JSPropertyAttributes(
68+
rawValue: UInt32(kJSPropertyAttributeNone))
6569
}
6670

6771
public func JSObjectSetProperty(
@@ -71,7 +75,7 @@ public func JSObjectSetProperty(
7175
_ value: JSValueRef!,
7276
_ attributes: JSPropertyAttributes
7377
) throws {
74-
var exception: JSValueRef? = nil
78+
var exception: JSValueRef?
7579
JSObjectSetProperty(
7680
ctx, object, propertyName, value, attributes.rawValue, &exception)
7781
if let exception = exception {

Tests/SJavaScriptCore/JavaScript/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test("persistent context") {
8888
try context.evaluate("result = 'success'")
8989
expect(try context.evaluate("result").toString() == "success")
9090

91-
try context.createFunction(name: "test") { (arguments) -> Value in
91+
try context.createFunction(name: "test") { (_) -> Value in
9292
return .string("test ok")
9393
}
9494

0 commit comments

Comments
 (0)