{"version":3,"sources":["../../src/equality.ts","../../src/slot.ts","../../src/context.ts","../../src/trie.ts"],"names":["Object","prototype","toString","hasOwnProperty","fnToStr","Function","previousComparisons","Map","equal","a","b","check","clear","aTag","call","length","previouslyCompared","aKeys","definedKeys","bKeys","keyCount","k","key","name","message","size","aIterator","entries","isMap","info","next","done","value","aKey","aValue","has","get","Uint8Array","len","byteLength","aCode","full","suffix","fromIndex","indexOf","endsWith","nativeCodeSuffix","obj","keys","filter","isDefinedKey","this","bSet","set","Set","add","currentContext","MISSING_VALUE","idCounter","maybe","fn","ignored","globalKey","globalHost","globalThis","global","create","Slot","Array","defineProperty","enumerable","writable","configurable","id","Date","now","Math","random","slice","join","hasValue","parent","slots","getValue","withValue","callback","args","thisArg","__proto__","apply","context","saved","arguments","defaultMakeData","forEach","weakness","makeData","lookup","lookupArray","array","node","getChildTrie","data","map","isObjRef","weak","WeakMap","strong","child","Trie"],"mappings":"uGAAM,wCAA+BA,OAAOC,UAApCC,EAAQ,WAAEC,EAAc,iBAC1BC,EAAUC,SAASJ,UAAUC,SAC7BI,EAAsB,IAAIC,I,SAKhBC,EAAMC,EAAQC,GAC5B,IACE,OAAOC,EAAMF,EAAGC,GADlB,QAGEJ,EAAoBM,SAOxB,SAASD,EAAMF,EAAQC,GAErB,GAAID,IAAMC,EACR,OAAO,EAKT,IAAMG,EAAOX,EAASY,KAAKL,GAM3B,GAAII,IALSX,EAASY,KAAKJ,GAMzB,OAAO,EAGT,OAAQG,GACN,IAAK,iBAGH,GAAIJ,EAAEM,SAAWL,EAAEK,OAAQ,OAAO,EAEpC,IAAK,kBACH,GAAIC,EAAmBP,EAAGC,GAAI,OAAO,EAErC,IAAMO,EAAQC,EAAYT,GACpBU,EAAQD,EAAYR,GAIpBU,EAAWH,EAAMF,OACvB,GAAIK,IAAaD,EAAMJ,OAAQ,OAAO,EAGtC,IAAK,IAAIM,EAAI,EAAGA,EAAID,IAAYC,EAC9B,IAAKlB,EAAeW,KAAKJ,EAAGO,E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AOnD,KAAK6C,SAASlB,EAAMhE,KAAKqF,MAGpD,YAAAE,aAAR,SAAqB/E,GACnB,IAAMiF,EAAMpD,KAAK4C,UASrB,SAAkB/D,GAChB,cAAeA,GACf,IAAK,SACH,GAAc,OAAVA,EAAgB,MAEtB,IAAK,WACH,OAAO,EAET,OAAO,EAjBwBwE,CAASlF,GAClC6B,KAAKsD,OAAStD,KAAKsD,KAAO,IAAIC,SAC9BvD,KAAKwD,SAAWxD,KAAKwD,OAAS,IAAIpG,KAClCqG,EAAQL,EAAInE,IAAId,GAEpB,OADKsF,GAAOL,EAAIlD,IAAI/B,EAAKsF,EAAQ,IAAIC,EAAW1D,KAAK4C,SAAU5C,KAAK6C,WAC7DY,GAEX,E","file":"static/js/wry.a6a8aff9.chunk.js","sourcesContent":["const { toString, hasOwnProperty } = Object.prototype;\nconst fnToStr = Function.prototype.toString;\nconst previousComparisons = new Map>();\n\n/**\n * Performs a deep equality check on two JavaScript values, tolerating cycles.\n */\nexport function equal(a: any, b: any): boolean {\n try {\n return check(a, b);\n } finally {\n previousComparisons.clear();\n }\n}\n\n// Allow default imports as well.\nexport default equal;\n\nfunction check(a: any, b: any): boolean {\n // If the two values are strictly equal, our job is easy.\n if (a === b) {\n return true;\n }\n\n // Object.prototype.toString returns a representation of the runtime type of\n // the given value that is considerably more precise than typeof.\n const aTag = toString.call(a);\n const bTag = toString.call(b);\n\n // If the runtime types of a and b are different, they could maybe be equal\n // under some interpretation of equality, but for simplicity and performance\n // we just return false instead.\n if (aTag !== bTag) {\n return false;\n }\n\n switch (aTag) {\n case '[object Array]':\n // Arrays are a lot like other objects, but we can cheaply compare their\n // lengths as a short-cut before comparing their elements.\n if (a.length !== b.length) return false;\n // Fall through to object case...\n case '[object Object]': {\n if (previouslyCompared(a, b)) return true;\n\n const aKeys = definedKeys(a);\n const bKeys = definedKeys(b);\n\n // If `a` and `b` have a different number of enumerable keys, they\n // must be different.\n const keyCount = aKeys.length;\n if (keyCount !== bKeys.length) return false;\n\n // Now make sure they have the same keys.\n for (let k = 0; k < keyCount; ++k) {\n if (!hasOwnProperty.call(b, aKeys[k])) {\n return false;\n }\n }\n\n // Finally, check deep equality of all child properties.\n for (let k = 0; k < keyCount; ++k) {\n const key = aKeys[k];\n if (!check(a[key], b[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n case '[object Error]':\n return a.name === b.name && a.message === b.message;\n\n case '[object Number]':\n // Handle NaN, which is !== itself.\n if (a !== a) return b !== b;\n // Fall through to shared +a === +b case...\n case '[object Boolean]':\n case '[object Date]':\n return +a === +b;\n\n case '[object RegExp]':\n case '[object String]':\n return a == `${b}`;\n\n case '[object Map]':\n case '[object Set]': {\n if (a.size !== b.size) return false;\n if (previouslyCompared(a, b)) return true;\n\n const aIterator = a.entries();\n const isMap = aTag === '[object Map]';\n\n while (true) {\n const info = aIterator.next();\n if (info.done) break;\n\n // If a instanceof Set, aValue === aKey.\n const [aKey, aValue] = info.value;\n\n // So this works the same way for both Set and Map.\n if (!b.has(aKey)) {\n return false;\n }\n\n // However, we care about deep equality of values only when dealing\n // with Map structures.\n if (isMap && !check(aValue, b.get(aKey))) {\n return false;\n }\n }\n\n return true;\n }\n\n case '[object Uint16Array]':\n case '[object Uint8Array]': // Buffer, in Node.js.\n case '[object Uint32Array]':\n case '[object Int32Array]':\n case '[object Int8Array]':\n case '[object Int16Array]':\n case '[object ArrayBuffer]':\n // DataView doesn't need these conversions, but the equality check is\n // otherwise the same.\n a = new Uint8Array(a);\n b = new Uint8Array(b);\n // Fall through...\n case '[object DataView]': {\n let len = a.byteLength;\n if (len === b.byteLength) {\n while (len-- && a[len] === b[len]) {\n // Keep looping as long as the bytes are equal.\n }\n }\n return len === -1;\n }\n\n case '[object AsyncFunction]':\n case '[object GeneratorFunction]':\n case '[object AsyncGeneratorFunction]':\n case '[object Function]': {\n const aCode = fnToStr.call(a);\n if (aCode !== fnToStr.call(b)) {\n return false;\n }\n\n // We consider non-native functions equal if they have the same code\n // (native functions require === because their code is censored).\n // Note that this behavior is not entirely sound, since !== function\n // objects with the same code can behave differently depending on\n // their closure scope. However, any function can behave differently\n // depending on the values of its input arguments (including this)\n // and its calling context (including its closure scope), even\n // though the function object is === to itself; and it is entirely\n // possible for functions that are not === to behave exactly the\n // same under all conceivable circumstances. Because none of these\n // factors are statically decidable in JavaScript, JS function\n // equality is not well-defined. This ambiguity allows us to\n // consider the best possible heuristic among various imperfect\n // options, and equating non-native functions that have the same\n // code has enormous practical benefits, such as when comparing\n // functions that are repeatedly passed as fresh function\n // expressions within objects that are otherwise deeply equal. Since\n // any function created from the same syntactic expression (in the\n // same code location) will always stringify to the same code\n // according to fnToStr.call, we can reasonably expect these\n // repeatedly passed function expressions to have the same code, and\n // thus behave \"the same\" (with all the caveats mentioned above),\n // even though the runtime function objects are !== to one another.\n return !endsWith(aCode, nativeCodeSuffix);\n }\n }\n\n // Otherwise the values are not equal.\n return false;\n}\n\nfunction definedKeys(obj: TObject) {\n // Remember that the second argument to Array.prototype.filter will be\n // used as `this` within the callback function.\n return Object.keys(obj).filter(isDefinedKey, obj);\n}\nfunction isDefinedKey(\n this: TObject,\n key: keyof TObject,\n) {\n return this[key] !== void 0;\n}\n\nconst nativeCodeSuffix = \"{ [native code] }\";\n\nfunction endsWith(full: string, suffix: string) {\n const fromIndex = full.length - suffix.length;\n return fromIndex >= 0 &&\n full.indexOf(suffix, fromIndex) === fromIndex;\n}\n\nfunction previouslyCompared(a: object, b: object): boolean {\n // Though cyclic references can make an object graph appear infinite from the\n // perspective of a depth-first traversal, the graph still contains a finite\n // number of distinct object references. We use the previousComparisons cache\n // to avoid comparing the same pair of object references more than once, which\n // guarantees termination (even if we end up comparing every object in one\n // graph to every object in the other graph, which is extremely unlikely),\n // while still allowing weird isomorphic structures (like rings with different\n // lengths) a chance to pass the equality test.\n let bSet = previousComparisons.get(a);\n if (bSet) {\n // Return true here because we can be sure false will be returned somewhere\n // else if the objects are not equivalent.\n if (bSet.has(b)) return true;\n } else {\n previousComparisons.set(a, bSet = new Set);\n }\n bSet.add(b);\n return false;\n}\n","type Context = {\n parent: Context | null;\n slots: { [slotId: string]: any };\n}\n\n// This currentContext variable will only be used if the makeSlotClass\n// function is called, which happens only if this is the first copy of the\n// @wry/context package to be imported.\nlet currentContext: Context | null = null;\n\n// This unique internal object is used to denote the absence of a value\n// for a given Slot, and is never exposed to outside code.\nconst MISSING_VALUE: any = {};\n\nlet idCounter = 1;\n\n// Although we can't do anything about the cost of duplicated code from\n// accidentally bundling multiple copies of the @wry/context package, we can\n// avoid creating the Slot class more than once using makeSlotClass.\nconst makeSlotClass = () => class Slot {\n // If you have a Slot object, you can find out its slot.id, but you cannot\n // guess the slot.id of a Slot you don't have access to, thanks to the\n // randomized suffix.\n public readonly id = [\n \"slot\",\n idCounter++,\n Date.now(),\n Math.random().toString(36).slice(2),\n ].join(\":\");\n\n public hasValue() {\n for (let context = currentContext; context; context = context.parent) {\n // We use the Slot object iself as a key to its value, which means the\n // value cannot be obtained without a reference to the Slot object.\n if (this.id in context.slots) {\n const value = context.slots[this.id];\n if (value === MISSING_VALUE) break;\n if (context !== currentContext) {\n // Cache the value in currentContext.slots so the next lookup will\n // be faster. This caching is safe because the tree of contexts and\n // the values of the slots are logically immutable.\n currentContext!.slots[this.id] = value;\n }\n return true;\n }\n }\n if (currentContext) {\n // If a value was not found for this Slot, it's never going to be found\n // no matter how many times we look it up, so we might as well cache\n // the absence of the value, too.\n currentContext.slots[this.id] = MISSING_VALUE;\n }\n return false;\n }\n\n public getValue(): TValue | undefined {\n if (this.hasValue()) {\n return currentContext!.slots[this.id] as TValue;\n }\n }\n\n public withValue(\n value: TValue,\n callback: (this: TThis, ...args: TArgs) => TResult,\n // Given the prevalence of arrow functions, specifying arguments is likely\n // to be much more common than specifying `this`, hence this ordering:\n args?: TArgs,\n thisArg?: TThis,\n ): TResult {\n const slots = {\n __proto__: null,\n [this.id]: value,\n };\n const parent = currentContext;\n currentContext = { parent, slots };\n try {\n // Function.prototype.apply allows the arguments array argument to be\n // omitted or undefined, so args! is fine here.\n return callback.apply(thisArg!, args!);\n } finally {\n currentContext = parent;\n }\n }\n\n // Capture the current context and wrap a callback function so that it\n // reestablishes the captured context when called.\n static bind(\n callback: (this: TThis, ...args: TArgs) => TResult,\n ) {\n const context = currentContext;\n return function (this: TThis) {\n const saved = currentContext;\n try {\n currentContext = context;\n return callback.apply(this, arguments as any);\n } finally {\n currentContext = saved;\n }\n } as typeof callback;\n }\n\n // Immediately run a callback function without any captured context.\n static noContext(\n callback: (this: TThis, ...args: TArgs) => TResult,\n // Given the prevalence of arrow functions, specifying arguments is likely\n // to be much more common than specifying `this`, hence this ordering:\n args?: TArgs,\n thisArg?: TThis,\n ) {\n if (currentContext) {\n const saved = currentContext;\n try {\n currentContext = null;\n // Function.prototype.apply allows the arguments array argument to be\n // omitted or undefined, so args! is fine here.\n return callback.apply(thisArg!, args!);\n } finally {\n currentContext = saved;\n }\n } else {\n return callback.apply(thisArg!, args!);\n }\n }\n};\n\nfunction maybe(fn: () => T): T | undefined {\n try {\n return fn();\n } catch (ignored) {}\n}\n\n// We store a single global implementation of the Slot class as a permanent\n// non-enumerable property of the globalThis object. This obfuscation does\n// nothing to prevent access to the Slot class, but at least it ensures the\n// implementation (i.e. currentContext) cannot be tampered with, and all copies\n// of the @wry/context package (hopefully just one) will share the same Slot\n// implementation. Since the first copy of the @wry/context package to be\n// imported wins, this technique imposes a steep cost for any future breaking\n// changes to the Slot class.\nconst globalKey = \"@wry/context:Slot\";\n\nconst host =\n // Prefer globalThis when available.\n // https://github.com/benjamn/wryware/issues/347\n maybe(() => globalThis) ||\n // Fall back to global, which works in Node.js and may be converted by some\n // bundlers to the appropriate identifier (window, self, ...) depending on the\n // bundling target. https://github.com/endojs/endo/issues/576#issuecomment-1178515224\n maybe(() => global) ||\n // Otherwise, use a dummy host that's local to this module. We used to fall\n // back to using the Array constructor as a namespace, but that was flagged in\n // https://github.com/benjamn/wryware/issues/347, and can be avoided.\n Object.create(null) as typeof Array;\n\n// Whichever globalHost we're using, make TypeScript happy about the additional\n// globalKey property.\nconst globalHost: typeof host & {\n [globalKey]?: typeof Slot;\n} = host;\n\nexport const Slot: ReturnType =\n globalHost[globalKey] ||\n // Earlier versions of this package stored the globalKey property on the Array\n // constructor, so we check there as well, to prevent Slot class duplication.\n (Array as typeof globalHost)[globalKey] ||\n (function (Slot) {\n try {\n Object.defineProperty(globalHost, globalKey, {\n value: Slot,\n enumerable: false,\n writable: false,\n // When it was possible for globalHost to be the Array constructor (a\n // legacy Slot dedup strategy), it was important for the property to be\n // configurable:true so it could be deleted. That does not seem to be as\n // important when globalHost is the global object, but I don't want to\n // cause similar problems again, and configurable:true seems safest.\n // https://github.com/endojs/endo/issues/576#issuecomment-1178274008\n configurable: true\n });\n } finally {\n return Slot;\n }\n })(makeSlotClass());\n","import { Slot } from \"./slot\";\nexport { Slot }\nexport const { bind, noContext } = Slot;\n\n// Relying on the @types/node declaration of global.setTimeout can make\n// things tricky for dowstream projects (see PR #7).\ndeclare function setTimeout(\n callback: (...args: any[]) => any,\n ms?: number,\n ...args: any[]\n): any;\n\n// Like global.setTimeout, except the callback runs with captured context.\nexport { setTimeoutWithContext as setTimeout };\nfunction setTimeoutWithContext(callback: () => any, delay: number) {\n return setTimeout(bind(callback), delay);\n}\n\n// Turn any generator function into an async function (using yield instead\n// of await), with context automatically preserved across yields.\nexport function asyncFromGen<\n TArgs extends any[],\n TYield = any,\n TReturn = any,\n TNext = any,\n>(\n genFn: (...args: TArgs) => Generator\n) {\n return function (this: any) {\n const gen = genFn.apply(this, arguments as any);\n\n type Method = (\n this: Generator,\n arg: any,\n ) => IteratorResult;\n\n const boundNext: Method = bind(gen.next);\n const boundThrow: Method = bind(gen.throw!);\n\n return new Promise((resolve, reject) => {\n function invoke(method: Method, argument: any) {\n try {\n var result: any = method.call(gen, argument);\n } catch (error) {\n return reject(error);\n }\n const next = result.done ? resolve : invokeNext;\n if (isPromiseLike(result.value)) {\n result.value.then(next, result.done ? reject : invokeThrow);\n } else {\n next(result.value);\n }\n }\n const invokeNext = (value?: any) => invoke(boundNext, value);\n const invokeThrow = (error: any) => invoke(boundThrow, error);\n invokeNext();\n });\n } as (...args: TArgs) => Promise;\n}\n\nfunction isPromiseLike(value: any): value is PromiseLike {\n return value && typeof value.then === \"function\";\n}\n\n// If you use the fibers npm package to implement coroutines in Node.js,\n// you should call this function at least once to ensure context management\n// remains coherent across any yields.\nconst wrappedFibers: Function[] = [];\nexport function wrapYieldingFiberMethods(Fiber: F): F {\n // There can be only one implementation of Fiber per process, so this array\n // should never grow longer than one element.\n if (wrappedFibers.indexOf(Fiber) < 0) {\n const wrap = (obj: any, method: string) => {\n const fn = obj[method];\n obj[method] = function () {\n return noContext(fn, arguments as any, this);\n };\n }\n // These methods can yield, according to\n // https://github.com/laverdet/node-fibers/blob/ddebed9b8ae3883e57f822e2108e6943e5c8d2a8/fibers.js#L97-L100\n wrap(Fiber, \"yield\");\n wrap(Fiber.prototype, \"run\");\n wrap(Fiber.prototype, \"throwInto\");\n wrappedFibers.push(Fiber);\n }\n return Fiber;\n}\n","// A [trie](https://en.wikipedia.org/wiki/Trie) data structure that holds\n// object keys weakly, yet can also hold non-object keys, unlike the\n// native `WeakMap`.\n\n// If no makeData function is supplied, the looked-up data will be an empty,\n// null-prototype Object.\nconst defaultMakeData = () => Object.create(null);\n\n// Useful for processing arguments objects as well as arrays.\nconst { forEach, slice } = Array.prototype;\n\nexport class Trie {\n // Since a `WeakMap` cannot hold primitive values as keys, we need a\n // backup `Map` instance to hold primitive keys. Both `this._weakMap`\n // and `this._strongMap` are lazily initialized.\n private weak?: WeakMap>;\n private strong?: Map>;\n private data?: Data;\n\n constructor(\n private weakness = true,\n private makeData: (array: any[]) => Data = defaultMakeData,\n ) {}\n\n public lookup(...array: T): Data {\n return this.lookupArray(array);\n }\n\n public lookupArray(array: T): Data {\n let node: Trie = this;\n forEach.call(array, key => node = node.getChildTrie(key));\n return node.data || (node.data = this.makeData(slice.call(array)));\n }\n\n private getChildTrie(key: any) {\n const map = this.weakness && isObjRef(key)\n ? this.weak || (this.weak = new WeakMap>())\n : this.strong || (this.strong = new Map>());\n let child = map.get(key);\n if (!child) map.set(key, child = new Trie(this.weakness, this.makeData));\n return child;\n }\n}\n\nfunction isObjRef(value: any) {\n switch (typeof value) {\n case \"object\":\n if (value === null) break;\n // Fall through to return true...\n case \"function\":\n return true;\n }\n return false;\n}\n"],"sourceRoot":""}