Skip to content
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
20 changes: 20 additions & 0 deletions Runtime/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import typescript from "@rollup/plugin-typescript";

/** @type {import('rollup').RollupOptions} */
const config = {
input: "src/index.ts",
output: [
{
file: "lib/index.mjs",
format: "esm",
},
{
dir: "lib",
format: "umd",
name: "JavaScriptKit",
},
],
plugins: [typescript()],
};

export default config;
25 changes: 25 additions & 0 deletions Runtime/src/closure-heap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ExportedFunctions } from "./types";

/// Memory lifetime of closures in Swift are managed by Swift side
export class SwiftClosureDeallocator {
private functionRegistry: FinalizationRegistry<number>;

constructor(exports: ExportedFunctions) {
if (typeof FinalizationRegistry === "undefined") {
throw new Error(
"The Swift part of JavaScriptKit was configured to require " +
"the availability of JavaScript WeakRefs. Please build " +
"with `-Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS` to " +
"disable features that use WeakRefs."
);
}

this.functionRegistry = new FinalizationRegistry((id) => {
exports.swjs_free_host_function(id);
});
}

track(func: Function, func_ref: number) {
this.functionRegistry.register(func, func_ref);
}
}
13 changes: 13 additions & 0 deletions Runtime/src/find-global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
interface GlobalVariable {}
declare const global: GlobalVariable;

export let globalVariable: any;
if (typeof globalThis !== "undefined") {
globalVariable = globalThis;
} else if (typeof window !== "undefined") {
globalVariable = window;
} else if (typeof global !== "undefined") {
globalVariable = global;
} else if (typeof self !== "undefined") {
globalVariable = self;
}
Loading