Skip to content

Split runtime into multiple files #150

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 22 commits into from
Jan 24, 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
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