Skip to content

Commit 6b98743

Browse files
author
cod1k
committed
Improve copyExecutionContext method handling
Enhanced the descriptor logic to better handle non-function properties and prevent invalid method overrides. Fixed potential issues with binding non-function properties to the context.
1 parent 5dfc197 commit 6b98743

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/cloudflare/src/utils/copyExecutionContext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ function makeMethodDescriptor(store: OverridesStore, ctx: ContextType, method: k
3939
configurable: true,
4040
enumerable: true,
4141
set: newValue => {
42+
if(typeof newValue !== 'function') throw new Error('Cannot override non-function')
4243
store.set(method, newValue);
4344
return true;
4445
},
4546

4647
get: () => {
4748
if (store.has(method)) return store.get(method);
48-
return Reflect.get(ctx, method).bind(ctx);
49+
const methodFunction = Reflect.get(ctx, method);
50+
if (typeof methodFunction !== 'function') return methodFunction;
51+
return methodFunction.bind(ctx);
4952
},
5053
};
5154
}

0 commit comments

Comments
 (0)