Skip to content
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

Init JSUInt8ClampedArray from [UInt8] failed #230

Open
meqtMac opened this issue Sep 3, 2023 · 0 comments
Open

Init JSUInt8ClampedArray from [UInt8] failed #230

meqtMac opened this issue Sep 3, 2023 · 0 comments

Comments

@meqtMac
Copy link

meqtMac commented Sep 3, 2023

        console.log(data: "arr transformed")
        let array: [UInt8] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        let jsArray: Uint8ClampedArray = .init(array)
        console.log(data: "newData created")
        let newImage = ImageData(data: .init(arr), sw: 600)
        console.log(data: "image created")
        context.putImageData(imagedata: newImage, dx: 0, dy: 0)

besides, I'm using WebAPIKit.
let jsArray: Uint8ClampedArray = .init(array) function crashed.
image

  • carton: 0.19.0
  • JavaScriptKit: 0.18.0
  • swift-wasm-5.8.0-RELEASE.xctoolchain
  • Safari 16.6

reproduce the situation

import JavaScriptKit

public enum console {
    public static func log(data: JSValue...) {
        let this = JSObject.global["console"].object!
        _ = this["log"].function!(this: this, arguments: data.map{$0.jsValue} )
    }
}

let document = JSObject.global.document
struct Button {
    var object: JSValue
    
   init(_ title: String, onClick block: @escaping () -> Void = {}) {
       self.object = JSObject.global.document.createElement("button")
        object.textContent = .init(stringLiteral: title)
        let callBackClosure = JSClosure { _ in
            block()
            return nil
        }
        object.onclick = .object(callBackClosure)
    }
}

let button = Button("Button") {
    console.log(data: "creating array")
    let array: [UInt8] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    console.log(data: array.jsValue)
    let jsUInt8ClampedArray: JSUInt8ClampedArray = .init(array)
    console.log(data: jsUInt8ClampedArray.jsValue)
}
_ = document.body.appendChild(button.object)
carton dev

click the button, and it seems crashes in JS Runtime.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant