Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added discardableresult#269

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Amzd wants to merge1 commit intoswiftwasm:main
base:main
Choose a base branch
Loading
fromAmzd:amzd-discardableresult-pr
Open
Show file tree
Hide file tree
Changes fromall 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
23 changes: 18 additions & 5 deletionsSources/JavaScriptKit/FundamentalObjects/JSObject.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,9 +35,9 @@ public class JSObject: Equatable {
/// - Parameter name: The name of this object's member to access.
/// - Returns: The `name` member method binding this object as `this` context.
@_disfavoredOverload
public subscript(_ name: String) ->((ConvertibleToJSValue...) -> JSValue)? {
public subscript(_ name: String) ->DiscardableResultClosure? {
guard let function = self[name].function else { return nil }
return{ (arguments: ConvertibleToJSValue...) in
returnDiscardableResultClosure {arguments in
function(this: self, arguments: arguments)
}
}
Expand All@@ -53,17 +53,17 @@ public class JSObject: Equatable {
/// - Parameter name: The name of this object's member to access.
/// - Returns: The `name` member method binding this object as `this` context.
@_disfavoredOverload
public subscript(_ name: JSString) ->((ConvertibleToJSValue...) -> JSValue)? {
public subscript(_ name: JSString) ->DiscardableResultClosure? {
guard let function = self[name].function else { return nil }
return{ (arguments: ConvertibleToJSValue...) in
returnDiscardableResultClosure {arguments in
function(this: self, arguments: arguments)
}
}

/// A convenience method of `subscript(_ name: String) -> ((ConvertibleToJSValue...) -> JSValue)?`
/// to access the member through Dynamic Member Lookup.
@_disfavoredOverload
public subscript(dynamicMember name: String) ->((ConvertibleToJSValue...) -> JSValue)? {
public subscript(dynamicMember name: String) ->DiscardableResultClosure? {
self[name]
}
#endif
Expand DownExpand Up@@ -232,6 +232,19 @@ public class JSThrowingObject {
#endif


#if !hasFeature(Embedded)
/// A swift closure wrapper that can be called as function.
/// This prevents the warnings for unused results through `@discardableResult` which means you no longer need `_ =` everywhere.
public struct DiscardableResultClosure {
var closure: ([ConvertibleToJSValue]) -> JSValue

@discardableResult
public func callAsFunction(_ args: ConvertibleToJSValue...) -> JSValue {
return self.closure(args)
}
}
#endif

#if hasFeature(Embedded)
// NOTE: once embedded supports variadic generics, we can remove these overloads
public extension JSObject {
Expand Down
3 changes: 2 additions & 1 deletionSources/JavaScriptKit/JSValue.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -104,7 +104,8 @@ public extension JSValue {
#if !hasFeature(Embedded)
/// An unsafe convenience method of `JSObject.subscript(_ name: String) -> ((ConvertibleToJSValue...) -> JSValue)?`
/// - Precondition: `self` must be a JavaScript Object and specified member should be a callable object.
subscript(dynamicMember name: String) -> ((ConvertibleToJSValue...) -> JSValue) {
@_disfavoredOverload
subscript(dynamicMember name: String) -> DiscardableResultClosure {
object![dynamicMember: name]!
}
#endif
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp