Skip to content

Commit bbc49d3

Browse files
authored
Rename JSValueConvertible/Constructible/Codable
1 parent 2f460ba commit bbc49d3

File tree

11 files changed

+85
-76
lines changed

11 files changed

+85
-76
lines changed

IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ try test("Object Conversion") {
286286
try expectEqual(jsArray1[1], .number(2))
287287
try expectEqual(jsArray1[2], .number(3))
288288

289-
let array2: [JSValueConvertible] = [1, "str", false]
289+
let array2: [ConvertibleToJSValue] = [1, "str", false]
290290
let jsArray2 = array2.jsValue().object!
291291
try expectEqual(jsArray2.length, .number(3))
292292
try expectEqual(jsArray2[0], .number(1))
@@ -298,7 +298,7 @@ try test("Object Conversion") {
298298

299299
try expectEqual(jsArray2[4], .object(jsArray1))
300300

301-
let dict1: [String: JSValueConvertible] = [
301+
let dict1: [String: ConvertibleToJSValue] = [
302302
"prop1": 1,
303303
"prop2": "foo",
304304
]

Sources/JavaScriptKit/BasicObjects/JSPromise.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ executed.
1616
If the actual `Promise` object in JavaScript environment lives longer than this `JSPromise`, it may
1717
attempt to call a deallocated `JSClosure`.
1818
*/
19-
public final class JSPromise<Success, Failure>: JSValueConvertible, JSValueConstructible {
19+
public final class JSPromise<Success, Failure>: ConvertibleToJSValue, ConstructibleFromJSValue {
2020
/// The underlying JavaScript `Promise` object.
2121
public let jsObject: JSObject
2222

@@ -88,7 +88,7 @@ extension JSPromise where Success == (), Failure == Never {
8888
}
8989
}
9090

91-
extension JSPromise where Failure: JSValueConvertible {
91+
extension JSPromise where Failure: ConvertibleToJSValue {
9292
/** Creates a new `JSPromise` instance from a given `resolver` closure. `resolver` takes
9393
two closure that your code should call to either resolve or reject this `JSPromise` instance.
9494
*/
@@ -113,7 +113,7 @@ extension JSPromise where Failure: JSValueConvertible {
113113
}
114114
}
115115

116-
extension JSPromise where Success: JSValueConvertible, Failure: JSError {
116+
extension JSPromise where Success: ConvertibleToJSValue, Failure: JSError {
117117
/** Creates a new `JSPromise` instance from a given `resolver` closure. `resolver` takes
118118
a closure that your code should call to either resolve or reject this `JSPromise` instance.
119119
*/
@@ -138,7 +138,7 @@ extension JSPromise where Success: JSValueConvertible, Failure: JSError {
138138
}
139139
}
140140

141-
extension JSPromise where Success: JSValueConstructible {
141+
extension JSPromise where Success: ConstructibleFromJSValue {
142142
/** Schedules the `success` closure to be invoked on sucessful completion of `self`.
143143
*/
144144
public func then(
@@ -160,7 +160,7 @@ extension JSPromise where Success: JSValueConstructible {
160160
closure invoked on sucessful completion of `self`. The returned promise will have a new
161161
`Success` type equal to the return type of `success`.
162162
*/
163-
public func then<ResultType: JSValueConvertible>(
163+
public func then<ResultType: ConvertibleToJSValue>(
164164
success: @escaping (Success) -> ResultType,
165165
file: StaticString = #file,
166166
line: Int = #line
@@ -179,7 +179,7 @@ extension JSPromise where Success: JSValueConstructible {
179179
closure invoked on sucessful completion of `self`. The returned promise will have a new type
180180
equal to the return type of `success`.
181181
*/
182-
public func then<ResultSuccess: JSValueConvertible, ResultFailure: JSValueConstructible>(
182+
public func then<ResultSuccess: ConvertibleToJSValue, ResultFailure: ConstructibleFromJSValue>(
183183
success: @escaping (Success) -> JSPromise<ResultSuccess, ResultFailure>,
184184
file: StaticString = #file,
185185
line: Int = #line
@@ -195,12 +195,12 @@ extension JSPromise where Success: JSValueConstructible {
195195
}
196196
}
197197

198-
extension JSPromise where Failure: JSValueConstructible {
198+
extension JSPromise where Failure: ConstructibleFromJSValue {
199199
/** Returns a new promise created from chaining the current `self` promise with the `failure`
200200
closure invoked on rejected completion of `self`. The returned promise will have a new `Success`
201201
type equal to the return type of the callback, while the `Failure` type becomes `Never`.
202202
*/
203-
public func `catch`<ResultSuccess: JSValueConvertible>(
203+
public func `catch`<ResultSuccess: ConvertibleToJSValue>(
204204
failure: @escaping (Failure) -> ResultSuccess,
205205
file: StaticString = #file,
206206
line: Int = #line
@@ -236,7 +236,7 @@ extension JSPromise where Failure: JSValueConstructible {
236236
closure invoked on rejected completion of `self`. The returned promise will have a new type
237237
equal to the return type of `success`.
238238
*/
239-
public func `catch`<ResultSuccess: JSValueConvertible, ResultFailure: JSValueConstructible>(
239+
public func `catch`<ResultSuccess: ConvertibleToJSValue, ResultFailure: ConstructibleFromJSValue>(
240240
failure: @escaping (Failure) -> JSPromise<ResultSuccess, ResultFailure>,
241241
file: StaticString = #file,
242242
line: Int = #line

Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import _CJavaScriptKit
66

77
/// A protocol that allows a Swift numeric type to be mapped to the JavaScript TypedArray that holds integers of its type
8-
public protocol TypedArrayElement: JSValueConvertible, JSValueConstructible {
8+
public protocol TypedArrayElement: ConvertibleToJSValue, ConstructibleFromJSValue {
99
/// The constructor function for the TypedArray class for this particular kind of number
1010
static var typedArrayClass: JSFunction { get }
1111
}

Sources/JavaScriptKit/JSValueConstructible.swift renamed to Sources/JavaScriptKit/ConstructibleFromJSValue.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Types conforming to this protocol can be constructed from `JSValue`.
2-
public protocol JSValueConstructible {
2+
public protocol ConstructibleFromJSValue {
33
/// Construct an instance of `Self`, if possible, from the given `JSValue`.
44
/// Return `nil` if the value is not compatible with the conforming Swift type.
55
///
@@ -8,91 +8,91 @@ public protocol JSValueConstructible {
88
static func construct(from value: JSValue) -> Self?
99
}
1010

11-
extension Bool: JSValueConstructible {
11+
extension Bool: ConstructibleFromJSValue {
1212
public static func construct(from value: JSValue) -> Bool? {
1313
value.boolean
1414
}
1515
}
1616

17-
extension String: JSValueConstructible {
17+
extension String: ConstructibleFromJSValue {
1818
public static func construct(from value: JSValue) -> String? {
1919
value.string
2020
}
2121
}
2222

23-
extension Double: JSValueConstructible {
23+
extension Double: ConstructibleFromJSValue {
2424
public static func construct(from value: JSValue) -> Double? {
2525
return value.number
2626
}
2727
}
2828

29-
extension Float: JSValueConstructible {
29+
extension Float: ConstructibleFromJSValue {
3030
public static func construct(from value: JSValue) -> Float? {
3131
return value.number.map(Float.init)
3232
}
3333
}
3434

35-
extension Int: JSValueConstructible {
35+
extension Int: ConstructibleFromJSValue {
3636
public static func construct(from value: JSValue) -> Self? {
3737
value.number.map(Self.init)
3838
}
3939
}
4040

41-
extension Int8: JSValueConstructible {
41+
extension Int8: ConstructibleFromJSValue {
4242
public static func construct(from value: JSValue) -> Self? {
4343
value.number.map(Self.init)
4444
}
4545
}
4646

47-
extension Int16: JSValueConstructible {
47+
extension Int16: ConstructibleFromJSValue {
4848
public static func construct(from value: JSValue) -> Self? {
4949
value.number.map(Self.init)
5050
}
5151
}
5252

53-
extension Int32: JSValueConstructible {
53+
extension Int32: ConstructibleFromJSValue {
5454
public static func construct(from value: JSValue) -> Self? {
5555
value.number.map(Self.init)
5656
}
5757
}
5858

59-
extension Int64: JSValueConstructible {
59+
extension Int64: ConstructibleFromJSValue {
6060
public static func construct(from value: JSValue) -> Self? {
6161
value.number.map(Self.init)
6262
}
6363
}
6464

65-
extension UInt: JSValueConstructible {
65+
extension UInt: ConstructibleFromJSValue {
6666
public static func construct(from value: JSValue) -> Self? {
6767
value.number.map(Self.init)
6868
}
6969
}
7070

71-
extension UInt8: JSValueConstructible {
71+
extension UInt8: ConstructibleFromJSValue {
7272
public static func construct(from value: JSValue) -> Self? {
7373
value.number.map(Self.init)
7474
}
7575
}
7676

77-
extension UInt16: JSValueConstructible {
77+
extension UInt16: ConstructibleFromJSValue {
7878
public static func construct(from value: JSValue) -> Self? {
7979
value.number.map(Self.init)
8080
}
8181
}
8282

83-
extension UInt32: JSValueConstructible {
83+
extension UInt32: ConstructibleFromJSValue {
8484
public static func construct(from value: JSValue) -> Self? {
8585
value.number.map(Self.init)
8686
}
8787
}
8888

89-
extension UInt64: JSValueConstructible {
89+
extension UInt64: ConstructibleFromJSValue {
9090
public static func construct(from value: JSValue) -> Self? {
9191
value.number.map(Self.init)
9292
}
9393
}
9494

95-
extension JSString: JSValueConstructible {
95+
extension JSString: ConstructibleFromJSValue {
9696
public static func construct(from value: JSValue) -> JSString? {
9797
value.jsString
9898
}

0 commit comments

Comments
 (0)