MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / shouldFnBind

Function shouldFnBind

src/app/service/content/create_context.ts:133–156  ·  view source on GitHub ↗
(f: any)

Source from the content-addressed store, hash-verified

131
132// 判断是否应该将函数绑定到global (原生函数)
133export const shouldFnBind = (f: any) => {
134 if (typeof f !== "function") return false;
135 // 函数有 prototype 即为 Class
136 if ("prototype" in f) return false; // 避免getter, 使用 in operator (注意, nodeJS的测试环境有异)
137 // 要求函数名字小写字头 能筛选掉 NodeFilter 之类 Interface ( 大写开头不用于直接呼叫 )
138 // 要求函数名字不包含空白 能筛选掉 已经this绑定函数
139 const { name } = f as typeof Function.prototype;
140 if (!name) return false;
141 const e = name.charCodeAt(0);
142 if (e >= 97 && e <= 122 && !name.includes(" ")) {
143 // 为避免浏览器插件封装了 原生函数,需要进行 toString 测试 (Proxy封装例外)
144 if (ncs?.[1]) {
145 const s = `${f}`;
146 // 广告拦截扩展进行Proxy封装后丢失名字 (Chrome:所有经Proxy封装都会变成无名原生函数)
147 if (s === `${ncs[0]}${name}${ncs[1]}` || s === `${ncs[0]}${ncs[1]}`) {
148 return true;
149 }
150 } else {
151 // 代码错误,全部 bind
152 return true;
153 }
154 }
155 return false;
156};
157
158type ForEachCallback<T> = (value: T, index: number, array: T[]) => void;
159

Callers 2

create_context.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected