文件
mynode/packages/lib/services/plugins/sandboxProxy.js
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

41 行
1.2 KiB
JavaScript

const handler = {};
handler.get = function(target, prop) {
let t = target;
// There's probably a cleaner way to do this but not sure how. The idea is to keep
// track of the calling chain current state. So if the user call `joplin.something.test("bla")`
// we know we need to pass "joplin.something.test" with args "bla" to the target.
// But also, if the user does this:
//
// const ns = joplin.view.dialogs;
// await ns.create();
// await ns.open();
//
// We need to know what "ns" maps to, so that's why call-specific context needs to be kept,
// and the easiest way to do this is to create a new target when the call chain starts,
// and attach a custom "__joplinNamespace" property to it.
if (!t.__joplinNamespace) {
const originalTarget = t;
const newTarget = (name, args) => {
return originalTarget(name, args);
};
newTarget.__joplinNamespace = [prop];
t = newTarget;
} else {
t.__joplinNamespace.push(prop);
}
return new Proxy(t, handler);
};
handler.apply = function(target, _thisArg, argumentsList) {
const path = target.__joplinNamespace.join('.');
target.__joplinNamespace.pop();
return target(path, argumentsList);
};
module.exports = function sandboxProxy(target) {
return new Proxy(target, handler);
};