Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/js/src/vm/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 3 kB image not shown  

Quelle  StencilObject.cpp

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "vm/StencilObject.h"

#include "mozilla/Assertions.h"     // MOZ_ASSERT
#include "mozilla/PodOperations.h"  // mozilla::PodCopy

#include <stddef.h>  // size_t
#include <stdint.h>  // uint8_t, INT32_MAX

#include "jsapi.h"           // JS_NewObject
#include "js/Class.h"        // JSClassOps, JSClass, JSCLASS_*
#include "js/ErrorReport.h"  // JS_ReportErrorASCII
#include "js/experimental/JSStencil.h"  // JS::Stencil, JS::StencilAddRef, JS::StencilRelease
#include "js/Utility.h"                 // js_free
#include "vm/JSContext.h"               // JSContext
#include "vm/JSObject.h"                // JSObject

#include "vm/JSObject-inl.h"  // NewBuiltinClassInstance

using namespace js;

/*static */ const JSClassOps StencilObject::classOps_ = {
    .finalize = StencilObject::finalize,
};

/*static */ const JSClass StencilObject::class_ = {
    "StencilObject",
    JSCLASS_HAS_RESERVED_SLOTS(StencilObject::ReservedSlots) |
        JSCLASS_BACKGROUND_FINALIZE,
    &StencilObject::classOps_,
};

bool StencilObject::hasStencil() const {
  // The stencil may not be present yet if we GC during initialization.
  return !getReservedSlot(StencilSlot).isUndefined();
}

JS::Stencil* StencilObject::stencil() const {
  void* ptr = getReservedSlot(StencilSlot).toPrivate();
  MOZ_ASSERT(ptr);
  return static_cast<JS::Stencil*>(ptr);
}

/* static */ StencilObject* StencilObject::create(JSContext* cx,
                                                  RefPtr<JS::Stencil> stencil) {
  auto* obj = NewBuiltinClassInstance<StencilObject>(cx);
  if (!obj) {
    return nullptr;
  }

  obj->setReservedSlot(StencilSlot, PrivateValue(stencil.forget().take()));

  return obj;
}

/* static */ void StencilObject::finalize(JS::GCContext* gcx, JSObject* obj) {
  if (obj->as<StencilObject>().hasStencil()) {
    JS::StencilRelease(obj->as<StencilObject>().stencil());
  }
}

/*static */ const JSClassOps StencilXDRBufferObject::classOps_ = {
    .finalize = StencilXDRBufferObject::finalize,
};

/*static */ const JSClass StencilXDRBufferObject::class_ = {
    "StencilXDRBufferObject",
    JSCLASS_HAS_RESERVED_SLOTS(StencilXDRBufferObject::ReservedSlots) |
        JSCLASS_BACKGROUND_FINALIZE,
    &StencilXDRBufferObject::classOps_,
};

bool StencilXDRBufferObject::hasBuffer() const {
  // The stencil may not be present yet if we GC during initialization.
  return !getReservedSlot(BufferSlot).isUndefined();
}

const uint8_t* StencilXDRBufferObject::buffer() const {
  void* ptr = getReservedSlot(BufferSlot).toPrivate();
  MOZ_ASSERT(ptr);
  return static_cast<const uint8_t*>(ptr);
}

uint8_t* StencilXDRBufferObject::writableBuffer() {
  void* ptr = getReservedSlot(BufferSlot).toPrivate();
  MOZ_ASSERT(ptr);
  return static_cast<uint8_t*>(ptr);
}

size_t StencilXDRBufferObject::bufferLength() const {
  return getReservedSlot(LengthSlot).toInt32();
}

/* static */ StencilXDRBufferObject* StencilXDRBufferObject::create(
    JSContext* cx, uint8_t* buffer, size_t length) {
  if (length >= INT32_MAX) {
    JS_ReportErrorASCII(cx, "XDR buffer is too long");
    return nullptr;
  }

  auto* obj = NewBuiltinClassInstance<StencilXDRBufferObject>(cx);
  if (!obj) {
    return nullptr;
  }

  auto ownedBuffer = cx->make_pod_array<uint8_t>(length);
  if (!ownedBuffer) {
    return nullptr;
  }

  mozilla::PodCopy(ownedBuffer.get(), buffer, length);

  obj->setReservedSlot(BufferSlot, PrivateValue(ownedBuffer.release()));
  obj->setReservedSlot(LengthSlot, Int32Value(length));

  return obj;
}

/* static */ void StencilXDRBufferObject::finalize(JS::GCContext* gcx,
                                                   JSObject* obj) {
  if (obj->as<StencilXDRBufferObject>().hasBuffer()) {
    js_free(obj->as<StencilXDRBufferObject>().writableBuffer());
  }
}

Messung V0.5 in Prozent
C=83 H=100 G=91

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.