Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛compatible with vConsole who will wrap global variables with proxy #2630

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/sandbox/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export function getTargetValue(target: any, value: any): any {

const boundValue = Function.prototype.bind.call(value, target);

// some callable function has custom fields, we need to copy the enumerable props to boundValue. such as moment function.
// use for..in rather than Object.keys.forEach for performance reason
// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const key in value) {
boundValue[key] = value[key];
}
// some callable function has custom fields, we need to copy the own props to boundValue. such as moment function.
Object.getOwnPropertyNames(value).forEach((key) => {
// boundValue might be a proxy, we need to check the key whether exist in it
if (!boundValue.hasOwnProperty(key)) {
Object.defineProperty(boundValue, key, Object.getOwnPropertyDescriptor(value, key)!);
}
});

// copy prototype if bound function not have but target one have
// as prototype is non-enumerable mostly, we need to copy it from target function manually
Expand Down