Skip to content

Add test for detached ArrayBuffer #154

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 3 commits into from
Jan 25, 2022
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
6 changes: 5 additions & 1 deletion IntegrationTests/TestSuites/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ let package = Package(
],
dependencies: [.package(name: "JavaScriptKit", path: "../../")],
targets: [
.target(name: "PrimaryTests", dependencies: ["JavaScriptKit"]),
.target(name: "CHelpers"),
.target(name: "PrimaryTests", dependencies: [
"JavaScriptKit",
"CHelpers",
]),
.target(
name: "ConcurrencyTests",
dependencies: [
Expand Down
4 changes: 4 additions & 0 deletions IntegrationTests/TestSuites/Sources/CHelpers/helpers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int growMemory(int pages) {
return __builtin_wasm_memory_grow(0, pages);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// Ask host to grow WebAssembly module's allocated memory
///
/// @param pages Number of memory pages to increase memory by.
int growMemory(int pages);

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CHelpers {
header "helpers.h"
export *
}
13 changes: 12 additions & 1 deletion IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import JavaScriptKit

import CHelpers

try test("Literal Conversion") {
let global = JSObject.global
Expand Down Expand Up @@ -735,4 +735,15 @@ try test("Exception") {
try expectNotNil(errorObject3)
}

/// If WebAssembly.Memory is not accessed correctly (i.e. creating a new view each time),
/// this test will fail with `TypeError: Cannot perform Construct on a detached ArrayBuffer`,
/// since asking to grow memory will detach the backing ArrayBuffer.
/// See https://github.com/swiftwasm/JavaScriptKit/pull/153
try test("Grow Memory") {
let string = "Hello"
let jsString = JSValue.string(string)
growMemory(1)
try expectEqual(string, jsString.description)
}

Expectation.wait(expectations)