MCPcopy Create free account
hub / github.com/arktypeio/arktype / createStandInProxy

Method createStandInProxy

ark/aot/interpreter.ts:2998–3100  ·  view source on GitHub ↗
({
		kind,
		target,
		length,
		name,
		mayBeStandardSchema = false,
		mayHaveHasInstance = false
	}: StandInProxyOptions)

Source from the content-addressed store, hash-verified

2996 // Interpreter/Precompiler/SourceModule ASTs when arktype caches a node
2997 // holding a stand-in in $ark or in V8's KeptObjects during a sync batch.
2998 private static createStandInProxy({
2999 kind,
3000 target,
3001 length,
3002 name,
3003 mayBeStandardSchema = false,
3004 mayHaveHasInstance = false
3005 }: StandInProxyOptions): object {
3006 const refuse = (): never => {
3007 const [interpreter, standIn] = requireStandIn(proxy)
3008 return interpreter.refuse(standIn)
3009 }
3010 const handler: ProxyHandler<Function> =
3011 kind === "opaque" ?
3012 {
3013 apply: () => {
3014 const [interpreter, standIn] = requireStandIn(proxy)
3015 interpreter.markCalled(standIn, true)
3016 throw interpreter.calledAtDefinition(standIn, undefined)
3017 },
3018 construct: () => {
3019 const [interpreter, standIn] = requireStandIn(proxy)
3020 throw interpreter.calledAtDefinition(standIn, undefined)
3021 },
3022 defineProperty: refuse,
3023 deleteProperty: refuse,
3024 get: (_, k) => (k === arkKind ? undefined : refuse()),
3025 getOwnPropertyDescriptor: refuse,
3026 getPrototypeOf: () => Object.prototype,
3027 has: (_, k) => {
3028 if (k !== "~standard") refuse()
3029 const resolved = resolveStandIn(proxy)
3030 if (resolved)
3031 resolved[0].activeCall?.ctx.site?.reached.push(resolved[1])
3032 return true
3033 },
3034 isExtensible: refuse,
3035 ownKeys: refuse,
3036 preventExtensions: refuse,
3037 set: refuse,
3038 setPrototypeOf: refuse
3039 }
3040 : {
3041 apply: (_, __, args: unknown[]) => {
3042 const [interpreter, standIn] = requireStandIn(proxy)
3043 if (kind === "class") {
3044 interpreter.markCalled(standIn, true)
3045 const node = standIn.node as Class
3046 throw new DynamicValue(
3047 standIn.module,
3048 node,
3049 `arktype calls the class${node.id ? ` \`${node.id.name}\`` : ""} (${standIn.module.positionOf(node)}) as a function, which throws a TypeError`,
3050 undefined,
3051 "callback"
3052 )
3053 }
3054 return interpreter.callStandIn(standIn, args)
3055 },

Callers 3

functionStandInMethod · 0.80
classStandInMethod · 0.80
opaqueStandInMethod · 0.80

Calls 12

requireStandInFunction · 0.85
resolveStandInFunction · 0.85
answersFactFunction · 0.85
markCalledMethod · 0.80
calledAtDefinitionMethod · 0.80
positionOfMethod · 0.80
callStandInMethod · 0.80
snippetOfMethod · 0.80
refuseFunction · 0.70
getMethod · 0.65
pushMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected