Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with 'isEmptyObject()' #268

Closed
AdamWr opened this issue Dec 8, 2022 · 0 comments
Closed

Issue with 'isEmptyObject()' #268

AdamWr opened this issue Dec 8, 2022 · 0 comments

Comments

@AdamWr
Copy link
Member

AdamWr commented Dec 8, 2022

If I'm not wrong, some scriptlets doesn't work in some cases due to issue with isEmptyObject.

Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('set-constant', 'EventTarget.prototype.dispatchEvent', 'noopFunc')
  1. Go to - https://example.org/
  2. Check EventTarget.prototype.dispatchEvent in console.

It should returns noopFunc, but it doesn't work.

Screenshot

image

If I'm not wrong, it's because isEmptyObject returns true in case of EventTarget and any other object with prototype.

export const isEmptyObject = (obj) => Object.keys(obj).length === 0;

For example:

var test = function(){};
test.prototype = { abc: function() {} };
Screenshot

image

The same happens with abort-current-inline-script, abort-on-property-read and probably with other scriptlets.

@stanislav-atr stanislav-atr self-assigned this Dec 13, 2022
adguard pushed a commit that referenced this issue Dec 13, 2022
Merge in ADGUARD-FILTERS/scriptlets from fix/AG-18170 to master

Squashed commit of the following:

commit 0390052
Merge: 180e595 d85c776
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Dec 13 20:46:10 2022 +0300

    Merge branch 'master' into fix/AG-18170

commit 180e595
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Dec 13 18:05:41 2022 +0300

    fix version

commit 2febad3
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Dec 13 16:51:14 2022 +0300

    update changelog

commit 19c6c85
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Dec 13 15:47:46 2022 +0300

    improve helper

commit f52e9a1
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Dec 13 15:47:04 2022 +0300

    improve helper and add tests

commit 817493a
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Dec 13 14:50:36 2022 +0300

    improve isEmptyObject - should not be function
@slavaleleka slavaleleka changed the title Issue with isEmptyObject Issue with 'isEmptyObject()' Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants