Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
args → arguments
  • Loading branch information
j-f1 committed Aug 10, 2020
commit f655aabae96fce7c931370fa27c89d88ee2f8bcb
20 changes: 10 additions & 10 deletions Sources/JavaScriptKit/JSFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import _CJavaScriptKit

public class JSFunctionRef: JSObjectRef {
@discardableResult
func callAsFunction(this: JSObjectRef? = nil, args: [JSValueConvertible]) -> JSValue {
let result = args.withRawJSValues { rawValues in
func callAsFunction(this: JSObjectRef? = nil, arguments: [JSValueConvertible]) -> JSValue {
let result = arguments.withRawJSValues { rawValues in
rawValues.withUnsafeBufferPointer { bufferPointer -> RawJSValue in
let argv = bufferPointer.baseAddress
let argc = bufferPointer.count
Expand All @@ -25,20 +25,20 @@ public class JSFunctionRef: JSObjectRef {
}

@discardableResult
public func callAsFunction(this: JSObjectRef? = nil, _ args: JSValueConvertible...) -> JSValue {
self(this: this, args: args)
public func callAsFunction(this: JSObjectRef? = nil, _ arguments: JSValueConvertible...) -> JSValue {
self(this: this, arguments: arguments)
}

public func new(_ args: JSValueConvertible...) -> JSObjectRef {
new(args: args)
public func new(_ arguments: JSValueConvertible...) -> JSObjectRef {
new(arguments: arguments)
}

// Guaranteed to return an object because either:
// a) the constructor explicitly returns an object, or
// b) the constructor returns nothing, which causes JS to return the `this` value, or
// c) the constructor returns undefined, null or a non-object, in which case JS also returns `this`.
public func new(args: [JSValueConvertible]) -> JSObjectRef {
args.withRawJSValues { rawValues in
public func new(arguments: [JSValueConvertible]) -> JSObjectRef {
arguments.withRawJSValues { rawValues in
rawValues.withUnsafeBufferPointer { bufferPointer in
let argv = bufferPointer.baseAddress
let argc = bufferPointer.count
Expand Down Expand Up @@ -105,10 +105,10 @@ public func _call_host_function(
guard let hostFunc = JSClosure.sharedFunctions[hostFuncRef] else {
fatalError("The function was already released")
}
let args = UnsafeBufferPointer(start: argv, count: Int(argc)).map {
let arguments = UnsafeBufferPointer(start: argv, count: Int(argc)).map {
$0.jsValue()
}
let result = hostFunc(args)
let result = hostFunc(arguments)
let callbackFuncRef = JSFunctionRef(id: callbackFuncRef)
_ = callbackFuncRef(result)
}
2 changes: 1 addition & 1 deletion Sources/JavaScriptKit/JSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class JSObjectRef: Equatable {
public subscript(dynamicMember name: String) -> ((JSValueConvertible...) -> JSValue)? {
guard let function = self[name].function else { return nil }
return { (arguments: JSValueConvertible...) in
function(this: self, args: arguments)
function(this: self, arguments: arguments)
}
}

Expand Down