atmos/os_lib/ecma/
fn_meta.rs1pub fn native_display_name(name: &str) -> &str {
10 if let Some(inner) = name.strip_prefix("Symbol(").and_then(|r| r.strip_suffix(')')) {
11 return inner;
13 }
14 if name.starts_with('[') || name.starts_with("bound ") || name.starts_with("get ") || name.starts_with("set ") {
15 return name;
16 }
17 if let Some(idx) = name.find('[') {
18 if let Some(sub) = name.get(idx..) {
19 return sub;
20 }
21 }
22 match name.rfind('.').and_then(|i| name.get(i + 1..)) {
23 Some(short) if !short.is_empty() => short,
24 _ => name,
25 }
26}
27
28pub fn native_name_string(name: &str) -> alloc::string::String {
30 if name.starts_with("Symbol(") && name.ends_with(')') {
31 return alloc::format!("[{}]", native_display_name(name));
32 }
33 alloc::string::String::from(native_display_name(name))
34}
35
36pub fn native_length(name: &str) -> u32 {
38 if let Some(n) = length_of(name) {
39 return n;
40 }
41 match name.rfind('.').and_then(|i| name.get(i + 1..)) {
42 Some(short) => length_of(short).unwrap_or(0),
43 None => 0,
44 }
45}
46
47fn length_of(name: &str) -> Option<u32> {
48 Some(match name {
49 "Iterator.concat" | "Date.now" | "Math.random" | "Promise.withResolvers" | "Array.of" | "TypedArray.of" => 0,
50 "Array" | "Array.from" | "Array.fromAsync" | "Array.isArray" | "ArrayBuffer" | "ArrayBuffer.isView" | "AsyncFunction" | "AsyncGeneratorFunction" | "Atomics.isLockFree" | "BigInt" | "Boolean" | "DataView" | "Date.parse" | "DateTimeFormat.format" | "Deferred" | "DisposableStack.defer" | "DisposableStack.use" | "AsyncDisposableStack.defer" | "AsyncDisposableStack.use" | "DurationFormat.format" | "Error" | "Error.isError" | "EvalError" | "FinalizationRegistry" | "Function" | "GeneratorFunction" | "Intl.Locale" | "Intl.getCanonicalLocales" | "Intl.supportedValuesOf" | "Iterator.from" | "Iterator.zip" | "Iterator.zipKeyed" | "Iterator.range" | "JSON.isRawJSON" | "JSON.rawJSON" | "ListFormat.format" | "Locale" | "Math.abs" | "Math.acos" | "Math.acosh" | "Math.asin" | "Math.asinh" | "Math.atan" | "Math.atanh" | "Math.cbrt" | "Math.ceil" | "Math.clz32" | "Math.cos" | "Math.cosh" | "Math.exp" | "Math.expm1" | "Math.f16round" | "Math.floor" | "Math.fround" | "Math.log" | "Math.log10" | "Math.log1p" | "Math.log2" | "Math.round" | "Math.sign" | "Math.sin" | "Math.sinh" | "Math.sqrt" | "Math.sumPrecise" | "Math.tan" | "Math.tanh" | "Math.trunc" | "Number" | "Number.isFinite" | "Number.isInteger" | "Number.isNaN" | "Number.isSafeInteger" | "Number.parseFloat" | "Number.toString" | "NumberFormat.format" | "Object" | "Object.entries" | "Object.freeze" | "Object.fromEntries" | "Object.getOwnPropertyDescriptors" | "Object.getOwnPropertyNames" | "Object.getOwnPropertySymbols" | "Object.getPrototypeOf" | "Object.isExtensible" | "Object.isFrozen" | "Object.isSealed" | "Object.keys" | "Object.preventExtensions" | "Object.seal" | "Object.values" | "Promise" | "Promise.all" | "Promise.allSettled" | "Promise.allKeyed" | "Promise.allSettledKeyed" | "Promise.any" | "Promise.race" | "Promise.reject" | "Promise.resolve" | "Promise.try" | "RangeError" | "ReferenceError" | "Reflect.getPrototypeOf" | "Reflect.isExtensible" | "Reflect.ownKeys" | "Reflect.preventExtensions" | "RegExp.escape" | "SharedArrayBuffer" | "String" | "String.fromCharCode" | "String.fromCodePoint" | "String.raw" | "Symbol(Symbol.hasInstance)" | "Symbol(Symbol.match)" | "Symbol(Symbol.matchAll)" | "Symbol(Symbol.search)" | "Symbol(Symbol.toPrimitive)" | "Symbol.for" | "Symbol.keyFor" | "SyntaxError" | "TypeError" | "URIError" | "Uint8Array.fromBase64" | "Uint8Array.fromHex" | "WeakRef" | "[Symbol.hasInstance]" | "[Symbol.match]" | "[Symbol.matchAll]" | "[Symbol.search]" | "[Symbol.toPrimitive]" | "__lookupGetter__" | "__lookupSetter__" | "add" | "anchor" | "at" | "bind" | "call" | "catch" | "charAt" | "charCodeAt" | "chunks" | "codePointAt" | "concat" | "containing" | "decodeURI" | "decodeURIComponent" | "defer" | "delete" | "difference" | "drop" | "encodeURI" | "encodeURIComponent" | "endsWith" | "escape" | "eval" | "every" | "exec" | "f16round" | "fill" | "filter" | "finally" | "find" | "findIndex" | "findLast" | "findLastIndex" | "flatMap" | "fontcolor" | "fontsize" | "forEach" | "format" | "formatToParts" | "from" | "fromBase64" | "fromHex" | "get" | "getBigInt64" | "getBigUint64" | "getCanonicalLocales" | "getFloat16" | "getFloat32" | "getFloat64" | "getInt16" | "getInt32" | "getInt8" | "getUint16" | "getUint32" | "getUint8" | "grow" | "has" | "hasOwnProperty" | "includes" | "indexOf" | "intersection" | "isDisjointFrom" | "isError" | "isFinite" | "isNaN" | "isPrototypeOf" | "isSubsetOf" | "isSupersetOf" | "isView" | "join" | "lastIndexOf" | "link" | "localeCompare" | "map" | "match" | "matchAll" | "padEnd" | "padStart" | "parseFloat" | "propertyIsEnumerable" | "push" | "reduce" | "reduceRight" | "repeat" | "resize" | "search" | "segment" | "select" | "set __proto__" | "set stack" | "setDate" | "setFromBase64" | "setFromHex" | "setMilliseconds" | "setTime" | "setUTCDate" | "setUTCMilliseconds" | "setYear" | "some" | "sort" | "startsWith" | "sumPrecise" | "supportedLocalesOf" | "supportedValuesOf" | "symmetricDifference" | "take" | "test" | "toExponential" | "toFixed" | "toJSON" | "toPrecision" | "toSorted" | "try" | "unescape" | "union" | "unregister" | "unshift" | "use" | "windows" => 1,
51 "AggregateError" | "Atomics.load" | "BigInt.asIntN" | "BigInt.asUintN" | "Collator.compare" | "DisplayNames" | "DisposableStack.adopt" | "AsyncDisposableStack.adopt" | "Error.captureStackTrace" | "Error.prepareStackTrace" | "FinalizationRegistry.register" | "Intl.DisplayNames" | "JSON.parse" | "Map.getOrInsert" | "Map.getOrInsertComputed" | "Map.groupBy" | "Math.atan2" | "Math.hypot" | "Math.imul" | "Math.max" | "Math.min" | "Math.pow" | "Number.parseInt" | "Object.assign" | "Object.create" | "Object.defineProperties" | "Object.getOwnPropertyDescriptor" | "Object.groupBy" | "Object.hasOwn" | "Object.is" | "Object.setPrototypeOf" | "Proxy" | "Proxy.revocable" | "Reflect.construct" | "Reflect.deleteProperty" | "Reflect.get" | "Reflect.getOwnPropertyDescriptor" | "Reflect.has" | "Reflect.setPrototypeOf" | "RegExp" | "RelativeTimeFormat.format" | "RelativeTimeFormat.formatToParts" | "Symbol(Symbol.replace)" | "Symbol(Symbol.split)" | "[Symbol.replace]" | "[Symbol.split]" | "__defineGetter__" | "__defineSetter__" | "adopt" | "apply" | "compare" | "compile" | "copyWithin" | "formatRange" | "formatRangeToParts" | "getOrInsert" | "getOrInsertComputed" | "parseInt" | "register" | "replace" | "replaceAll" | "selectRange" | "set" | "setBigInt64" | "setBigUint64" | "setFloat16" | "setFloat32" | "setFloat64" | "setInt16" | "setInt32" | "setInt8" | "setMonth" | "setSeconds" | "setUTCMonth" | "setUTCSeconds" | "setUint16" | "setUint32" | "setUint8" | "slice" | "splice" | "split" | "subarray" | "substr" | "substring" | "then" | "toSpliced" | "with" => 2,
52 "Atomics.add" | "Atomics.and" | "Atomics.exchange" | "Atomics.notify" | "Atomics.or" | "Atomics.store" | "Atomics.sub" | "Atomics.xor" | "BigInt64Array" | "BigUint64Array" | "Float16Array" | "Float32Array" | "Float64Array" | "Int16Array" | "Int32Array" | "Int8Array" | "JSON.stringify" | "Math.clamp" | "Object.defineProperty" | "Reflect.apply" | "Reflect.defineProperty" | "Reflect.set" | "SuppressedError" | "Uint16Array" | "Uint32Array" | "Uint8Array" | "Uint8ClampedArray" | "clamp" | "setFullYear" | "setMinutes" | "setUTCFullYear" | "setUTCMinutes" => 3,
53 "Atomics.compareExchange" | "Atomics.wait" | "Atomics.waitAsync" | "setHours" | "setUTCHours" => 4,
54 "Date" | "Date.UTC" => 7,
55 _ => return None,
56 })
57}