Commit c1ae6857 authored by Molnar Sandor's avatar Molnar Sandor
Browse files

Backed out 9 changesets (bug 1769002, bug 1768870, bug 1771097, bug 1771092,...

Backed out 9 changesets (bug 1769002, bug 1768870, bug 1771097, bug 1771092, bug 1768819) for causing lint failures. CLOSED TREE

Backed out changeset 829df1dfad70 (bug 1769002)
Backed out changeset f0537d333adc (bug 1771092)
Backed out changeset 25b43856bc00 (bug 1771092)
Backed out changeset a49f754ca73f (bug 1771092)
Backed out changeset 164f85686a32 (bug 1769002)
Backed out changeset ef5cf9ceb915 (bug 1768819)
Backed out changeset c64e6c1fbfe7 (bug 1771097)
Backed out changeset f85393f988a8 (bug 1768870)
Backed out changeset fe708d13cc1d (bug 1768870)
parent 482eccfa
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -832,7 +832,6 @@ add_task(async function checkAllTheFiles() {
    ".mjs",
    ".js",
    ".jsm",
    ".mjs",
    ".json",
    ".html",
    ".xhtml",
@@ -881,9 +880,6 @@ add_task(async function checkAllTheFiles() {
  for (let jsm of Components.manager.getComponentJSMs()) {
    gReferencesFromCode.set(jsm, null);
  }
  for (let esModule of Components.manager.getComponentESModules()) {
    gReferencesFromCode.set(esModule, null);
  }

  // manifest.json is a common name, it is used for WebExtension manifests
  // but also for other things.  To tell them apart, we have to actually
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ The plugin implements the following rules:
   eslint-plugin-mozilla/import-globals
   eslint-plugin-mozilla/import-globals-from
   eslint-plugin-mozilla/import-headjs-globals
   eslint-plugin-mozilla/lazy-getter-object-name
   eslint-plugin-mozilla/mark-exported-symbols-as-used
   eslint-plugin-mozilla/mark-test-function-used
   eslint-plugin-mozilla/no-aArgs
+0 −25
Original line number Diff line number Diff line
lazy-getter-object-name
=============================

Enforce the standard object variable name ``lazy`` for
``ChromeUtils.defineESModuleGetters``

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    const obj = {};
    ChromeUtils.defineESModuleGetters(obj, {
      Services: “resource://gre/modules/Services.sys.mjs”,
    });

Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

    const lazy = {};
    ChromeUtils.defineESModuleGetters(lazy, {
      Services: “resource://gre/modules/Services.sys.mjs”,
    });
+18 −124
Original line number Diff line number Diff line
@@ -8,10 +8,9 @@

#include "js/CharacterEncoding.h"
#include "js/Object.h"              // JS::GetClass
#include "js/PropertyAndElement.h"  // JS_DefineProperty, JS_DefinePropertyById, JS_Enumerate, JS_GetProperty, JS_GetPropertyById, JS_SetProperty, JS_SetPropertyById, JS::IdVector
#include "js/PropertyAndElement.h"  // JS_DefineProperty, JS_DefinePropertyById, JS_Enumerate, JS_GetProperty, JS_GetPropertyById, JS_SetProperty, JS_SetPropertyById
#include "js/PropertyDescriptor.h"  // JS::PropertyDescriptor, JS_GetOwnPropertyDescriptorById
#include "js/SavedFrameAPI.h"
#include "js/Value.h"  // JS::Value, JS::StringValue
#include "jsfriendapi.h"
#include "WrapperFactory.h"

@@ -627,10 +626,7 @@ static bool ExtractArgs(JSContext* aCx, JS::CallArgs& aArgs,
  return true;
}

enum class ModuleType { JSM, ESM };

static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
                             ModuleType aType) {
static bool ModuleGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);

  JS::Rooted<JSObject*> callee(aCx);
@@ -651,8 +647,6 @@ static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
  RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
  MOZ_ASSERT(moduleloader);

  JS::Rooted<JS::Value> value(aCx);
  if (aType == ModuleType::JSM) {
  JS::Rooted<JSObject*> moduleGlobal(aCx);
  JS::Rooted<JSObject*> moduleExports(aCx);
  nsresult rv = moduleloader->Import(aCx, uri, &moduleGlobal, &moduleExports);
@@ -661,29 +655,10 @@ static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
    return false;
  }

    // JSM's exports is from the same realm.
  JS::Rooted<JS::Value> value(aCx);
  if (!JS_GetPropertyById(aCx, moduleExports, id, &value)) {
    return false;
  }
  } else {
    JS::Rooted<JSObject*> moduleNamespace(aCx);
    nsresult rv = moduleloader->ImportESModule(aCx, uri, &moduleNamespace);
    if (NS_FAILED(rv)) {
      Throw(aCx, rv);
      return false;
    }

    // ESM's namespace is from the module's realm.
    {
      JSAutoRealm ar(aCx, moduleNamespace);
      if (!JS_GetPropertyById(aCx, moduleNamespace, id, &value)) {
        return false;
      }
    }
    if (!JS_WrapValue(aCx, &value)) {
      return false;
    }
  }

  if (!JS_DefinePropertyById(aCx, thisObj, id, value, JSPROP_ENUMERATE)) {
    return false;
@@ -693,15 +668,7 @@ static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
  return true;
}

static bool JSModuleGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  return ModuleGetterImpl(aCx, aArgc, aVp, ModuleType::JSM);
}

static bool ESModuleGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  return ModuleGetterImpl(aCx, aArgc, aVp, ModuleType::ESM);
}

static bool ModuleSetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
static bool ModuleSetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);

  JS::Rooted<JSObject*> callee(aCx);
@@ -714,17 +681,8 @@ static bool ModuleSetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  return JS_DefinePropertyById(aCx, thisObj, id, args.get(0), JSPROP_ENUMERATE);
}

static bool JSModuleSetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  return ModuleSetterImpl(aCx, aArgc, aVp);
}

static bool ESModuleSetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
  return ModuleSetterImpl(aCx, aArgc, aVp);
}

static bool DefineJSModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
                                 const nsAString& aId,
                                 const nsAString& aResourceURI) {
static bool DefineGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
                         const nsAString& aId, const nsAString& aResourceURI) {
  JS::Rooted<JS::Value> uri(aCx);
  JS::Rooted<JS::Value> idValue(aCx);
  JS::Rooted<jsid> id(aCx);
@@ -737,11 +695,11 @@ static bool DefineJSModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,

  JS::Rooted<JSObject*> getter(
      aCx, JS_GetFunctionObject(
               js::NewFunctionByIdWithReserved(aCx, JSModuleGetter, 0, 0, id)));
               js::NewFunctionByIdWithReserved(aCx, ModuleGetter, 0, 0, id)));

  JS::Rooted<JSObject*> setter(
      aCx, JS_GetFunctionObject(
               js::NewFunctionByIdWithReserved(aCx, JSModuleSetter, 0, 0, id)));
               js::NewFunctionByIdWithReserved(aCx, ModuleSetter, 0, 0, id)));

  if (!getter || !setter) {
    JS_ReportOutOfMemory(aCx);
@@ -756,33 +714,6 @@ static bool DefineJSModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
  return JS_DefinePropertyById(aCx, aTarget, id, getter, setter,
                               JSPROP_ENUMERATE);
}

static bool DefineESModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
                                 JS::Handle<JS::PropertyKey> aId,
                                 JS::Handle<JS::Value> aResourceURI) {
  JS::Rooted<JS::Value> idVal(aCx, JS::StringValue(aId.toString()));

  JS::Rooted<JSObject*> getter(
      aCx, JS_GetFunctionObject(js::NewFunctionByIdWithReserved(
               aCx, ESModuleGetter, 0, 0, aId)));

  JS::Rooted<JSObject*> setter(
      aCx, JS_GetFunctionObject(js::NewFunctionByIdWithReserved(
               aCx, ESModuleSetter, 0, 0, aId)));

  if (!getter || !setter) {
    JS_ReportOutOfMemory(aCx);
    return false;
  }

  js::SetFunctionNativeReserved(getter, SLOT_ID, idVal);
  js::SetFunctionNativeReserved(setter, SLOT_ID, idVal);

  js::SetFunctionNativeReserved(getter, SLOT_URI, aResourceURI);

  return JS_DefinePropertyById(aCx, aTarget, aId, getter, setter,
                               JSPROP_ENUMERATE);
}
}  // namespace module_getter

/* static */
@@ -791,48 +722,11 @@ void ChromeUtils::DefineModuleGetter(const GlobalObject& global,
                                     const nsAString& id,
                                     const nsAString& resourceURI,
                                     ErrorResult& aRv) {
  if (!module_getter::DefineJSModuleGetter(global.Context(), target, id,
                                           resourceURI)) {
  if (!module_getter::DefineGetter(global.Context(), target, id, resourceURI)) {
    aRv.NoteJSContextException(global.Context());
  }
}

/* static */
void ChromeUtils::DefineESModuleGetters(const GlobalObject& global,
                                        JS::Handle<JSObject*> target,
                                        JS::Handle<JSObject*> modules,
                                        ErrorResult& aRv) {
  auto cx = global.Context();

  JS::Rooted<JS::IdVector> props(cx, JS::IdVector(cx));
  if (!JS_Enumerate(cx, modules, &props)) {
    aRv.NoteJSContextException(cx);
    return;
  }

  JS::Rooted<JS::PropertyKey> prop(cx);
  JS::Rooted<JS::Value> resourceURIVal(cx);
  for (JS::PropertyKey tmp : props) {
    prop = tmp;

    if (!prop.isString()) {
      aRv.Throw(NS_ERROR_FAILURE);
      return;
    }

    if (!JS_GetPropertyById(cx, modules, prop, &resourceURIVal)) {
      aRv.NoteJSContextException(cx);
      return;
    }

    if (!module_getter::DefineESModuleGetter(cx, target, prop,
                                             resourceURIVal)) {
      aRv.NoteJSContextException(cx);
      return;
    }
  }
}

/* static */
void ChromeUtils::OriginAttributesToSuffix(
    dom::GlobalObject& aGlobal, const dom::OriginAttributesDictionary& aAttrs,
+0 −5
Original line number Diff line number Diff line
@@ -211,11 +211,6 @@ class ChromeUtils {
                                 const nsAString& resourceURI,
                                 ErrorResult& aRv);

  static void DefineESModuleGetters(const GlobalObject& global,
                                    JS::Handle<JSObject*> target,
                                    JS::Handle<JSObject*> modules,
                                    ErrorResult& aRv);

  static void GetCallerLocation(const GlobalObject& global,
                                nsIPrincipal* principal,
                                JS::MutableHandle<JSObject*> aRetval);
Loading