Skip to content

Commit

Permalink
Merge pull request #37 from unyt-org/fix-disable-function-constructor…
Browse files Browse the repository at this point in the history
…s-for-std-types

Fix: Disable function constructors for std types
  • Loading branch information
benStre authored Jan 18, 2024
2 parents 6a942d0 + 3787f4e commit 20eaee1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion runtime/pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ export class Pointer<T = any> extends Ref<T> {
// else
if (!allow_failure) displayFatalError('pointer-not-found');
pointer.delete();
throw new PointerError("Pointer $"+id_string+" has no assigned value", SCOPE);
throw new PointerError("Pointer $"+id_string+" does not exist", SCOPE);
}
}

Expand Down
4 changes: 4 additions & 0 deletions runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,10 @@ export class Runtime {
* @param header DXB header of incoming message
*/
private static updateEndpointOnlineState(header: dxb_header) {
if (!header) {
logger.error("updateEndpointOnlineState: no header provided");
return;
}
if (header.sender) {
// received signed GOODBYE message -> endpoint is offline
if (header.type == ProtocolDataType.GOODBYE) {
Expand Down
4 changes: 2 additions & 2 deletions types/function-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ export function createFunctionWithDependencyInjections(source: string, dependenc
}

export class ExtensibleFunction {
constructor(f:globalThis.Function) {
return Object.setPrototypeOf(f, new.target.prototype);
constructor(f?:globalThis.Function) {
if (f) return Object.setPrototypeOf(f, new.target.prototype);
}
}

Expand Down
10 changes: 5 additions & 5 deletions types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class Type<T = any> extends ExtensibleFunction {

// never call the constructor directly!! should be private
constructor(namespace?:string, name?:string, variation?:string, parameters?:any[]) {
super((val:any) => this.cast(val))
super(namespace && namespace != "std" ? (val:any) => this.cast(val) : undefined)
if (name) this.name = name;
if (namespace) this.namespace = namespace;
if (variation) this.variation = variation;
Expand Down Expand Up @@ -1081,15 +1081,15 @@ Type.std.Assertion.setJSInterface({
})


Type.std.StorageMap.setJSInterface({
class: StorageMap,
Type.std.StorageWeakMap.setJSInterface({
class: StorageWeakMap,
is_normal_object: true,
proxify_children: true,
visible_children: new Set(),
})

Type.std.StorageWeakMap.setJSInterface({
class: StorageWeakMap,
Type.std.StorageMap.setJSInterface({
class: StorageMap,
is_normal_object: true,
proxify_children: true,
visible_children: new Set(),
Expand Down

0 comments on commit 20eaee1

Please sign in to comment.