content icon indicating copy to clipboard operation
content copied to clipboard

Issue with "Sharing objects with page scripts": syntax error in the example

Open automatedbugreportingfacility opened this issue 4 years ago • 6 comments

MDN URL: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts

What information was incorrect, unhelpful, or incomplete?

Reflect.defineProperty(ev.wrappedJSObject,        // privileged reflection can operate on less privileged objects
  'propC', {
     get: exportFunction(function() {             // getters must be exported like regular functions
       return 'propC';
     }
  }
);

This code throws a syntax error. The call to exportFunction is missing the second argument and the closing bracket.

Specific section or headline?

Constructors from the page context

MDN Content page report details
  • Folder: en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts
  • MDN URL: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts
  • GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts/index.html
  • Last commit: https://github.com/mdn/content/commit/c7d9128559ed9526914c9be5bb461445fde5866a
  • Document last modified: 2021-02-19T20:09:33.000Z

@sideshowbarker: please re-open this issue -- the updated example still throws an error because the second argument (targetScope, according to https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction) is required in the call to exportFunction:

Error: Function requires at least 2 arguments

This code throws a syntax error. The call to exportFunction is missing the second argument and the closing bracket.

#2678 added the closing bracket but not the missing second argument.

@NegiAkash890 was it your intention to only partially fix this, or did you somehow misread the issue description?

Regardless, do you plan to raise another PR to fix the problem with the missing second argument?

@automatedbugreportingfacility — Thanks for the heads-up on this, and sorry for having failed to catch this myself when I reviewed the PR.

sideshowbarker avatar Feb 26 '21 04:02 sideshowbarker

@sideshowbarker Sure , I will try my best to fix the issue .

NegiAkash890 avatar Feb 26 '21 09:02 NegiAkash890

Screenshot from 2021-03-01 11-03-08

Hi @sideshowbarker , I am on my way to fix the issue . So I started by creating objects objA and objB using console(browser) for the same . I noticed that the result of the log is different in log(browser) and as stated in the documentation .

Output in testing console .

`console.log(
 objA instanceof Object ,                        // true
  objB instanceof Object,                        // true
  objA instanceof window.Object,           // true
  objB instanceof window.Object,           // true
  'wrappedJSObject' in objB                  // false
)`

Output on Documentation

console.log(
  objA instanceof Object,                        // true
  objB instanceof Object,                        // false
  objA instanceof window.Object,                 // false
  objB instanceof window.Object,                 // true
  'wrappedJSObject' in objB                      // true; xrayed
);`
`

Can You Please point here which one of the above in unexpected behavior ?

NegiAkash890 avatar Mar 01 '21 05:03 NegiAkash890

Can You Please point here which one of the above in unexpected behavior ?

No, I can’t, actually. I don’t have the bandwidth to assist on testing and investigation related to preparation of patches. But I can review any patch you do end up putting together.

sideshowbarker avatar Mar 01 '21 06:03 sideshowbarker

This should be reopened, the example still throws an error.