-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: okay actually add all updates to commit lol
- Loading branch information
1 parent
d2e1998
commit db684fc
Showing
53 changed files
with
2,608 additions
and
2,813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ struct ContentCore: _Feature { | |
LoggerClient() | ||
Tagged() | ||
ComposableArchitecture() | ||
Styling() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ let package = Package { | |
Search() | ||
Settings() | ||
VideoPlayer() | ||
ContentCore() | ||
|
||
MochiApp() | ||
} testTargets: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// File.swift | ||
// JSContext+.swift | ||
// | ||
// | ||
// Created by ErrorErrorError on 11/17/23. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,74 @@ | ||
// | ||
// File.swift | ||
// JSValue+.swift | ||
// | ||
// | ||
// Created by ErrorErrorError on 11/17/23. | ||
// | ||
// | ||
|
||
import Foundation | ||
import JavaScriptCore | ||
|
||
extension JSValue { | ||
subscript(_ key: String) -> JSValue? { | ||
guard !isOptional else { | ||
return nil | ||
} | ||
guard let value = forProperty(key) else { | ||
return nil | ||
} | ||
return !value.isOptional ? value : nil | ||
} | ||
|
||
var isOptional: Bool { isNull || isUndefined } | ||
|
||
@discardableResult | ||
func value(_ function: String) async throws -> JSValue { | ||
try await withCheckedThrowingContinuation { continuation in | ||
let onFufilled: @convention(block) (JSValue) -> Void = { value in | ||
continuation.resume(returning: value) | ||
} | ||
|
||
let onRejected: @convention(block) (JSValue) -> Void = { value in | ||
continuation.resume(throwing: value.toError(function)) | ||
} | ||
|
||
self.invokeMethod( | ||
"then", | ||
withArguments: [ | ||
unsafeBitCast(onFufilled, to: JSValue.self), | ||
unsafeBitCast(onRejected, to: JSValue.self) | ||
] | ||
) | ||
} | ||
} | ||
|
||
func toError(_ functionName: String? = nil, stackTrace: Bool = true) -> JSValueError { .init(self, functionName) } | ||
} | ||
|
||
struct JSValueError: Error, LocalizedError, CustomStringConvertible { | ||
var functionName: String? | ||
var name: String? | ||
var errorDescription: String? | ||
var failureReason: String? | ||
var stackTrace: String? | ||
|
||
init(_ value: JSValue, _ functionName: String? = nil, stackTrace: Bool = true) { | ||
self.functionName = functionName | ||
self.name = value["name"]?.toString() | ||
self.errorDescription = value["message"]?.toString() | ||
self.failureReason = value["cause"]?.toString() | ||
if stackTrace { | ||
self.stackTrace = value["stack"]?.toString() | ||
} | ||
} | ||
|
||
// TODO: Allow stack trace | ||
var description: String { | ||
""" | ||
Instance\(functionName.flatMap { ".\($0)" } ?? "") => \ | ||
\(name ?? "Error"): \(errorDescription ?? "No Message") | ||
\(failureReason.flatMap { " \($0)" } ?? "\\") | ||
""" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 31 additions & 1 deletion
32
Sources/Clients/ModuleClient/JS+Bindings/JSContext+Console.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
// | ||
// File.swift | ||
// JSContext+Console.swift | ||
// | ||
// | ||
// Created by ErrorErrorError on 11/17/23. | ||
// | ||
// | ||
|
||
import Foundation | ||
import JavaScriptCore | ||
|
||
extension JSContext { | ||
func setConsoleBinding(_ logger: @escaping (MessageLog, String) -> Void) { | ||
exceptionHandler = { _, exception in | ||
guard let exception else { | ||
return | ||
} | ||
|
||
logger(.error, exception.toError().description) | ||
} | ||
|
||
let console = JSValue(newObjectIn: self) | ||
|
||
let logger = { (type: MessageLog) in { | ||
guard let arguments = JSContext.currentArguments()?.compactMap({ $0 as? JSValue }) else { | ||
return | ||
} | ||
|
||
let msg = arguments.compactMap { $0.toString() } | ||
.joined(separator: " ") | ||
|
||
logger(type, msg) | ||
} as @convention(block) () -> Void } | ||
|
||
MessageLog.allCases.forEach { console?.setObject(logger($0), forKeyedSubscript: $0.rawValue) } | ||
|
||
setObject(console, forKeyedSubscript: "console" as NSString) | ||
} | ||
} |
Oops, something went wrong.