File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Tests for utils
3
+ */
4
+ import { setup } from './helpers/harness.js'
5
+
6
+ describe ( 'Ensure utils behave as expected' , ( ) => {
7
+ let browser
8
+ let server
9
+ let teardown
10
+ let setupServer
11
+ let gotoAndWait
12
+ beforeAll ( async ( ) => {
13
+ ( { browser, setupServer, teardown, gotoAndWait } = await setup ( { withExtension : true } ) )
14
+ server = setupServer ( )
15
+ } )
16
+ afterAll ( async ( ) => {
17
+ await server ?. close ( )
18
+ await teardown ( )
19
+ } )
20
+
21
+ it ( 'should toString DDGProxy correctly' , async ( ) => {
22
+ const port = server . address ( ) . port
23
+ const page = await browser . newPage ( )
24
+ await gotoAndWait ( page , `http://localhost:${ port } /blank.html` , { platform : { name : 'extension' } } )
25
+ const toStringResult = await page . evaluate ( 'HTMLCanvasElement.prototype.getContext.toString()' )
26
+ expect ( toStringResult ) . toEqual ( 'function getContext() { [native code] }' )
27
+
28
+ const toStringToStringResult = await page . evaluate ( 'HTMLCanvasElement.prototype.getContext.toString.toString()' )
29
+ expect ( toStringToStringResult ) . toEqual ( 'function toString() { [native code] }' )
30
+
31
+ /* TOFIX: This is failing because the toString() call is being proxied and the result is not what we expect
32
+ const callToStringToStringResult = await page.evaluate('String.toString.call(HTMLCanvasElement.prototype.getContext.toString)')
33
+ expect(callToStringToStringResult).toEqual('function toString() { [native code] }')
34
+ */
35
+ } )
36
+ } )
Original file line number Diff line number Diff line change @@ -377,16 +377,29 @@ export class DDGProxy {
377
377
}
378
378
return proxyObject . apply ( ...args )
379
379
}
380
+ const getMethod = ( target , prop , receiver ) => {
381
+ if ( prop === 'toString' ) {
382
+ const method = Reflect . get ( target , prop , receiver ) . bind ( target )
383
+ Object . defineProperty ( method , 'toString' , {
384
+ value : String . toString . bind ( String . toString ) ,
385
+ enumerable : false
386
+ } )
387
+ return method
388
+ }
389
+ return DDGReflect . get ( target , prop , receiver )
390
+ }
380
391
if ( hasMozProxies ) {
381
392
this . _native = objectScope [ property ]
382
393
const handler = new globalObj . wrappedJSObject . Object ( )
383
394
handler . apply = exportFunction ( outputHandler , globalObj )
395
+ handler . get = exportFunction ( getMethod , globalObj )
384
396
// @ts -ignore
385
397
this . internal = new globalObj . wrappedJSObject . Proxy ( objectScope . wrappedJSObject [ property ] , handler )
386
398
} else {
387
399
this . _native = objectScope [ property ]
388
400
const handler = { }
389
401
handler . apply = outputHandler
402
+ handler . get = getMethod
390
403
this . internal = new globalObj . Proxy ( objectScope [ property ] , handler )
391
404
}
392
405
}
You can’t perform that action at this time.
0 commit comments