diff --git a/src/client/sandbox/native-methods.js b/src/client/sandbox/native-methods.js index b54dc0082..fdea425b5 100644 --- a/src/client/sandbox/native-methods.js +++ b/src/client/sandbox/native-methods.js @@ -62,7 +62,8 @@ class NativeMethods { const documentCookieDescriptor = win.Object.getOwnPropertyDescriptor(win[this.documentCookiePropOwnerName].prototype, 'cookie'); // TODO: remove this condition after the GH-1649 fix - if (documentCookieDescriptor.get.toString().indexOf('native code') === -1) { + if (documentCookieDescriptor.get.toString().indexOf('native code') === -1 || + documentCookieDescriptor.get.toString.toString().indexOf('native code') === -1) { try { const parentNativeMethods = win.parent['%hammerhead%'].nativeMethods; diff --git a/src/client/utils/property-overriding.js b/src/client/utils/property-overriding.js index 48213107f..075606daa 100644 --- a/src/client/utils/property-overriding.js +++ b/src/client/utils/property-overriding.js @@ -1,13 +1,23 @@ import nativeMethods from '../sandbox/native-methods'; +function replaceNativeAccessor (descriptor, accessorName, newAccessor) { + if (newAccessor && descriptor[accessorName]) { + const stringifiedNativeAccessor = descriptor[accessorName].toString(); + + newAccessor.toString = () => stringifiedNativeAccessor; + } + + descriptor[accessorName] = newAccessor; +} + export function createOverriddenDescriptor (obj, prop, { getter, setter }) { const descriptor = nativeMethods.objectGetOwnPropertyDescriptor.call(window.Object, obj, prop); if (getter !== null) - descriptor.get = getter; + replaceNativeAccessor(descriptor, 'get', getter); if (setter !== null) - descriptor.set = setter; + replaceNativeAccessor(descriptor, 'set', setter); return descriptor; } diff --git a/test/client/fixtures/sandbox/node/attributes-test.js b/test/client/fixtures/sandbox/node/attributes-test.js index 2617b7b6b..8070f1968 100644 --- a/test/client/fixtures/sandbox/node/attributes-test.js +++ b/test/client/fixtures/sandbox/node/attributes-test.js @@ -1088,3 +1088,12 @@ test('Url resolving in an instance of document.implementation (GH-1673)', functi strictEqual(anchorEl.href, 'http://localhost:1993/some/page.html'); }); + +test('The toString function should return native string for overridden descriptor accessors (GH-1713)', function () { + ok(HTMLElement.prototype.__lookupGetter__('firstChild').toString().indexOf('[native code]') !== -1); + ok(HTMLElement.prototype.__lookupGetter__('lastChild').toString().indexOf('[native code]') !== -1); + ok(HTMLAnchorElement.prototype.__lookupGetter__('port').toString().indexOf('[native code]') !== -1); + ok(HTMLAnchorElement.prototype.__lookupSetter__('port').toString().indexOf('[native code]') !== -1); + ok(HTMLAnchorElement.prototype.__lookupGetter__('pathname').toString().indexOf('[native code]') !== -1); + ok(HTMLAnchorElement.prototype.__lookupSetter__('pathname').toString().indexOf('[native code]') !== -1); +});