@@ -212,6 +212,36 @@ describe('instrumentDurableObjectWithSentry', () => {
212212 expect ( getInstrumented ( obj . rpcMethod ) ) . toBeFalsy ( ) ;
213213 expect ( obj . rpcMethod ( ) ) . toBe ( 'result' ) ;
214214 } ) ;
215+
216+ it ( 'does not wrap Object.prototype methods as RPC methods' , ( ) => {
217+ const testClass = class {
218+ rpcMethod ( ) {
219+ return 'rpc-result' ;
220+ }
221+ } ;
222+ const instrumented = instrumentDurableObjectWithSentry (
223+ vi . fn ( ) . mockReturnValue ( { enableRpcTracePropagation : true } ) ,
224+ testClass as any ,
225+ ) ;
226+ const obj = Reflect . construct ( instrumented , [ ] ) ;
227+
228+ // Object.prototype methods should NOT be wrapped - they should be the original methods
229+ expect ( obj . toString ) . toBe ( Object . prototype . toString ) ;
230+ expect ( obj . valueOf ) . toBe ( Object . prototype . valueOf ) ;
231+ expect ( obj . hasOwnProperty ) . toBe ( Object . prototype . hasOwnProperty ) ;
232+ expect ( obj . propertyIsEnumerable ) . toBe ( Object . prototype . propertyIsEnumerable ) ;
233+ expect ( obj . isPrototypeOf ) . toBe ( Object . prototype . isPrototypeOf ) ;
234+ expect ( obj . toLocaleString ) . toBe ( Object . prototype . toLocaleString ) ;
235+
236+ // They should still work correctly
237+ expect ( obj . toString ( ) ) . toBe ( '[object Object]' ) ;
238+ expect ( obj . hasOwnProperty ( 'rpcMethod' ) ) . toBe ( false ) ; // It's on prototype, not own
239+ expect ( obj . valueOf ( ) ) . toBe ( obj ) ;
240+
241+ // Meanwhile, actual RPC methods SHOULD be wrapped (not equal to prototype method)
242+ expect ( obj . rpcMethod ) . not . toBe ( testClass . prototype . rpcMethod ) ;
243+ expect ( obj . rpcMethod ( ) ) . toBe ( 'rpc-result' ) ;
244+ } ) ;
215245 } ) ;
216246
217247 it ( 'flush performs after all waitUntil promises are finished' , async ( ) => {
0 commit comments