-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d590c9e
Split runtime into multiple files
j-f1 a274ca2
use Rollup to bundle everything into one file
j-f1 d76b295
use UMD to allow directly loading via a script tag
j-f1 66e33c2
Build ESM and UMD builds separately
j-f1 2f1d6b1
Add memory and exports getters on SwiftRuntime
j-f1 630495c
move WeakRef availability checking to SwiftClosureHeap
j-f1 2b26cc4
add a Memory class that wraps the heap and raw memory
j-f1 3104c4a
rename to SwiftClosureDeallocator
j-f1 aba43c1
make callHostFunction a method
j-f1 486d941
store textEncoder, textDecoder on the instance
j-f1 341f847
mark APIs as private
j-f1 5c38015
convert from method to property
j-f1 ab9d4c3
Update TS to fix rollup issue
j-f1 dc00141
Access JSValue APIs as a namespace
j-f1 a42b0fb
Update memory.ts
j-f1 fcfdc63
explicitly type wasmImports
j-f1 418640e
remove auto-generated getter/setter pair
j-f1 fe516bc
fix endianness
j-f1 49d16b7
Merge branch 'main' into jed/runtime-js-modules
j-f1 23490c6
empty commit to trigger ci
j-f1 9ffef91
Break WeakRefs error onto multiple lines
j-f1 3c51cba
Add a comment about BigInt typed arrays not being supported
j-f1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.