Commit 8e178acc authored by Kagami Sascha Rosylight's avatar Kagami Sascha Rosylight
Browse files

Bug 1769290 - Part 23: Apply mozilla-js-handle-rooted-typedef against toolkit...

Bug 1769290 - Part 23: Apply mozilla-js-handle-rooted-typedef against toolkit misc r=extension-reviewers,kmag

Differential Revision: https://phabricator.services.mozilla.com/D151790
parent 279a987f
Loading
Loading
Loading
Loading
+21 −19
Original line number Diff line number Diff line
@@ -62,31 +62,33 @@ nsHangDetails::GetRemoteType(nsACString& aName) {
}

NS_IMETHODIMP
nsHangDetails::GetAnnotations(JSContext* aCx, JS::MutableHandleValue aVal) {
nsHangDetails::GetAnnotations(JSContext* aCx,
                              JS::MutableHandle<JS::Value> aVal) {
  // We create an Array with ["key", "value"] string pair entries for each item
  // in our annotations object.
  auto& annotations = mDetails.annotations();
  size_t length = annotations.Length();
  JS::RootedObject retObj(aCx, JS::NewArrayObject(aCx, length));
  JS::Rooted<JSObject*> retObj(aCx, JS::NewArrayObject(aCx, length));
  if (!retObj) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  for (size_t i = 0; i < length; ++i) {
    const auto& annotation = annotations[i];
    JS::RootedObject annotationPair(aCx, JS::NewArrayObject(aCx, 2));
    JS::Rooted<JSObject*> annotationPair(aCx, JS::NewArrayObject(aCx, 2));
    if (!annotationPair) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    JS::RootedString key(aCx, JS_NewUCStringCopyN(aCx, annotation.name().get(),
    JS::Rooted<JSString*> key(aCx,
                              JS_NewUCStringCopyN(aCx, annotation.name().get(),
                                                  annotation.name().Length()));
    if (!key) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    JS::RootedString value(aCx,
                           JS_NewUCStringCopyN(aCx, annotation.value().get(),
    JS::Rooted<JSString*> value(
        aCx, JS_NewUCStringCopyN(aCx, annotation.value().get(),
                                 annotation.value().Length()));
    if (!value) {
      return NS_ERROR_OUT_OF_MEMORY;
@@ -117,7 +119,7 @@ nsresult StringFrame(JSContext* aCx, JS::RootedObject& aTarget, size_t aIndex,
  if (!jsString) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  JS::RootedString string(aCx, jsString);
  JS::Rooted<JSString*> string(aCx, jsString);
  if (!string) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
@@ -130,10 +132,10 @@ nsresult StringFrame(JSContext* aCx, JS::RootedObject& aTarget, size_t aIndex,
}  // anonymous namespace

NS_IMETHODIMP
nsHangDetails::GetStack(JSContext* aCx, JS::MutableHandleValue aStack) {
nsHangDetails::GetStack(JSContext* aCx, JS::MutableHandle<JS::Value> aStack) {
  auto& stack = mDetails.stack();
  uint32_t length = stack.stack().Length();
  JS::RootedObject ret(aCx, JS::NewArrayObject(aCx, length));
  JS::Rooted<JSObject*> ret(aCx, JS::NewArrayObject(aCx, length));
  if (!ret) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
@@ -176,7 +178,7 @@ nsHangDetails::GetStack(JSContext* aCx, JS::MutableHandleValue aStack) {
      case HangEntry::THangEntryModOffset: {
        const HangEntryModOffset& mo = entry.get_HangEntryModOffset();

        JS::RootedObject jsFrame(aCx, JS::NewArrayObject(aCx, 2));
        JS::Rooted<JSObject*> jsFrame(aCx, JS::NewArrayObject(aCx, 2));
        if (!jsFrame) {
          return NS_ERROR_OUT_OF_MEMORY;
        }
@@ -186,7 +188,7 @@ nsHangDetails::GetStack(JSContext* aCx, JS::MutableHandleValue aStack) {
        }

        nsPrintfCString hexString("%" PRIxPTR, (uintptr_t)mo.offset());
        JS::RootedString hex(aCx, JS_NewStringCopyZ(aCx, hexString.get()));
        JS::Rooted<JSString*> hex(aCx, JS_NewStringCopyZ(aCx, hexString.get()));
        if (!hex || !JS_DefineElement(aCx, jsFrame, 1, hex, JSPROP_ENUMERATE)) {
          return NS_ERROR_OUT_OF_MEMORY;
        }
@@ -237,29 +239,29 @@ nsHangDetails::GetStack(JSContext* aCx, JS::MutableHandleValue aStack) {
}

NS_IMETHODIMP
nsHangDetails::GetModules(JSContext* aCx, JS::MutableHandleValue aVal) {
nsHangDetails::GetModules(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) {
  auto& modules = mDetails.stack().modules();
  size_t length = modules.Length();
  JS::RootedObject retObj(aCx, JS::NewArrayObject(aCx, length));
  JS::Rooted<JSObject*> retObj(aCx, JS::NewArrayObject(aCx, length));
  if (!retObj) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  for (size_t i = 0; i < length; ++i) {
    const HangModule& module = modules[i];
    JS::RootedObject jsModule(aCx, JS::NewArrayObject(aCx, 2));
    JS::Rooted<JSObject*> jsModule(aCx, JS::NewArrayObject(aCx, 2));
    if (!jsModule) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    JS::RootedString name(aCx,
                          JS_NewUCStringCopyN(aCx, module.name().BeginReading(),
    JS::Rooted<JSString*> name(
        aCx, JS_NewUCStringCopyN(aCx, module.name().BeginReading(),
                                 module.name().Length()));
    if (!JS_DefineElement(aCx, jsModule, 0, name, JSPROP_ENUMERATE)) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    JS::RootedString breakpadId(
    JS::Rooted<JSString*> breakpadId(
        aCx, JS_NewStringCopyN(aCx, module.breakpadId().BeginReading(),
                               module.breakpadId().Length()));
    if (!JS_DefineElement(aCx, jsModule, 1, breakpadId, JSPROP_ENUMERATE)) {
+3 −3
Original line number Diff line number Diff line
@@ -160,19 +160,19 @@ nsresult NimbusFeatures::GetExperimentSlug(const nsACString& aFeatureId,
  if (JS_ParseJSON(cx, prefValue.BeginReading(), prefValue.Length(), &json) &&
      json.isObject()) {
    JS::Rooted<JSObject*> experimentJSON(cx, json.toObjectOrNull());
    JS::RootedValue expSlugValue(cx);
    JS::Rooted<JS::Value> expSlugValue(cx);
    if (!JS_GetProperty(cx, experimentJSON, "slug", &expSlugValue)) {
      return NS_ERROR_UNEXPECTED;
    }
    AssignJSString(cx, aExperimentSlug, expSlugValue.toString());

    JS::RootedValue branchJSON(cx);
    JS::Rooted<JS::Value> branchJSON(cx);
    if (!JS_GetProperty(cx, experimentJSON, "branch", &branchJSON) &&
        !branchJSON.isObject()) {
      return NS_ERROR_UNEXPECTED;
    }
    JS::Rooted<JSObject*> branchObj(cx, branchJSON.toObjectOrNull());
    JS::RootedValue branchSlugValue(cx);
    JS::Rooted<JS::Value> branchSlugValue(cx);
    if (!JS_GetProperty(cx, branchObj, "slug", &branchSlugValue)) {
      return NS_ERROR_UNEXPECTED;
    }
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ TEST_F(NimbusTelemetryFixture, NimbusFeaturesTelemetry) {
  ASSERT_EQ(NimbusFeatures::RecordExposureEvent("bar"_ns), NS_ERROR_UNEXPECTED)
      << "Should fail because we don't have an experiment for bar";

  JS::RootedValue eventsSnapshot(cx.GetJSContext());
  JS::Rooted<JS::Value> eventsSnapshot(cx.GetJSContext());
  GetEventSnapshot(cx.GetJSContext(), &eventsSnapshot);
  ASSERT_TRUE(EventPresent(cx.GetJSContext(), eventsSnapshot, "normandy"_ns,
                           "expose"_ns, "nimbus_experiment"_ns));
+12 −12
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ class AbstractResult : public nsINativeOSFileResult {
  }

  virtual nsresult GetCacheableResult(JSContext* cx,
                                      JS::MutableHandleValue aResult) = 0;
                                      JS::MutableHandle<JS::Value> aResult) = 0;

 private:
  TimeStamp mStartDate;
@@ -248,7 +248,7 @@ AbstractResult::GetExecutionDurationMS(double* aExecutionDuration) {
}

NS_IMETHODIMP
AbstractResult::GetResult(JSContext* cx, JS::MutableHandleValue aResult) {
AbstractResult::GetResult(JSContext* cx, JS::MutableHandle<JS::Value> aResult) {
  if (mCachedResult.isUndefined()) {
    nsresult rv = GetCacheableResult(cx, aResult);
    if (NS_FAILED(rv)) {
@@ -286,14 +286,14 @@ class StringResult final : public AbstractResult {

 protected:
  nsresult GetCacheableResult(JSContext* cx,
                              JS::MutableHandleValue aResult) override;
                              JS::MutableHandle<JS::Value> aResult) override;

 private:
  nsString mContents;
};

nsresult StringResult::GetCacheableResult(JSContext* cx,
                                          JS::MutableHandleValue aResult) {
nsresult StringResult::GetCacheableResult(
    JSContext* cx, JS::MutableHandle<JS::Value> aResult) {
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mContents.get());

@@ -330,7 +330,7 @@ class TypedArrayResult final : public AbstractResult {

 protected:
  nsresult GetCacheableResult(JSContext* cx,
                              JS::MutableHandleValue aResult) override;
                              JS::MutableHandle<JS::Value> aResult) override;

 private:
  ScopedArrayBufferContents mContents;
@@ -388,14 +388,14 @@ class Int32Result final : public AbstractResult {

 protected:
  nsresult GetCacheableResult(JSContext* cx,
                              JS::MutableHandleValue aResult) override;
                              JS::MutableHandle<JS::Value> aResult) override;

 private:
  int32_t mContents;
};

nsresult Int32Result::GetCacheableResult(JSContext* cx,
                                         JS::MutableHandleValue aResult) {
                                         JS::MutableHandle<JS::Value> aResult) {
  MOZ_ASSERT(NS_IsMainThread());
  aResult.set(JS::NumberValue(mContents));
  return NS_OK;
@@ -1120,7 +1120,7 @@ NS_IMPL_ISUPPORTS(NativeOSFileInternalsService,

NS_IMETHODIMP
NativeOSFileInternalsService::Read(const nsAString& aPath,
                                   JS::HandleValue aOptions,
                                   JS::Handle<JS::Value> aOptions,
                                   nsINativeOSFileSuccessCallback* aOnSuccess,
                                   nsINativeOSFileErrorCallback* aOnError,
                                   JSContext* cx) {
@@ -1175,8 +1175,8 @@ NativeOSFileInternalsService::Read(const nsAString& aPath,
// Note: This method steals the contents of `aBuffer`.
NS_IMETHODIMP
NativeOSFileInternalsService::WriteAtomic(
    const nsAString& aPath, JS::HandleValue aBuffer, JS::HandleValue aOptions,
    nsINativeOSFileSuccessCallback* aOnSuccess,
    const nsAString& aPath, JS::Handle<JS::Value> aBuffer,
    JS::Handle<JS::Value> aOptions, nsINativeOSFileSuccessCallback* aOnSuccess,
    nsINativeOSFileErrorCallback* aOnError, JSContext* cx) {
  MOZ_ASSERT(NS_IsMainThread());
  // Extract typed-array/string into buffer. We also need to store the length
@@ -1189,7 +1189,7 @@ NativeOSFileInternalsService::WriteAtomic(
    return NS_ERROR_INVALID_ARG;
  }

  JS::RootedObject bufferObject(cx, nullptr);
  JS::Rooted<JSObject*> bufferObject(cx, nullptr);
  if (!JS_ValueToObject(cx, aBuffer, &bufferObject)) {
    return NS_ERROR_FAILURE;
  }
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ PlaceInfo::GetVisits(JSContext* aContext,
  nsCOMPtr<nsIXPConnect> xpc = nsIXPConnect::XPConnect();

  for (VisitsArray::size_type idx = 0; idx < mVisits.Length(); idx++) {
    JS::RootedObject jsobj(aContext);
    JS::Rooted<JSObject*> jsobj(aContext);
    nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
                                  NS_GET_IID(mozIVisitInfo), jsobj.address());
    NS_ENSURE_SUCCESS(rv, rv);
Loading