Skip to content

Rename JSValueConvertible/Constructible/Codable #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ try test("Object Conversion") {
try expectEqual(jsArray1[1], .number(2))
try expectEqual(jsArray1[2], .number(3))

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

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

let dict1: [String: JSValueConvertible] = [
let dict1: [String: ConvertibleToJSValue] = [
"prop1": 1,
"prop2": "foo",
]
Expand Down
18 changes: 9 additions & 9 deletions Sources/JavaScriptKit/BasicObjects/JSPromise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ executed.
If the actual `Promise` object in JavaScript environment lives longer than this `JSPromise`, it may
attempt to call a deallocated `JSClosure`.
*/
public final class JSPromise<Success, Failure>: JSValueConvertible, JSValueConstructible {
public final class JSPromise<Success, Failure>: ConvertibleToJSValue, ConstructibleFromJSValue {
/// The underlying JavaScript `Promise` object.
public let jsObject: JSObject

Expand Down Expand Up @@ -88,7 +88,7 @@ extension JSPromise where Success == (), Failure == Never {
}
}

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

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

extension JSPromise where Success: JSValueConstructible {
extension JSPromise where Success: ConstructibleFromJSValue {
/** Schedules the `success` closure to be invoked on sucessful completion of `self`.
*/
public func then(
Expand All @@ -160,7 +160,7 @@ extension JSPromise where Success: JSValueConstructible {
closure invoked on sucessful completion of `self`. The returned promise will have a new
`Success` type equal to the return type of `success`.
*/
public func then<ResultType: JSValueConvertible>(
public func then<ResultType: ConvertibleToJSValue>(
success: @escaping (Success) -> ResultType,
file: StaticString = #file,
line: Int = #line
Expand All @@ -179,7 +179,7 @@ extension JSPromise where Success: JSValueConstructible {
closure invoked on sucessful completion of `self`. The returned promise will have a new type
equal to the return type of `success`.
*/
public func then<ResultSuccess: JSValueConvertible, ResultFailure: JSValueConstructible>(
public func then<ResultSuccess: ConvertibleToJSValue, ResultFailure: ConstructibleFromJSValue>(
success: @escaping (Success) -> JSPromise<ResultSuccess, ResultFailure>,
file: StaticString = #file,
line: Int = #line
Expand All @@ -195,12 +195,12 @@ extension JSPromise where Success: JSValueConstructible {
}
}

extension JSPromise where Failure: JSValueConstructible {
extension JSPromise where Failure: ConstructibleFromJSValue {
/** Returns a new promise created from chaining the current `self` promise with the `failure`
closure invoked on rejected completion of `self`. The returned promise will have a new `Success`
type equal to the return type of the callback, while the `Failure` type becomes `Never`.
*/
public func `catch`<ResultSuccess: JSValueConvertible>(
public func `catch`<ResultSuccess: ConvertibleToJSValue>(
failure: @escaping (Failure) -> ResultSuccess,
file: StaticString = #file,
line: Int = #line
Expand Down Expand Up @@ -236,7 +236,7 @@ extension JSPromise where Failure: JSValueConstructible {
closure invoked on rejected completion of `self`. The returned promise will have a new type
equal to the return type of `success`.
*/
public func `catch`<ResultSuccess: JSValueConvertible, ResultFailure: JSValueConstructible>(
public func `catch`<ResultSuccess: ConvertibleToJSValue, ResultFailure: ConstructibleFromJSValue>(
failure: @escaping (Failure) -> JSPromise<ResultSuccess, ResultFailure>,
file: StaticString = #file,
line: Int = #line
Expand Down
2 changes: 1 addition & 1 deletion Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import _CJavaScriptKit

/// A protocol that allows a Swift numeric type to be mapped to the JavaScript TypedArray that holds integers of its type
public protocol TypedArrayElement: JSValueConvertible, JSValueConstructible {
public protocol TypedArrayElement: ConvertibleToJSValue, ConstructibleFromJSValue {
/// The constructor function for the TypedArray class for this particular kind of number
static var typedArrayClass: JSFunction { get }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Types conforming to this protocol can be constructed from `JSValue`.
public protocol JSValueConstructible {
public protocol ConstructibleFromJSValue {
/// Construct an instance of `Self`, if possible, from the given `JSValue`.
/// Return `nil` if the value is not compatible with the conforming Swift type.
///
Expand All @@ -8,91 +8,91 @@ public protocol JSValueConstructible {
static func construct(from value: JSValue) -> Self?
}

extension Bool: JSValueConstructible {
extension Bool: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Bool? {
value.boolean
}
}

extension String: JSValueConstructible {
extension String: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> String? {
value.string
}
}

extension Double: JSValueConstructible {
extension Double: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Double? {
return value.number
}
}

extension Float: JSValueConstructible {
extension Float: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Float? {
return value.number.map(Float.init)
}
}

extension Int: JSValueConstructible {
extension Int: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension Int8: JSValueConstructible {
extension Int8: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension Int16: JSValueConstructible {
extension Int16: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension Int32: JSValueConstructible {
extension Int32: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension Int64: JSValueConstructible {
extension Int64: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension UInt: JSValueConstructible {
extension UInt: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension UInt8: JSValueConstructible {
extension UInt8: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension UInt16: JSValueConstructible {
extension UInt16: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension UInt32: JSValueConstructible {
extension UInt32: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension UInt64: JSValueConstructible {
extension UInt64: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
}

extension JSString: JSValueConstructible {
extension JSString: ConstructibleFromJSValue {
public static func construct(from value: JSValue) -> JSString? {
value.jsString
}
Expand Down
Loading