-
Notifications
You must be signed in to change notification settings - Fork 112
Server Registry Stuff #1085
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
base: main
Are you sure you want to change the base?
Server Registry Stuff #1085
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,25 @@ static Holder<?> wrap(KubeJSContext cx, Object from, TypeInfo param) { | |
| return holder.isEmpty() ? DeferredHolder.create(registry.key(), id) : holder.get(); | ||
| } | ||
|
|
||
| static Holder.Reference<?> wrapRef(KubeJSContext cx, Object from, TypeInfo param) { | ||
| if (from instanceof Holder.Reference<?> h) { | ||
| return h; | ||
| } else if (from == null) { | ||
| throw Context.reportRuntimeError("Can't interpret 'null' as a holder", cx); | ||
| } | ||
|
|
||
| var registry = cx.lookupRegistry(param, from); | ||
|
|
||
| if (from instanceof Holder<?> h) { | ||
| return Holder.Reference.createStandAlone(Cast.to(registry.holderOwner()), h.getKey()); | ||
| } else if (!ID.isKey(from)) { | ||
| throw Context.reportRuntimeError("Can't interpret '" + from + "' as a reference holder", cx); | ||
| } | ||
|
|
||
| var id = ID.mc(from); | ||
| return Holder.Reference.createStandAlone(Cast.to(registry.holderOwner()), ResourceKey.create(registry.key(), id)); | ||
| } | ||
|
|
||
|
Comment on lines
+59
to
+77
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, more general question, is there any time where we shouldn't just be using the regular wrap() method and then convert that (either cast or retrieve delegate) to a reference holder?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only time a holder's delegate would be a reference holder is reference holders themselves and bound deferred holders, and the latter has problems due to only being bound if the registry has the id registered and the actual registry either being non-existent or frozen. |
||
| static HolderSet<?> wrapSet(KubeJSContext cx, Object from, TypeInfo param) { | ||
| var registry = cx.lookupRegistry(param, from); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is createStandAlone guaranteed to be safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what context? When serializing with a registry present (the intent & use case I have), yes. For retrieving a value/id from the registry itself (or the holder even), no