Skip to content

Resolve warnings #266

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 15, 2024
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 Sources/JavaScriptBigIntSupport/Int64+I64.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import JavaScriptKit

extension UInt64: ConvertibleToJSValue, TypedArrayElement {
extension UInt64: JavaScriptKit.ConvertibleToJSValue, JavaScriptKit.TypedArrayElement {
public static var typedArrayClass = JSObject.global.BigUint64Array.function!

public var jsValue: JSValue { .bigInt(JSBigInt(unsigned: self)) }
}

extension Int64: ConvertibleToJSValue, TypedArrayElement {
extension Int64: JavaScriptKit.ConvertibleToJSValue, JavaScriptKit.TypedArrayElement {
public static var typedArrayClass = JSObject.global.BigInt64Array.function!

public var jsValue: JSValue { .bigInt(JSBigInt(self)) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/JavaScriptBigIntSupport/JSBigInt+I64.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _CJavaScriptBigIntSupport
@_spi(JSObject_id) import JavaScriptKit

extension JSBigInt: JSBigIntExtended {
extension JSBigInt: JavaScriptKit.JSBigIntExtended {
public var int64Value: Int64 {
swjs_bigint_to_i64(id, true)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/JavaScriptKit/BasicObjects/JSTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public final class JSTimer {
case .oneshot(let closure):
closure.release()
case .repeating(let closure):
#if JAVASCRIPTKIT_WITHOUT_WEAKREFS
closure.release()
#else
break // no-op
#endif
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
/// - Parameter array: The array that will be copied to create a new instance of TypedArray
public convenience init(_ array: [Element]) {
let jsArrayRef = array.withUnsafeBufferPointer { ptr in
swjs_create_typed_array(Self.constructor!.id, ptr.baseAddress!, Int32(array.count))
swjs_create_typed_array(Self.constructor!.id, ptr.baseAddress, Int32(array.count))
}
self.init(unsafelyWrapping: JSObject(id: jsArrayRef))
}
Expand Down Expand Up @@ -187,4 +187,4 @@ extension Float32: TypedArrayElement {
extension Float64: TypedArrayElement {
public static var typedArrayClass = JSObject.global.Float64Array.function!
}
#endif
#endif
9 changes: 2 additions & 7 deletions Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import _CJavaScriptKit
/// alert("Hello, world")
/// ```
///
public class JSFunction: JSObject, _JSFunctionProtocol {
public class JSFunction: JSObject {
#if !hasFeature(Embedded)
/// Call this function with given `arguments` and binding given `this` as context.
/// - Parameters:
Expand Down Expand Up @@ -163,14 +163,9 @@ public class JSFunction: JSObject, _JSFunctionProtocol {
}
}

/// Internal protocol to support generic arguments for `JSFunction`.
///
/// In Swift Embedded, non-final classes cannot have generic methods.
public protocol _JSFunctionProtocol: JSFunction {}

#if hasFeature(Embedded)
// NOTE: once embedded supports variadic generics, we can remove these overloads
public extension _JSFunctionProtocol {
public extension JSFunction {

@discardableResult
func callAsFunction(this: JSObject) -> JSValue {
Expand Down
52 changes: 26 additions & 26 deletions Sources/_CJavaScriptKit/include/_CJavaScriptKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ IMPORT_JS_FUNCTION(swjs_set_prop, void, (const JavaScriptObjectRef _this,
/// @return A `JavaScriptValueKind` bits represented as 32bit integer for the returned value.
IMPORT_JS_FUNCTION(swjs_get_prop, uint32_t, (const JavaScriptObjectRef _this,
const JavaScriptObjectRef prop,
JavaScriptPayload1 *payload1,
JavaScriptPayload2 *payload2))
JavaScriptPayload1 * _Nonnull payload1,
JavaScriptPayload2 * _Nonnull payload2))

/// Sets a value of `_this` JavaScript object.
///
Expand All @@ -131,29 +131,29 @@ IMPORT_JS_FUNCTION(swjs_set_subscript, void, (const JavaScriptObjectRef _this,
/// get a value of `_this` JavaScript object.
IMPORT_JS_FUNCTION(swjs_get_subscript, uint32_t, (const JavaScriptObjectRef _this,
const int index,
JavaScriptPayload1 *payload1,
JavaScriptPayload2 *payload2))
JavaScriptPayload1 * _Nonnull payload1,
JavaScriptPayload2 * _Nonnull payload2))

/// Encodes the `str_obj` to bytes sequence and returns the length of bytes.
///
/// @param str_obj A JavaScript string object ref to encode.
/// @param bytes_result A result pointer of bytes sequence representation in JavaScript.
/// This value will be used to load the actual bytes using `_load_string`.
/// @result The length of bytes sequence. This value will be used to allocate Swift side string buffer to load the actual bytes.
IMPORT_JS_FUNCTION(swjs_encode_string, int, (const JavaScriptObjectRef str_obj, JavaScriptObjectRef *bytes_result))
IMPORT_JS_FUNCTION(swjs_encode_string, int, (const JavaScriptObjectRef str_obj, JavaScriptObjectRef * _Nonnull bytes_result))

/// Decodes the given bytes sequence into JavaScript string object.
///
/// @param bytes_ptr A `uint8_t` byte sequence to decode.
/// @param length The length of `bytes_ptr`.
/// @result The decoded JavaScript string object.
IMPORT_JS_FUNCTION(swjs_decode_string, JavaScriptObjectRef, (const unsigned char *bytes_ptr, const int length))
IMPORT_JS_FUNCTION(swjs_decode_string, JavaScriptObjectRef, (const unsigned char * _Nonnull bytes_ptr, const int length))

/// Loads the actual bytes sequence of `bytes` into `buffer` which is a Swift side memory address.
///
/// @param bytes A bytes sequence representation in JavaScript to load. This value should be derived from `_encode_string`.
/// @param buffer A Swift side string buffer to load the bytes.
IMPORT_JS_FUNCTION(swjs_load_string, void, (const JavaScriptObjectRef bytes, unsigned char *buffer))
IMPORT_JS_FUNCTION(swjs_load_string, void, (const JavaScriptObjectRef bytes, unsigned char * _Nonnull buffer))

/// Converts the provided Int64 or UInt64 to a BigInt in slow path by splitting 64bit integer to two 32bit integers
/// to avoid depending on [JS-BigInt-integration](https://github.com/WebAssembly/JS-BigInt-integration) feature
Expand All @@ -172,10 +172,10 @@ IMPORT_JS_FUNCTION(swjs_i64_to_bigint_slow, JavaScriptObjectRef, (unsigned int l
/// @param result_payload2 A result pointer of second payload of JavaScript value of returned result or thrown exception.
/// @return A `JavaScriptValueKindAndFlags` bits represented as 32bit integer for the returned value.
IMPORT_JS_FUNCTION(swjs_call_function, uint32_t, (const JavaScriptObjectRef ref,
const RawJSValue *argv,
const RawJSValue * _Nullable argv,
const int argc,
JavaScriptPayload1 *result_payload1,
JavaScriptPayload2 *result_payload2))
JavaScriptPayload1 * _Nonnull result_payload1,
JavaScriptPayload2 * _Nonnull result_payload2))

/// Calls JavaScript function with given arguments list without capturing any exception
///
Expand All @@ -186,10 +186,10 @@ IMPORT_JS_FUNCTION(swjs_call_function, uint32_t, (const JavaScriptObjectRef ref,
/// @param result_payload2 A result pointer of second payload of JavaScript value of returned result or thrown exception.
/// @return A `JavaScriptValueKindAndFlags` bits represented as 32bit integer for the returned value.
IMPORT_JS_FUNCTION(swjs_call_function_no_catch, uint32_t, (const JavaScriptObjectRef ref,
const RawJSValue *argv,
const RawJSValue * _Nullable argv,
const int argc,
JavaScriptPayload1 *result_payload1,
JavaScriptPayload2 *result_payload2))
JavaScriptPayload1 * _Nonnull result_payload1,
JavaScriptPayload2 * _Nonnull result_payload2))

/// Calls JavaScript function with given arguments list and given `_this`.
///
Expand All @@ -202,10 +202,10 @@ IMPORT_JS_FUNCTION(swjs_call_function_no_catch, uint32_t, (const JavaScriptObjec
/// @return A `JavaScriptValueKindAndFlags` bits represented as 32bit integer for the returned value.
IMPORT_JS_FUNCTION(swjs_call_function_with_this, uint32_t, (const JavaScriptObjectRef _this,
const JavaScriptObjectRef func_ref,
const RawJSValue *argv,
const RawJSValue * _Nullable argv,
const int argc,
JavaScriptPayload1 *result_payload1,
JavaScriptPayload2 *result_payload2))
JavaScriptPayload1 * _Nonnull result_payload1,
JavaScriptPayload2 * _Nonnull result_payload2))

/// Calls JavaScript function with given arguments list and given `_this` without capturing any exception.
///
Expand All @@ -218,10 +218,10 @@ IMPORT_JS_FUNCTION(swjs_call_function_with_this, uint32_t, (const JavaScriptObje
/// @return A `JavaScriptValueKindAndFlags` bits represented as 32bit integer for the returned value.
IMPORT_JS_FUNCTION(swjs_call_function_with_this_no_catch, uint32_t, (const JavaScriptObjectRef _this,
const JavaScriptObjectRef func_ref,
const RawJSValue *argv,
const RawJSValue * _Nullable argv,
const int argc,
JavaScriptPayload1 *result_payload1,
JavaScriptPayload2 *result_payload2))
JavaScriptPayload1 * _Nonnull result_payload1,
JavaScriptPayload2 * _Nonnull result_payload2))

/// Calls JavaScript object constructor with given arguments list.
///
Expand All @@ -230,7 +230,7 @@ IMPORT_JS_FUNCTION(swjs_call_function_with_this_no_catch, uint32_t, (const JavaS
/// @param argc The length of `argv``.
/// @returns A reference to the constructed object.
IMPORT_JS_FUNCTION(swjs_call_new, JavaScriptObjectRef, (const JavaScriptObjectRef ref,
const RawJSValue *argv,
const RawJSValue * _Nullable argv,
const int argc))

/// Calls JavaScript object constructor with given arguments list.
Expand All @@ -243,11 +243,11 @@ IMPORT_JS_FUNCTION(swjs_call_new, JavaScriptObjectRef, (const JavaScriptObjectRe
/// @param exception_payload2 A result pointer of second payload of JavaScript value of thrown exception.
/// @returns A reference to the constructed object.
IMPORT_JS_FUNCTION(swjs_call_throwing_new, JavaScriptObjectRef, (const JavaScriptObjectRef ref,
const RawJSValue *argv,
const RawJSValue * _Nullable argv,
const int argc,
JavaScriptRawValueKindAndFlags *exception_kind,
JavaScriptPayload1 *exception_payload1,
JavaScriptPayload2 *exception_payload2))
JavaScriptRawValueKindAndFlags * _Nonnull exception_kind,
JavaScriptPayload1 * _Nonnull exception_payload1,
JavaScriptPayload2 * _Nonnull exception_payload2))

/// Acts like JavaScript `instanceof` operator.
///
Expand Down Expand Up @@ -276,14 +276,14 @@ IMPORT_JS_FUNCTION(swjs_create_function, JavaScriptObjectRef, (const JavaScriptH
/// @param length The length of `elements_ptr`
/// @returns A reference to the constructed typed array
IMPORT_JS_FUNCTION(swjs_create_typed_array, JavaScriptObjectRef, (const JavaScriptObjectRef constructor,
const void *elements_ptr,
const void * _Nullable elements_ptr,
const int length))

/// Copies the byte contents of a typed array into a Swift side memory buffer.
///
/// @param ref A JavaScript typed array object.
/// @param buffer A Swift side buffer into which to copy the bytes.
IMPORT_JS_FUNCTION(swjs_load_typed_array, void, (const JavaScriptObjectRef ref, unsigned char *buffer))
IMPORT_JS_FUNCTION(swjs_load_typed_array, void, (const JavaScriptObjectRef ref, unsigned char * _Nonnull buffer))

/// Decrements reference count of `ref` retained by `SwiftRuntimeHeap` in JavaScript side.
///
Expand Down
Loading