create null prototype object in web page window

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
BZZZZ

create null prototype object in web page window

Unread post by BZZZZ » 2021-08-31, 09:29

I want to create null prototype object (like Object.create(null)) in web page window.
  • win is web page window with xray
  • obj is null prototype object to be created without xray
This works:

Code: Select all

var obj=new win.Object.wrappedJSObject();
Object.setPrototypeOf(obj,null);
but according this web page Object.setPrototypeOf() is slow.

Is there better way to create null prototype object in web page window?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35403
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: create null prototype object in web page window

Unread post by Moonchild » 2021-08-31, 09:35

BZZZZ wrote:
2021-08-31, 09:29
Is there better way to create null prototype object in web page window?
No, because you need it to be wrapped for script safety. Too bad if you lose some performance as a result.

Not sure what your context is but you seem to be poking at the barriers that exist between chrome and content on purpose. I suggest you try to find better solutions for your problems; in most cases this kind of thing won't be necessary.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

BZZZZ

Re: create null prototype object in web page window

Unread post by BZZZZ » 2021-08-31, 10:58

Moonchild wrote:
2021-08-31, 09:35
Not sure what your context is but you seem to be poking at the barriers that exist between chrome and content on purpose. I suggest you try to find better solutions for your problems; in most cases this kind of thing won't be necessary.
null prototype object in window is needed to create Proxy in window.

It has to be null prototype because web page script can do:

Code: Select all

Object.prototype.apply=function(){
  alert("unintended Proxy handler");
};
.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35403
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: create null prototype object in web page window

Unread post by Moonchild » 2021-08-31, 11:01

Yeah if you're exposing a proxy to content you have to be careful. this is exactly why xrays and wrappers exist.
Not sure why you are concerned about a bit of relative slowness to do this safely. This is not the kind of thing you'd be doing thousands of times where it becomes a potential issue, right?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

Locked