Skip to content

Commit

Permalink
🐛 the bound value not copy the static field of original value in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos committed Aug 1, 2019
1 parent 57dce07 commit 9b8eccc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export function genSandbox(appName: string) {
@warning 这里不要随意替换成别的判断方式,因为可能触发一些 edge case(比如在 lodash.isFunction 在 iframe 上下文中可能由于调用了 top window 对象触发的安全异常)
*/
if (typeof value === 'function' && !isConstructable(value)) {
return value.bind(target);
const boundValue = value.bind(target);
// some callable function has custom fields, we need to copy the enumerable props to boundValue. such as moment function.
Object.keys(value).forEach(key => boundValue[key] = value[key]);
return boundValue;
}

return value;
Expand Down

0 comments on commit 9b8eccc

Please sign in to comment.