Closed
Bug 1396482
Opened 7 years ago
Closed 6 years ago
Object.getOwnPropertyNames(window) is missing some native functions in WebExtension content page
Categories
(Core :: XPConnect, defect, P2)
Tracking
()
RESOLVED
FIXED
mozilla64
People
(Reporter: gera2ld, Assigned: bzbarsky)
Details
Attachments
(3 files)
4.60 KB,
patch
|
jandem
:
review+
|
Details | Diff | Splinter Review |
3.17 KB,
patch
|
bholley
:
review+
|
Details | Diff | Splinter Review |
6.93 KB,
patch
|
bholley
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:57.0) Gecko/20100101 Firefox/57.0 Build ID: 20170903220032 Steps to reproduce: 1. In normal web page, open console, type `console.log(Object.getOwnPropertyNames(window).includes('Array'))`, got `true`. 2. In WebExtension content page, `console.log(Object.getOwnPropertyNames(window).includes('Array'))`, got `false`. Actual results: See above. Expected results: 'Array', 'String', etc should be included in `Object.getOwnPropertyNames(window)` either in web page or WebExtension content page, but actually missing in WebExtension content page. This has a bad effect on my WebExtension ported from Chrome since it worked well on Chrome.
Component: Untriaged → WebExtensions: General
Product: Core → Toolkit
Updated•7 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Assignee | ||
Comment 2•7 years ago
|
||
Are you sure this is a duplicat of bug 1208775? I can think of at least two approaches that fix bug 1208775 but don't affect this issue...
Flags: needinfo?(tomica)
Comment 3•7 years ago
|
||
I could be wrong, bug looking at other dupes of bug 1208775, it is not (only) specifically about `this === window` being false, but about all the consequences of `window` not being the global in content scripts (which would also include this). If you are working on a solution for bug 1208775 that doesn't also cover this issue though, feel free to reopen/undupe/depend as you see appropriate.
Flags: needinfo?(tomica)
Assignee | ||
Comment 4•7 years ago
|
||
I'm not working on a solution. But ok, it want's clear to me that the plan was to fix "window to be the global" as opposed to fixing "this" to be the targeted window...
Assignee | ||
Comment 5•7 years ago
|
||
I guess in either case, my approach would be to mark dependent, not dup. Otherwise the chance that anyone tests the behavior here once bug 1208775 is fixed is pretty slim. But not my component.
Comment 6•7 years ago
|
||
It looks like this is more about X-ray wrappers around `window` than they are about top-level `this` not pointing to the window wrapper.
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---
Comment 7•7 years ago
|
||
(In reply to Kris Maglione [:kmag] (long backlog; ping on IRC if you're blocked) from comment #6) > It looks like this is more about X-ray wrappers around `window` than they > are about top-level `this` not pointing to the window wrapper. *than it is about
Updated•7 years ago
|
status-firefox57:
--- → wontfix
Updated•6 years ago
|
Product: Toolkit → WebExtensions
Updated•6 years ago
|
Component: General → XPConnect
Product: WebExtensions → Core
Comment 9•6 years ago
|
||
We do have code in XrayWrapper for resolving standard classes on global objects. It's not clear to me that the target here is actually the window. If it is then there might be a bug in that code, but if it isn't then the code won't kick in.
Assignee | ||
Comment 10•6 years ago
|
||
We have code for making "window.Array" work, in XrayTraits::resolveOwnProperty. I don't think we have anything in DOMXrayTraits::enumerateNames for standard classes. We might be able to just throw a JS_NewEnumerateStandardClasses in there in the global case. I'll give that a shot.
Assignee | ||
Comment 11•6 years ago
|
||
So one issue is that JS_NewEnumerateStandardClasses only returns the names of _unresolved_ standard classes. Here we really want to get the names of all standard classes, because we're not doing an enumerate on the object itself, so whether they've been resolved there or not does not matter. Jan, would adding an API for that be OK? Any preferences on naming it?
Flags: needinfo?(jdemooij)
Assignee | ||
Comment 12•6 years ago
|
||
One option is to give JS_NewEnumerateStandardClasses an optional boolean arg for "include resolved ones".
Assignee | ||
Comment 13•6 years ago
|
||
I guess that doesn't work because JS_NewEnumerateStandardClasses is used as a class newenumerate hook. So we would really need a separate method.
Comment 14•6 years ago
|
||
Adding an API for this is fine I think. Internally we could use a helper function with a bool argument to avoid duplication. Maybe JS_NewEnumerateStandardClassesIncludingResolved? Pretty long but clear...
Flags: needinfo?(jdemooij)
Assignee | ||
Comment 15•6 years ago
|
||
Attachment #9012663 -
Flags: review?(jdemooij)
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → bzbarsky
Status: REOPENED → ASSIGNED
Assignee | ||
Comment 16•6 years ago
|
||
Attachment #9012665 -
Flags: review?(bobbyholley)
Updated•6 years ago
|
Flags: needinfo?(kmaglione+bmo)
Comment 17•6 years ago
|
||
Comment on attachment 9012665 [details] [diff] [review] part 2. Expose JS standard classes on Window Xrays, just like we expose WebIDL interfaces Review of attachment 9012665 [details] [diff] [review]: ----------------------------------------------------------------- I think the commit message should be something like "enumerate" rather than "expose", since they're already exposed (just not listed when querying names).
Attachment #9012665 -
Flags: review?(bobbyholley) → review+
Assignee | ||
Comment 18•6 years ago
|
||
> I think the commit message should be something like "enumerate" rather than "expose"
Done.
Comment 19•6 years ago
|
||
Comment on attachment 9012663 [details] [diff] [review] part 1. Add an API for enumerating all the standard class names on a global Review of attachment 9012663 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/jsapi.cpp @@ +1136,3 @@ > { > if (enumerableOnly) { > // There are no enumerable lazy properties. I was wondering if this is correct for the includeResolved case. Maybe change the comment to "There are no enumerable standard classes."? ::: js/src/jsapi.h @@ +957,5 @@ > extern JS_PUBLIC_API(bool) > JS_EnumerateStandardClasses(JSContext* cx, JS::HandleObject obj); > > +/** > + * Fill "properties" with a list of standard class names that have not yet been Thanks for adding this comment.
Attachment #9012663 -
Flags: review?(jdemooij) → review+
Comment 20•6 years ago
|
||
Would it make sense to also move the resolving code for builtins from XrayTraits::resolveOwnProperty to DOMXrayTraits::resolveOwnProperty, for symmetry?
Updated•6 years ago
|
Priority: -- → P2
Assignee | ||
Comment 21•6 years ago
|
||
> Maybe change the comment to "There are no enumerable standard classes."? I will do that. > Would it make sense to also move the resolving code for builtins from > XrayTraits::resolveOwnProperty to DOMXrayTraits::resolveOwnProperty I was a bit torn about that. I guess we could do that instead of the maybe-move-enumeration-to-superclass comment I have...
Comment 22•6 years ago
|
||
Pushed by bzbarsky@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/c23086c12393 part 1. Add an API for enumerating all the standard class names on a global. r=jandem https://hg.mozilla.org/integration/mozilla-inbound/rev/8c9b27320d6e part 2. Enumerate JS standard classes on Window Xrays, just like we enumerateWebIDL interfaces. r=bholley
Comment 23•6 years ago
|
||
Backed out for failing dom/tests/mochitest/general/test_interfaces.html Push that started the failures: https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&resultStatus=pending,running,success,testfailed,busted,exception&classifiedState=unclassified&searchStr=m-e10s(9)&selectedJob=202238171&revision=8c9b27320d6e37b77631980d19607d5c58717896 Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=202238171&repo=mozilla-inbound&lineNumber=23377 Backout: https://hg.mozilla.org/integration/mozilla-inbound/rev/59496d5915844c01b3aa71894e35cfedf347443f
Flags: needinfo?(bzbarsky)
Assignee | ||
Comment 24•6 years ago
|
||
Need to adjust the test expectations. The test actually has comments about how it's working around this bug for NaN and Infinity!
Assignee | ||
Comment 25•6 years ago
|
||
I guess there is one question there: with this change Object.getOwnPropertyNames will return a list including "Infinity" and "NaN" but Xrays don't produce property descriptors for those. Bobby, are you ok with that? If not, I can probably just add support for those two properties in Xrays too...
Flags: needinfo?(bzbarsky) → needinfo?(bobbyholley)
Comment 26•6 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #25) > I guess there is one question there: with this change > Object.getOwnPropertyNames will return a list including "Infinity" and "NaN" > but Xrays don't produce property descriptors for those. Bobby, are you ok > with that? If not, I can probably just add support for those two > properties in Xrays too... I don't have a strong opinion. In general I don't care, though it's plausible that it could cause some weird WebExtension bustage whereby somebody iterates and expects to be able to look up those same properties. I'm fine with either seeing what kmag thinks or just adding support.
Flags: needinfo?(bobbyholley)
Assignee | ||
Comment 27•6 years ago
|
||
Attachment #9012959 -
Flags: review?(bobbyholley)
Updated•6 years ago
|
Attachment #9012959 -
Flags: review?(bobbyholley) → review+
Comment 28•6 years ago
|
||
Pushed by bzbarsky@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/2396739f4dfc part 1. Add an API for enumerating all the standard class names on a global. r=jandem https://hg.mozilla.org/integration/mozilla-inbound/rev/747286879049 part 2. Enumerate JS standard classes on Window Xrays, just like we enumerateWebIDL interfaces. r=bholley
Comment 29•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/2396739f4dfc https://hg.mozilla.org/mozilla-central/rev/747286879049
Status: ASSIGNED → RESOLVED
Closed: 7 years ago → 6 years ago
status-firefox64:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
You need to log in
before you can comment on or make changes to this bug.
Description
•