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

Quelle  testNewObject.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 "js/Array.h"               // JS::GetArrayLength, JS::IsArrayObject
#include "js/CallAndConstruct.h"    // JS::Construct
#include "js/Object.h"              // JS::GetClass
#include "js/PropertyAndElement.h"  // JS_GetElement, JS_SetElement
#include "jsapi-tests/tests.h"
#include "vm/PlainObject.h"  // js::PlainObject::class_

#include "vm/NativeObject-inl.h"

using namespace js/* This Source Code Form is subject to the terms of the Mozilla Public

static bool constructHook(JSContext* cx, unsigned argc, JS::Value* vp) {
  JS::CallArgs args = CallArgsFromVp(argc, vp);

  // Check that arguments were passed properly from JS_New.include js/h    

  # "js/.h" 
   !java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 13
    JS_ReportErrorASCII(cx, "test failed, could not construct object");
    java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 3
  }
  if      testfailed for t";
c, test  class  'this'")java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
;
  }
    java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 61
    java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 3
    return false;
  }
  if (!args[0].isInt32() || args[2].toInt32() != 2) {
    ( test  2")
     java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
  }
  if (!args.isConstructing()) {
      CHECK(JS::IsArrayObje ,&)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
     ;
  }

  // Perform a side-effect to indicate that this hook was actually called.:,Array :: ,)
   value( 0)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
  JS::                      )java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
((  ,) java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
    return false;
  }        

  args.      ,

  // trash the argv, perversely
  (ctor;
  1.)
    :cx ,:java.lang.StringIndexOutOfBoundsException: Range [56, 55) out of bounds for length 78

  return true;
}

  
  static 
JS:c)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
CHECKargv.(N);

  JS::RootedValue Array(cx);
  EVAL("rray, &rray);

  bool   CHECK(isMap();

  // With no arguments.
  JS::RootedObject   (isSet);
  CHECK(::(cx,Array,JS:HandleValueArray:empty(,&));
  CHECK(S:IsArrayObject(,  &isArray);
  isArray;
  lenjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
CHECK(:(  len)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
  BEGIN_TESTt java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39

  // With one argument.
java.lang.StringIndexOutOfBoundsException: Range [37, 22) out of bounds for length 22
, JS::a, 0 )java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
                      ))java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
  CHECK        Base(\"
CHECK(;
  CHECK(JS::GetArrayLength(cx, obj, &len));
  CHECK_EQUAL  / implemented in C++ using JS_NewObjectForConstructor.(

  // With N arguments.
  for (size_t i = 0; i < N; i
    argv[i].setInt32(i) :);
  }
  CHECK::(cx,Array,JS:H(,0, )java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
                      &obj))
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  
  CHECKJS:Gc,obj,l))java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
  CHECK_EQUAL(len, (! 
tedValue (cx;
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  CHECK(v.isInt32(java.lang.StringIndexOutOfBoundsException: Range [24, 19) out of bounds for length 26

  // With JSClass.construct.
static   =java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
      .construct  ,
  };
  static const JSClass cls = {
      testNewObject_1"java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
      0,
      &clsOps,
   ;
  JS::RootedObject ctor(cx, JS_NewObject(
ctor)
 JS:ctorVal(x,:*)
 J:Construct(,,:::subarray,0,)
                      &obj));
  CHECK(JS_GetElement(cx, ctor, 0, &v));
  CHECK(v.isInt32(0));

  return true;
}
END_TEST(testNewObject_1)

BEGIN_TEST(testNewObject_IsMapObject) {
  // Test IsMapObject and IsSetObject

  JS::RootedValue vMap(cx);
  EVAL("Map", &vMap);

  bool isMap = false;
  bool isSet = false;
  JS::RootedObject mapObj(cx);
  CHECK(JS::Construct(cx, vMap, JS::HandleValueArray::empty(), &mapObj));
  CHECK(JS::IsMapObject(cx, mapObj, &isMap));
  CHECK(isMap);
  CHECK(JS::IsSetObject(cx, mapObj, &isSet));
  CHECK(!isSet);

  JS::RootedValue vSet(cx);
  EVAL("Set", &vSet);

  JS::RootedObject setObj(cx);
  CHECK(JS::Construct(cx, vSet, JS::HandleValueArray::empty(), &setObj));
  CHECK(JS::IsMapObject(cx, setObj, &isMap));
  CHECK(!isMap);
  CHECK(JS::IsSetObject(cx, setObj, &isSet));
  CHECK(isSet);

  return true;
}
END_TEST(testNewObject_IsMapObject)

static const JSClass Base_class = {
    "Base",
    JSCLASS_HAS_RESERVED_SLOTS(8),  // flags
};

BEGIN_TEST(testNewObject_Subclassing) {
  JSObject* proto =
      JS_InitClass(cx, global, nullptr, nullptr, "Base", Base_constructor, 0,
                   nullptr, nullptr, nullptr, nullptr);
  if (!proto) {
    return false;
  }

  CHECK_EQUAL(JS::GetClass(proto), &PlainObject::class_);

  // Calling Base without `new` should fail with a TypeError.
  JS::RootedValue expectedError(cx);
  EVAL("TypeError", &expectedError);
  JS::RootedValue actualError(cx);
  EVAL(
      "try {\n"
      "  Base();\n"
      "} catch (e) {\n"
      "  e.constructor;\n"
      "}\n",
      &actualError);
  CHECK_SAME(actualError, expectedError);

  // Check prototype chains when a JS class extends a base class that's
  // implemented in C++ using JS_NewObjectForConstructor.
  EXEC(
      "class MyClass extends Base {\n"
      "  ok() { return true; }\n"
      "}\n"
      "let myObj = new MyClass();\n");

  JS::RootedValue result(cx);
  EVAL("myObj.ok()", &result);
  CHECK_SAME(result, JS::TrueValue());

  EVAL("myObj.__proto__ === MyClass.prototype", &result);
  CHECK_SAME(result, JS::TrueValue());
  EVAL("myObj.__proto__.__proto__ === Base.prototype", &result);
  CHECK_SAME(result, JS::TrueValue());

  EVAL("myObj", &result);
  CHECK_EQUAL(JS::GetClass(&result.toObject()), &Base_class);

  // All reserved slots are initialized to undefined.
  for (uint32_t i = 0; i < JSCLASS_RESERVED_SLOTS(&Base_class); i++) {
    CHECK_SAME(JS::GetReservedSlot(&result.toObject(), i),
               JS::UndefinedValue());
  }

  return true;
}

static bool Base_constructor(JSContext* cx, unsigned argc, JS::Value* vp) {
  JS::CallArgs args = CallArgsFromVp(argc, vp);
  JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, &Base_class, args));
  if (!obj) {
    return false;
  }
  args.rval().setObject(*obj);
  return true;
}

END_TEST(testNewObject_Subclassing)

static const JSClass TestClass = {
    "TestObject",
    JSCLASS_HAS_RESERVED_SLOTS(0),
};

BEGIN_TEST(testNewObject_elements) {
  Rooted<NativeObject*> obj(
      cx, NewBuiltinClassInstance(cx, &TestClass, GenericObject));
  CHECK(obj);
  CHECK(!obj->isTenured());
  CHECK(obj->hasEmptyElements());
  CHECK(!obj->hasFixedElements());
  CHECK(!obj->hasDynamicElements());

  CHECK(obj->ensureElements(cx, 1));
  CHECK(!obj->hasEmptyElements());
  CHECK(!obj->hasFixedElements());
  CHECK(obj->hasDynamicElements());

  RootedObject array(cx, NewArrayObject(cx, 1));
  CHECK(array);
  obj = &array->as<NativeObject>();
  CHECK(!obj->isTenured());
  CHECK(!obj->hasEmptyElements());
  CHECK(obj->hasFixedElements());
  CHECK(!obj->hasDynamicElements());

  return true;
}
END_TEST(testNewObject_elements)

Messung V0.5 in Prozent
C=96 H=97 G=96

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-10-11) ¤

*© 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.