-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Extract various changes from the invoke and custom marshaler PRs #60877
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 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9dc0c0b
Extract various changes from the invoke and custom marshaler PRs
kg 178b5af
Repair merge damage
kg 6360c02
Repair merge damage
kg 324a260
Address PR feedback
kg c7a4ce7
Address PR feedback
kg 83dd9c3
Address PR feedback
kg 58ec782
Address PR feedback
kg 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
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,76 @@ | ||
| import { MonoAssembly, MonoClass, MonoType, MonoTypeNull } from "./types"; | ||
| import cwraps from "./cwraps"; | ||
|
|
||
| const _assembly_cache_by_name = new Map<string, MonoAssembly>(); | ||
| const _class_cache_by_assembly = new Map<MonoAssembly, Map<string, Map<string, MonoClass>>>(); | ||
|
|
||
| export function assembly_load (name : string) : MonoAssembly { | ||
| if (_assembly_cache_by_name.has(name)) | ||
| return <MonoAssembly>_assembly_cache_by_name.get(name); | ||
|
|
||
| const result = cwraps.mono_wasm_assembly_load(name); | ||
| _assembly_cache_by_name.set(name, result); | ||
| return result; | ||
| } | ||
|
|
||
| function _find_cached_class (assembly : MonoAssembly, namespace : string, name : string) : MonoClass | undefined { | ||
| let namespaces = _class_cache_by_assembly.get(assembly); | ||
| if (!namespaces) | ||
| _class_cache_by_assembly.set(assembly, namespaces = new Map()); | ||
|
|
||
| let classes = namespaces.get(namespace); | ||
| if (!classes) { | ||
| classes = new Map<string, MonoClass>(); | ||
| namespaces.set(namespace, classes); | ||
| } | ||
|
|
||
| return classes.get(name); | ||
| } | ||
|
|
||
| function _set_cached_class (assembly : MonoAssembly, namespace : string, name : string, ptr : MonoClass) { | ||
| const namespaces = _class_cache_by_assembly.get(assembly); | ||
| if (!namespaces) | ||
| throw new Error("internal error"); | ||
| const classes = namespaces.get(namespace); | ||
| if (!classes) | ||
| throw new Error("internal error"); | ||
| classes.set(name, ptr); | ||
| } | ||
|
|
||
| export function find_corlib_class (namespace : string, name : string, throw_on_failure? : boolean | undefined) : MonoClass { | ||
| const corlib = cwraps.mono_wasm_get_corlib(); | ||
| let result = _find_cached_class (corlib, namespace, name); | ||
| if (result !== undefined) | ||
| return result; | ||
| result = cwraps.mono_wasm_assembly_find_class(corlib, namespace, name); | ||
| if (throw_on_failure && !result) | ||
| throw new Error(`Failed to find corlib class ${namespace}.${name}`); | ||
| _set_cached_class(corlib, namespace, name, result); | ||
| return result; | ||
| } | ||
|
|
||
| export function find_class_in_assembly (assembly_name : string, namespace : string, name : string, throw_on_failure? : boolean | undefined) : MonoClass { | ||
| const assembly = cwraps.mono_wasm_assembly_load(assembly_name); | ||
| let result = _find_cached_class(assembly, namespace, name); | ||
| if (result !== undefined) | ||
| return result; | ||
| result = cwraps.mono_wasm_assembly_find_class(assembly, namespace, name); | ||
| if (throw_on_failure && !result) | ||
| throw new Error(`Failed to find class ${namespace}.${name} in ${assembly_name}`); | ||
| _set_cached_class(assembly, namespace, name, result); | ||
| return result; | ||
| } | ||
|
|
||
| export function find_corlib_type (namespace : string, name : string, throw_on_failure? : boolean | undefined) : MonoType { | ||
| const classPtr = find_corlib_class(namespace, name, throw_on_failure); | ||
| if (!classPtr) | ||
| return MonoTypeNull; | ||
| return cwraps.mono_wasm_class_get_type(classPtr); | ||
| } | ||
|
|
||
| export function find_type_in_assembly (assembly_name : string, namespace : string, name : string, throw_on_failure? : boolean | undefined) : MonoType { | ||
| const classPtr = find_class_in_assembly(assembly_name, namespace, name, throw_on_failure); | ||
| if (!classPtr) | ||
| return MonoTypeNull; | ||
| return cwraps.mono_wasm_class_get_type(classPtr); | ||
| } | ||
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
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.